Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

ClosureCompilerApplication.php

Zuletzt modifiziert: 02.04.2025, 15:04 - Dateigröße: 2.46 KiB


001  <?php
002   
003  /**
004  * @package   s9e\TextFormatter
005  * @copyright Copyright (c) 2010-2022 The s9e authors
006  * @license   http://www.opensource.org/licenses/mit-license.php The MIT License
007  */
008  namespace s9e\TextFormatter\Configurator\JavaScript\Minifiers;
009   
010  use RuntimeException;
011  use s9e\TextFormatter\Configurator\JavaScript\Minifier;
012   
013  class ClosureCompilerApplication extends Minifier
014  {
015      /**
016      * @var string Command used to invoke the Closure Compiler application
017      */
018      public $command;
019   
020      /**
021      * @var string Closure Compiler's compilation level
022      */
023      public $compilationLevel = 'ADVANCED_OPTIMIZATIONS';
024   
025      /**
026      * @var bool Whether to exclude Closure Compiler's default externs
027      */
028      public $excludeDefaultExterns = true;
029   
030      /**
031      * @var string Extra options to be passed to the Closure Compiler application
032      */
033      public $options = '--use_types_for_optimization';
034   
035      /**
036      * Constructor
037      *
038      * @param string $command Command to execute
039      */
040      public function __construct($command)
041      {
042          $this->command = $command;
043      }
044   
045      /**
046      * {@inheritdoc}
047      */
048      public function getCacheDifferentiator()
049      {
050          $key = [
051              $this->command,
052              $this->compilationLevel,
053              $this->excludeDefaultExterns,
054              $this->options
055          ];
056          if ($this->excludeDefaultExterns)
057          {
058              $key[] = file_get_contents(__DIR__ . '/../externs.application.js');
059          }
060   
061          return $key;
062      }
063   
064      /**
065      * Compile given JavaScript source via the Closure Compiler application
066      *
067      * @param  string $src JavaScript source
068      * @return string      Compiled source
069      */
070      public function minify($src)
071      {
072          $options = ($this->options) ? ' ' . $this->options : '';
073   
074          // Add our custom externs if default externs are disabled
075          if ($this->excludeDefaultExterns && $this->compilationLevel === 'ADVANCED_OPTIMIZATIONS')
076          {
077              $options .= ' --externs ' . __DIR__ . '/../externs.application.js --env=CUSTOM';
078          }
079   
080          $crc     = crc32($src);
081          $inFile  = sys_get_temp_dir() . '/' . $crc . '.js';
082          $outFile = sys_get_temp_dir() . '/' . $crc . '.min.js';
083          file_put_contents($inFile, $src);
084   
085          $cmd = $this->command
086               . ' --compilation_level ' . escapeshellarg($this->compilationLevel)
087               . $options
088               . ' --js ' . escapeshellarg($inFile)
089               . ' --js_output_file ' . escapeshellarg($outFile);
090   
091          exec($cmd . ' 2>&1', $output, $return);
092          unlink($inFile);
093   
094          if (file_exists($outFile))
095          {
096              $src = trim(file_get_contents($outFile));
097              unlink($outFile);
098          }
099   
100          if (!empty($return))
101          {
102              throw new RuntimeException('An error occured during minification: ' . implode("\n", $output));
103          }
104   
105          return $src;
106      }
107  }