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

Encoder.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 4.05 KiB


001  <?php
002   
003  /*
004  * @package   s9e\TextFormatter
005  * @copyright Copyright (c) 2010-2016 The s9e Authors
006  * @license   http://www.opensource.org/licenses/mit-license.php The MIT License
007  */
008  namespace s9e\TextFormatter\Configurator\JavaScript;
009  use RuntimeException;
010  use s9e\TextFormatter\Configurator\Items\Regexp;
011  use s9e\TextFormatter\Configurator\JavaScript\Code;
012  use s9e\TextFormatter\Configurator\JavaScript\Dictionary;
013  use s9e\TextFormatter\Configurator\JavaScript\Encoder;
014  class Encoder
015  {
016      public $objectEncoders;
017      public $typeEncoders;
018      public function __construct()
019      {
020          $ns = 's9e\\TextFormatter\\Configurator\\';
021          $this->objectEncoders = array(
022              $ns . 'Items\\Regexp'           => array($this, 'encodeRegexp'),
023              $ns . 'JavaScript\\Code'        => array($this, 'encodeCode'),
024              $ns . 'JavaScript\\ConfigValue' => array($this, 'encodeConfigValue'),
025              $ns . 'JavaScript\\Dictionary'  => array($this, 'encodeDictionary')
026          );
027          $this->typeEncoders = array(
028              'array'   => array($this, 'encodeArray'),
029              'boolean' => array($this, 'encodeBoolean'),
030              'double'  => array($this, 'encodeScalar'),
031              'integer' => array($this, 'encodeScalar'),
032              'object'  => array($this, 'encodeObject'),
033              'string'  => array($this, 'encodeScalar')
034          );
035      }
036      public function encode($value)
037      {
038          $type = \gettype($value);
039          if (!isset($this->typeEncoders[$type]))
040              throw new RuntimeException('Cannot encode ' . $type . ' value');
041          return \call_user_func($this->typeEncoders[$type], $value);
042      }
043      protected function encodeArray(array $array)
044      {
045          return ($this->isIndexedArray($array)) ? $this->encodeIndexedArray($array) : $this->encodeAssociativeArray($array);
046      }
047      protected function encodeAssociativeArray(array $array, $preserveNames = \false)
048      {
049          \ksort($array);
050          $src = '{';
051          $sep = '';
052          foreach ($array as $k => $v)
053          {
054              $src .= $sep . $this->encodePropertyName("$k", $preserveNames) . ':' . $this->encode($v);
055              $sep = ',';
056          }
057          $src .= '}';
058          return $src;
059      }
060      protected function encodeBoolean($value)
061      {
062          return ($value) ? '!0' : '!1';
063      }
064      protected function encodeCode(Code $code)
065      {
066          return (string) $code;
067      }
068      protected function encodeConfigValue(ConfigValue $configValue)
069      {
070          return ($configValue->isDeduplicated()) ? $configValue->getVarName() : $this->encode($configValue->getValue());
071      }
072      protected function encodeDictionary(Dictionary $dict)
073      {
074          return $this->encodeAssociativeArray($dict->getArrayCopy(), \true);
075      }
076      protected function encodeIndexedArray(array $array)
077      {
078          return '[' . \implode(',', \array_map(array($this, 'encode'), $array)) . ']';
079      }
080      protected function encodeObject($object)
081      {
082          foreach ($this->objectEncoders as $className => $callback)
083              if ($object instanceof $className)
084                  return \call_user_func($callback, $object);
085          throw new RuntimeException('Cannot encode instance of ' . \get_class($object));
086      }
087      protected function encodePropertyName($name, $preserveNames)
088      {
089          return ($preserveNames || !$this->isLegalProp($name)) ? \json_encode($name) : $name;
090      }
091      protected function encodeRegexp(Regexp $regexp)
092      {
093          return $regexp->getJS();
094      }
095      protected function encodeScalar($value)
096      {
097          return \json_encode($value);
098      }
099      protected function isIndexedArray(array $array)
100      {
101          if (empty($array))
102              return \true;
103          if (isset($array[0]) && \array_keys($array) === \range(0, \count($array) - 1))
104              return \true;
105          return \false;
106      }
107      protected function isLegalProp($name)
108      {
109          $reserved = array('abstract', 'boolean', 'break', 'byte', 'case', 'catch', 'char', 'class', 'const', 'continue', 'debugger', 'default', 'delete', 'do', 'double', 'else', 'enum', 'export', 'extends', 'false', 'final', 'finally', 'float', 'for', 'function', 'goto', 'if', 'implements', 'import', 'in', 'instanceof', 'int', 'interface', 'let', 'long', 'native', 'new', 'null', 'package', 'private', 'protected', 'public', 'return', 'short', 'static', 'super', 'switch', 'synchronized', 'this', 'throw', 'throws', 'transient', 'true', 'try', 'typeof', 'var', 'void', 'volatile', 'while', 'with');
110          if (\in_array($name, $reserved, \true))
111              return \false;
112          return (bool) \preg_match('#^(?![0-9])[$_\\pL][$_\\pL\\pNl]+$#Du', $name);
113      }
114  }