Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

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

Configurator.php

Zuletzt modifiziert: 02.04.2025, 15:04 - Dateigröße: 5.72 KiB


001  <?php
002   
003  /**
004  * @package   s9e\TextFormatter
005  * @copyright Copyright (c) 2010-2022 The s9e authors
006  * @license   http://www.opensource.org/licenses/mit-license.php The MIT License
007  */
008  namespace s9e\TextFormatter\Plugins\BBCodes;
009   
010  use ArrayAccess;
011  use Countable;
012  use InvalidArgumentException;
013  use Iterator;
014  use RuntimeException;
015  use s9e\TextFormatter\Configurator\Helpers\RegexpBuilder;
016  use s9e\TextFormatter\Configurator\Helpers\RegexpParser;
017  use s9e\TextFormatter\Configurator\JavaScript\Dictionary;
018  use s9e\TextFormatter\Configurator\Traits\CollectionProxy;
019  use s9e\TextFormatter\Plugins\BBCodes\Configurator\BBCode;
020  use s9e\TextFormatter\Plugins\BBCodes\Configurator\BBCodeCollection;
021  use s9e\TextFormatter\Plugins\BBCodes\Configurator\BBCodeMonkey;
022  use s9e\TextFormatter\Plugins\BBCodes\Configurator\Repository;
023  use s9e\TextFormatter\Plugins\BBCodes\Configurator\RepositoryCollection;
024  use s9e\TextFormatter\Plugins\ConfiguratorBase;
025   
026  /**
027  * @method mixed   add(string $key, mixed $value) Add an item to this collection
028  * @method array   asConfig()
029  * @method void    clear()                        Empty this collection
030  * @method bool    contains(mixed $value)         Test whether a given value is present in this collection
031  * @method integer count()
032  * @method mixed   current()
033  * @method void    delete(string $key)            Delete an item from this collection
034  * @method bool    exists(string $key)            Test whether an item of given key exists
035  * @method mixed   get(string $key)               Return a value from this collection
036  * @method mixed   indexOf(mixed $value)          Find the index of a given value
037  * @method integer|string key()
038  * @method mixed   next()
039  * @method string  normalizeKey(string $key)      Normalize an item's key
040  * @method mixed   normalizeValue(mixed $value)   Normalize a value for storage
041  * @method bool    offsetExists(string|integer $offset)
042  * @method mixed   offsetGet(string|integer $offset)
043  * @method void    offsetSet(string|integer $offset, mixed $value)
044  * @method void    offsetUnset(string|integer $offset)
045  * @method string  onDuplicate(string|null $action) Query and set the action to take when add() is called with a key that already exists
046  * @method void    rewind()
047  * @method mixed   set(string $key, mixed $value) Set and overwrite a value in this collection
048  * @method bool    valid()
049  */
050  class Configurator extends ConfiguratorBase implements ArrayAccess, Countable, Iterator
051  {
052      use CollectionProxy;
053   
054      /**
055      * @var BBCodeMonkey Instance of BBCodeMonkey used to parse definitions
056      */
057      public $bbcodeMonkey;
058   
059      /**
060      * @var BBCodeCollection BBCode collection
061      */
062      public $collection;
063   
064      /**
065      * {@inheritdoc}
066      */
067      protected $quickMatch = '[';
068   
069      /**
070      * {@inheritdoc}
071      */
072      protected $regexp = '#\\[/?(\\*|[-\\w]+)(?=[\\]\\s=:/])#';
073   
074      /**
075      * @var RepositoryCollection BBCode repositories
076      */
077      public $repositories;
078   
079      /**
080      * Plugin setup
081      *
082      * @return void
083      */
084      protected function setUp()
085      {
086          $this->bbcodeMonkey = new BBCodeMonkey($this->configurator);
087          $this->collection   = new BBCodeCollection;
088          $this->repositories = new RepositoryCollection($this->bbcodeMonkey);
089          $this->repositories->add('default', __DIR__ . '/Configurator/repository.xml');
090      }
091   
092      /**
093      * Add a BBCode using their human-readable representation
094      *
095      * @see s9e\TextFormatter\Plugins\BBCodes\Configurator\BBCodeMonkey
096      *
097      * @param  string $usage    BBCode's usage
098      * @param  string|\s9e\TextFormatter\Configurator\Items\Template $template BBCode's template
099      * @param  array  $options  Supported: 'tagName' and 'rules'
100      * @return BBCode           Newly-created BBCode
101      */
102      public function addCustom($usage, $template, array $options = [])
103      {
104          $config = $this->bbcodeMonkey->create($usage, $template);
105   
106          if (isset($options['tagName']))
107          {
108              $config['bbcode']->tagName = $options['tagName'];
109          }
110   
111          if (isset($options['rules']))
112          {
113              $config['tag']->rules->merge($options['rules']);
114          }
115   
116          return $this->addFromConfig($config);
117      }
118   
119      /**
120      * Add a BBCode from a repository
121      *
122      * @param  string $name       Name of the entry in the repository
123      * @param  mixed  $repository Name of the repository to use as source, or instance of Repository
124      * @param  array  $vars       Variables that will replace default values in the tag definition
125      * @return BBCode             Newly-created BBCode
126      */
127      public function addFromRepository($name, $repository = 'default', array $vars = [])
128      {
129          // Load the Repository if necessary
130          if (!($repository instanceof Repository))
131          {
132              if (!$this->repositories->exists($repository))
133              {
134                  throw new InvalidArgumentException("Repository '" . $repository . "' does not exist");
135              }
136   
137              $repository = $this->repositories->get($repository);
138          }
139   
140          return $this->addFromConfig($repository->get($name, $vars));
141      }
142   
143      /**
144      * Add a BBCode and its tag based on the return config from BBCodeMonkey
145      *
146      * @param  array  $config BBCodeMonkey::create()'s return array
147      * @return BBCode
148      */
149      protected function addFromConfig(array $config)
150      {
151          $bbcodeName = $config['bbcodeName'];
152          $bbcode     = $config['bbcode'];
153          $tag        = $config['tag'];
154   
155          // If the BBCode doesn't specify a tag name, it's the same as the BBCode
156          if (!isset($bbcode->tagName))
157          {
158              $bbcode->tagName = $bbcodeName;
159          }
160   
161          // Normalize this tag's templates
162          $this->configurator->templateNormalizer->normalizeTag($tag);
163   
164          // Test whether this BBCode/tag is safe before adding it
165          $this->configurator->templateChecker->checkTag($tag);
166   
167          // Add our BBCode then its tag
168          $this->collection->add($bbcodeName, $bbcode);
169          $this->configurator->tags->add($bbcode->tagName, $tag);
170   
171          return $bbcode;
172      }
173   
174      /**
175      * {@inheritdoc}
176      */
177      public function asConfig()
178      {
179          if (!count($this->collection))
180          {
181              return;
182          }
183   
184          return [
185              'bbcodes'    => $this->collection->asConfig(),
186              'quickMatch' => $this->quickMatch,
187              'regexp'     => $this->regexp
188          ];
189      }
190  }