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

CallbackGenerator.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 2.52 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 CallbackGenerator
 10  {
 11      public $callbacks = array(
 12          'tags.*.attributes.*.filterChain.*' => array(
 13              'attrValue' => '*',
 14              'attrName'  => '!string'
 15          ),
 16          'tags.*.attributes.*.generator' => array(
 17              'attrName'  => '!string'
 18          ),
 19          'tags.*.filterChain.*' => array(
 20              'tag'       => '!Tag',
 21              'tagConfig' => '!Object'
 22          )
 23      );
 24      protected $encoder;
 25      public function __construct()
 26      {
 27          $this->encoder = new Encoder;
 28      }
 29      public function replaceCallbacks(array $config)
 30      {
 31          foreach ($this->callbacks as $path => $params)
 32              $config = $this->mapArray($config, \explode('.', $path), $params);
 33          return $config;
 34      }
 35      protected function buildCallbackArguments(array $params, array $localVars)
 36      {
 37          unset($params['parser']);
 38          $localVars += array('logger' => 1, 'openTags' => 1, 'registeredVars' => 1, 'text' => 1);
 39          $args = array();
 40          foreach ($params as $k => $v)
 41              if (isset($v))
 42                  $args[] = $this->encoder->encode($v);
 43              elseif (isset($localVars[$k]))
 44                  $args[] = $k;
 45              else
 46                  $args[] = 'registeredVars[' . \json_encode($k) . ']';
 47          return \implode(',', $args);
 48      }
 49      protected function generateFunction(array $config, array $params)
 50      {
 51          if ($config['js'] == 'returnFalse' || $config['js'] == 'returnTrue')
 52              return new Code((string) $config['js']);
 53          $config += array('params' => array());
 54          $src  = $this->getHeader($params);
 55          $src .= 'function(' . \implode(',', \array_keys($params)) . '){';
 56          $src .= 'return ' . $this->parenthesizeCallback($config['js']);
 57          $src .= '(' . $this->buildCallbackArguments($config['params'], $params) . ');}';
 58          return new Code($src);
 59      }
 60      protected function getHeader(array $params)
 61      {
 62          $header = "/**\n";
 63          foreach ($params as $paramName => $paramType)
 64              $header .= '* @param {' . $paramType . '} ' . $paramName . "\n";
 65          $header .= "*/\n";
 66          return $header;
 67      }
 68      protected function mapArray(array $array, array $path, array $params)
 69      {
 70          $key  = \array_shift($path);
 71          $keys = ($key === '*') ? \array_keys($array) : array($key);
 72          foreach ($keys as $key)
 73          {
 74              if (!isset($array[$key]))
 75                  continue;
 76              $array[$key] = (empty($path)) ? $this->generateFunction($array[$key], $params) : $this->mapArray($array[$key], $path, $params);
 77          }
 78          return $array;
 79      }
 80      protected function parenthesizeCallback($callback)
 81      {
 82          return (\preg_match('(^[.\\w]+$)D', $callback)) ? $callback : '(' . $callback  . ')';
 83      }
 84  }