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

Tag.php

Zuletzt modifiziert: 02.04.2025, 15:04 - Dateigröße: 5.94 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\Configurator\Items;
009   
010  use InvalidArgumentException;
011  use s9e\TextFormatter\Configurator\Collections\AttributeCollection;
012  use s9e\TextFormatter\Configurator\Collections\AttributePreprocessorCollection;
013  use s9e\TextFormatter\Configurator\Collections\Ruleset;
014  use s9e\TextFormatter\Configurator\Collections\TagFilterChain;
015  use s9e\TextFormatter\Configurator\ConfigProvider;
016  use s9e\TextFormatter\Configurator\Helpers\ConfigHelper;
017  use s9e\TextFormatter\Configurator\Items\Template;
018  use s9e\TextFormatter\Configurator\Traits\Configurable;
019   
020  /**
021  * @property AttributeCollection $attributes This tag's attributes
022  * @property AttributePreprocessorCollection $attributePreprocessors This tag's attribute parsers
023  * @property TagFilterChain $filterChain This tag's filter chain
024  * @property integer $nestingLimit Maximum nesting level for this tag
025  * @property Ruleset $rules Rules associated with this tag
026  * @property integer $tagLimit Maximum number of this tag per message
027  * @property-read Template $template Template associated with this tag
028  * @property-write string|Template $template Template associated with this tag
029  */
030  class Tag implements ConfigProvider
031  {
032      use Configurable;
033   
034      /**
035      * @var AttributeCollection This tag's attributes
036      */
037      protected $attributes;
038   
039      /**
040      * @var AttributePreprocessorCollection This tag's attribute parsers
041      */
042      protected $attributePreprocessors;
043   
044      /**
045      * @var TagFilterChain This tag's filter chain
046      */
047      protected $filterChain;
048   
049      /**
050      * @var integer Maximum nesting level for this tag
051      */
052      protected $nestingLimit = 10;
053   
054      /**
055      * @var Ruleset Rules associated with this tag
056      */
057      protected $rules;
058   
059      /**
060      * @var integer Maximum number of this tag per message
061      */
062      protected $tagLimit = 5000;
063   
064      /**
065      * @var Template Template associated with this tag
066      */
067      protected $template;
068   
069      /**
070      * Constructor
071      *
072      * @param  array $options This tag's options
073      */
074      public function __construct(array $options = null)
075      {
076          $this->attributes             = new AttributeCollection;
077          $this->attributePreprocessors = new AttributePreprocessorCollection;
078          $this->filterChain            = new TagFilterChain;
079          $this->rules                  = new Ruleset;
080   
081          // Start the filterChain with the default processing
082          $this->filterChain->append('s9e\\TextFormatter\\Parser\\FilterProcessing::executeAttributePreprocessors')
083                            ->addParameterByName('tagConfig')
084                            ->setJS('executeAttributePreprocessors');
085   
086          $this->filterChain->append('s9e\\TextFormatter\\Parser\\FilterProcessing::filterAttributes')
087                            ->addParameterByName('tagConfig')
088                            ->addParameterByName('registeredVars')
089                            ->addParameterByName('logger')
090                            ->setJS('filterAttributes');
091   
092          if (isset($options))
093          {
094              // Sort the options by name so that attributes are set before the template, which is
095              // necessary to evaluate whether the template is safe
096              ksort($options);
097   
098              foreach ($options as $optionName => $optionValue)
099              {
100                  $this->__set($optionName, $optionValue);
101              }
102          }
103      }
104   
105      /**
106      * {@inheritdoc}
107      */
108      public function asConfig()
109      {
110          $vars = get_object_vars($this);
111   
112          // Remove properties that are not needed during parsing
113          unset($vars['template']);
114   
115          // If there are no attribute preprocessors defined, we can remove the step from this tag's
116          // filterChain
117          if (!count($this->attributePreprocessors))
118          {
119              $callback = 's9e\\TextFormatter\\Parser\\FilterProcessing::executeAttributePreprocessors';
120   
121              // We operate on a copy of the filterChain, without modifying the original
122              $filterChain = clone $vars['filterChain'];
123   
124              // Process the chain in reverse order so that we don't skip indices
125              $i = count($filterChain);
126              while (--$i >= 0)
127              {
128                  if ($filterChain[$i]->getCallback() === $callback)
129                  {
130                      unset($filterChain[$i]);
131                  }
132              }
133   
134              $vars['filterChain'] = $filterChain;
135          }
136   
137          return ConfigHelper::toArray($vars) + ['attributes' => [], 'filterChain' => []];
138      }
139   
140      /**
141      * Return this tag's template
142      *
143      * @return Template
144      */
145      public function getTemplate()
146      {
147          return $this->template;
148      }
149   
150      /**
151      * Test whether this tag has a template
152      *
153      * @return bool
154      */
155      public function issetTemplate()
156      {
157          return isset($this->template);
158      }
159   
160      /**
161      * Set this tag's attribute preprocessors
162      *
163      * @param  array|AttributePreprocessorCollection $attributePreprocessors 2D array of [attrName=>[regexp]], or an instance of AttributePreprocessorCollection
164      * @return void
165      */
166      public function setAttributePreprocessors($attributePreprocessors)
167      {
168          $this->attributePreprocessors->clear();
169          $this->attributePreprocessors->merge($attributePreprocessors);
170      }
171   
172      /**
173      * Set this tag's nestingLimit
174      *
175      * @param  integer $limit
176      * @return void
177      */
178      public function setNestingLimit($limit)
179      {
180          $limit = (int) $limit;
181   
182          if ($limit < 1)
183          {
184              throw new InvalidArgumentException('nestingLimit must be a number greater than 0');
185          }
186   
187          $this->nestingLimit = $limit;
188      }
189   
190      /**
191      * Set this tag's rules
192      *
193      * @param  array|Ruleset $rules 2D array of rule definitions, or instance of Ruleset
194      * @return void
195      */
196      public function setRules($rules)
197      {
198          $this->rules->clear();
199          $this->rules->merge($rules);
200      }
201   
202      /**
203      * Set this tag's tagLimit
204      *
205      * @param  integer $limit
206      * @return void
207      */
208      public function setTagLimit($limit)
209      {
210          $limit = (int) $limit;
211   
212          if ($limit < 1)
213          {
214              throw new InvalidArgumentException('tagLimit must be a number greater than 0');
215          }
216   
217          $this->tagLimit = $limit;
218      }
219   
220      /**
221      * Set the template associated with this tag
222      *
223      * @param  string|Template $template
224      * @return void
225      */
226      public function setTemplate($template)
227      {
228          if (!($template instanceof Template))
229          {
230              $template = new Template($template);
231          }
232   
233          $this->template = $template;
234      }
235   
236      /**
237      * Unset this tag's template
238      *
239      * @return void
240      */
241      public function unsetTemplate()
242      {
243          unset($this->template);
244      }
245  }