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

ConfigOptimizer.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 2.51 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;
09  class ConfigOptimizer
10  {
11      protected $configValues;
12      protected $encoder;
13      protected $jsLengths;
14      public function __construct(Encoder $encoder)
15      {
16          $this->encoder = $encoder;
17          $this->reset();
18      }
19      public function getVarDeclarations()
20      {
21          \asort($this->jsLengths);
22          $src = '';
23          foreach (\array_keys($this->jsLengths) as $varName)
24          {
25              $configValue = $this->configValues[$varName];
26              if ($configValue->isDeduplicated())
27                  $src .= '/** @const */ var ' . $varName . '=' . $this->encoder->encode($configValue->getValue()) . ";\n";
28          }
29          return $src;
30      }
31      public function optimize($object)
32      {
33          return \current($this->optimizeObjectContent(array($object)))->getValue();
34      }
35      public function reset()
36      {
37          $this->configValues = array();
38          $this->jsLengths    = array();
39      }
40      protected function canDeduplicate($value)
41      {
42          return (\is_array($value) || $value instanceof Code || $value instanceof Dictionary);
43      }
44      protected function deduplicateConfigValues()
45      {
46          \arsort($this->jsLengths);
47          foreach (\array_keys($this->jsLengths) as $varName)
48          {
49              $configValue = $this->configValues[$varName];
50              if ($configValue->getUseCount() > 1)
51                  $configValue->deduplicate();
52          }
53      }
54      protected function getVarName($js)
55      {
56          return \sprintf('o%08X', \crc32($js));
57      }
58      protected function isIterable($value)
59      {
60          return (\is_array($value) || $value instanceof Dictionary);
61      }
62      protected function optimizeObjectContent($object)
63      {
64          $object = $this->recordObject($object);
65          $this->deduplicateConfigValues();
66          return $object->getValue();
67      }
68      protected function recordObject($object)
69      {
70          $js      = $this->encoder->encode($object);
71          $varName = $this->getVarName($js);
72          if ($this->isIterable($object))
73              $object = $this->recordObjectContent($object);
74          if (!isset($this->configValues[$varName]))
75          {
76              $this->configValues[$varName] = new ConfigValue($object, $varName);
77              $this->jsLengths[$varName]    = \strlen($js);
78          }
79          $this->configValues[$varName]->incrementUseCount();
80          return $this->configValues[$varName];
81      }
82      protected function recordObjectContent($object)
83      {
84          foreach ($object as $k => $v)
85              if ($this->canDeduplicate($v) && !$this->shouldPreserve($v))
86                  $object[$k] = $this->recordObject($v);
87          return $object;
88      }
89      protected function shouldPreserve($value)
90      {
91          return ($value instanceof Code && \preg_match('(^\\w+$)', $value));
92      }
93  }