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

ClosureCompilerService.php

Zuletzt modifiziert: 09.10.2024, 12:59 - Dateigröße: 2.84 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\OnlineMinifier;
 11  class ClosureCompilerService extends OnlineMinifier
 12  {
 13      public $compilationLevel = 'ADVANCED_OPTIMIZATIONS';
 14      public $excludeDefaultExterns = \true;
 15      public $externs;
 16      public $url = 'http://closure-compiler.appspot.com/compile';
 17      public function __construct()
 18      {
 19          parent::__construct();
 20          $this->externs = \file_get_contents(__DIR__ . '/../externs.service.js');
 21      }
 22      public function getCacheDifferentiator()
 23      {
 24          $key = array($this->compilationLevel, $this->excludeDefaultExterns);
 25          if ($this->excludeDefaultExterns)
 26              $key[] = $this->externs;
 27          return $key;
 28      }
 29      public function minify($src)
 30      {
 31          $body     = $this->generateRequestBody($src);
 32          $response = $this->query($body);
 33          if ($response === \false)
 34              throw new RuntimeException('Could not contact the Closure Compiler service');
 35          return $this->decodeResponse($response);
 36      }
 37      protected function decodeResponse($response)
 38      {
 39          $response = \json_decode($response, \true);
 40          if (\is_null($response))
 41          {
 42              $msgs = array(
 43                      \JSON_ERROR_NONE => 'No error',
 44                      \JSON_ERROR_DEPTH => 'Maximum stack depth exceeded',
 45                      \JSON_ERROR_STATE_MISMATCH => 'State mismatch (invalid or malformed JSON)',
 46                      \JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded',
 47                      \JSON_ERROR_SYNTAX => 'Syntax error',
 48                      \JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded'
 49                  );
 50                  throw new RuntimeException('Closure Compiler service returned invalid JSON: ' . (isset($msgs[\json_last_error()]) ? $msgs[\json_last_error()] : 'Unknown error'));
 51          }
 52          if (isset($response['serverErrors'][0]))
 53          {
 54              $error = $response['serverErrors'][0];
 55              throw new RuntimeException('Server error ' . $error['code'] . ': ' . $error['error']);
 56          }
 57          if (isset($response['errors'][0]))
 58          {
 59              $error = $response['errors'][0];
 60              throw new RuntimeException('Compilation error: ' . $error['error']);
 61          }
 62          return $response['compiledCode'];
 63      }
 64      protected function generateRequestBody($src)
 65      {
 66          $params = array(
 67              'compilation_level' => $this->compilationLevel,
 68              'js_code'           => $src,
 69              'output_format'     => 'json',
 70              'output_info'       => 'compiled_code'
 71          );
 72          if ($this->excludeDefaultExterns && $this->compilationLevel === 'ADVANCED_OPTIMIZATIONS')
 73          {
 74              $params['exclude_default_externs'] = 'true';
 75              $params['js_externs'] = $this->externs;
 76          }
 77          $body = \http_build_query($params) . '&output_info=errors';
 78          return $body;
 79      }
 80      protected function query($body)
 81      {
 82          return $this->httpClient->post(
 83              $this->url,
 84              array('Content-Type: application/x-www-form-urlencoded'),
 85              $body
 86          );
 87      }
 88  }