Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

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: 09.10.2024, 12:59 - Dateigröße: 2.58 KiB


01  <?php
02   
03  /*
04  * @package   s9e\TextFormatter
05  * @copyright Copyright (c) 2010-2016 The s9e Authors
06  * @license   http://www.opensource.org/licenses/mit-license.php The MIT License
07  */
08  namespace s9e\TextFormatter\Configurator\JavaScript\Minifiers;
09  use RuntimeException;
10  use s9e\TextFormatter\Configurator\JavaScript\Minifier;
11  class ClosureCompilerApplication extends Minifier
12  {
13      public $closureCompilerBin;
14      public $compilationLevel = 'ADVANCED_OPTIMIZATIONS';
15      public $excludeDefaultExterns = \true;
16      public $javaBin = 'java';
17      public $options = '--use_types_for_optimization';
18      public function __construct($filepath = \null)
19      {
20          if (isset($filepath))
21          {
22              $this->closureCompilerBin = $filepath;
23              $this->testFilepaths();
24          }
25      }
26      public function getCacheDifferentiator()
27      {
28          $key = array(
29              $this->compilationLevel,
30              $this->excludeDefaultExterns,
31              $this->options,
32              $this->getClosureCompilerBinHash()
33          );
34          if ($this->excludeDefaultExterns)
35              $key[] = \file_get_contents(__DIR__ . '/../externs.application.js');
36          return $key;
37      }
38      public function minify($src)
39      {
40          $this->testFilepaths();
41          $options = ($this->options) ? ' ' . $this->options : '';
42          if ($this->excludeDefaultExterns && $this->compilationLevel === 'ADVANCED_OPTIMIZATIONS')
43              $options .= ' --externs ' . __DIR__ . '/../externs.application.js --env=CUSTOM';
44          $crc     = \crc32($src);
45          $inFile  = \sys_get_temp_dir() . '/' . $crc . '.js';
46          $outFile = \sys_get_temp_dir() . '/' . $crc . '.min.js';
47          \file_put_contents($inFile, $src);
48          $cmd = \escapeshellcmd($this->javaBin)
49               . ' -jar ' . \escapeshellarg($this->closureCompilerBin)
50               . ' --compilation_level ' . \escapeshellarg($this->compilationLevel)
51               . $options
52               . ' --js ' . \escapeshellarg($inFile)
53               . ' --js_output_file ' . \escapeshellarg($outFile);
54          \exec($cmd . ' 2>/dev/null', $output, $return);
55          \unlink($inFile);
56          if (\file_exists($outFile))
57          {
58              $src = \trim(\file_get_contents($outFile));
59              \unlink($outFile);
60          }
61          if (!empty($return))
62              throw new RuntimeException('An error occured during minification');
63          return $src;
64      }
65      protected function getClosureCompilerBinHash()
66      {
67          static $cache = array();
68          if (!isset($cache[$this->closureCompilerBin]))
69              $cache[$this->closureCompilerBin] = \md5_file($this->closureCompilerBin);
70          return $cache[$this->closureCompilerBin];
71      }
72      protected function testFilepaths()
73      {
74          if (!isset($this->closureCompilerBin))
75              throw new RuntimeException('No path set for Closure Compiler');
76          if (!\file_exists($this->closureCompilerBin))
77              throw new RuntimeException('Cannot find Closure Compiler at ' . $this->closureCompilerBin);
78      }
79  }