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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
TemplateNormalizer.php
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'); The MIT License
007 */
008 namespace s9e\TextFormatter\Configurator;
009
010 use ArrayAccess;
011 use Iterator;
012 use s9e\TextFormatter\Configurator\Collections\TemplateNormalizationList;
013 use s9e\TextFormatter\Configurator\Helpers\TemplateLoader;
014 use s9e\TextFormatter\Configurator\Items\Tag;
015 use s9e\TextFormatter\Configurator\Traits\CollectionProxy;
016
017 /**
018 * @method mixed add(mixed $value, null $void) Add (append) a value to this list
019 * @method mixed append(mixed $value) Append a value to this list
020 * @method array asConfig()
021 * @method void clear() Empty this collection
022 * @method bool contains(mixed $value) Test whether a given value is present in this collection
023 * @method integer count()
024 * @method mixed current()
025 * @method void delete(string $key) Delete a value from this list and remove gaps in keys
026 * @method bool exists(string $key) Test whether an item of given key exists
027 * @method mixed get(string $key) Return a value from this collection
028 * @method mixed indexOf(mixed $value) Find the index of a given value
029 * @method mixed insert(integer $offset, mixed $value) Insert a value at an arbitrary 0-based position
030 * @method integer|string key()
031 * @method mixed next()
032 * @method integer normalizeKey(mixed $key) Ensure that the key is a valid offset
033 * @method AbstractNormalization normalizeValue(mixed $value) Normalize the value to an instance of AbstractNormalization
034 * @method bool offsetExists(string|integer $offset)
035 * @method mixed offsetGet(string|integer $offset)
036 * @method void offsetSet(mixed $offset, mixed $value) Custom offsetSet() implementation to allow assignment with a null offset to append to the
037 * @method void offsetUnset(string|integer $offset)
038 * @method string onDuplicate(string|null $action) Query and set the action to take when add() is called with a key that already exists
039 * @method mixed prepend(mixed $value) Prepend a value to this list
040 * @method integer remove(mixed $value) Remove all items matching given value
041 * @method void rewind()
042 * @method mixed set(string $key, mixed $value) Set and overwrite a value in this collection
043 * @method bool valid()
044 */
045 class TemplateNormalizer implements ArrayAccess, Iterator
046 {
047 use CollectionProxy;
048
049 /**
050 * @var TemplateNormalizationList Collection of TemplateNormalization instances
051 */
052 protected $collection;
053
054 /**
055 * @var string[] Default list of normalizations
056 */
057 protected $defaultNormalizations = [
058 'PreserveSingleSpaces',
059 'RemoveComments',
060 'RemoveInterElementWhitespace',
061 'NormalizeElementNames',
062 'FixUnescapedCurlyBracesInHtmlAttributes',
063 'EnforceHTMLOmittedEndTags',
064 'InlineCDATA',
065 'InlineElements',
066 'InlineTextElements',
067 'UninlineAttributes',
068 'MinifyXPathExpressions',
069 'NormalizeAttributeNames',
070 'OptimizeConditionalAttributes',
071 'FoldArithmeticConstants',
072 'FoldConstantXPathExpressions',
073 'InlineXPathLiterals',
074 'DeoptimizeIf',
075 'OptimizeChooseDeadBranches',
076 'OptimizeChooseText',
077 'OptimizeChoose',
078 'OptimizeConditionalValueOf',
079 'InlineAttributes',
080 'NormalizeUrls',
081 'InlineInferredValues',
082 'RenameLivePreviewEvent',
083 'SetRelNoreferrerOnTargetedLinks',
084 'MinifyInlineCSS'
085 ];
086
087 /**
088 * @var integer Maximum number of iterations over a given template
089 */
090 protected $maxIterations = 100;
091
092 /**
093 * Constructor
094 *
095 * Will load the default normalization rules if no list is passed
096 *
097 * @param array $normalizations List of normalizations
098 */
099 public function __construct(array $normalizations = null)
100 {
101 if (!isset($normalizations))
102 {
103 $normalizations = $this->defaultNormalizations;
104 }
105
106 $this->collection = new TemplateNormalizationList;
107 foreach ($normalizations as $normalization)
108 {
109 $this->collection->append($normalization);
110 }
111 }
112
113 /**
114 * Normalize a tag's template
115 *
116 * @param Tag $tag Tag whose template will be normalized
117 * @return void
118 */
119 public function normalizeTag(Tag $tag)
120 {
121 if (isset($tag->template) && !$tag->template->isNormalized())
122 {
123 $tag->template->normalize($this);
124 }
125 }
126
127 /**
128 * Normalize a template
129 *
130 * @param string $template Original template
131 * @return string Normalized template
132 */
133 public function normalizeTemplate($template)
134 {
135 $dom = TemplateLoader::load($template);
136
137 // Apply all the normalizations until no more change is made or we've reached the maximum
138 // number of loops
139 $i = 0;
140 do
141 {
142 $old = $template;
143 foreach ($this->collection as $k => $normalization)
144 {
145 $normalization->normalize($dom->documentElement);
146 }
147 $template = TemplateLoader::save($dom);
148 }
149 while (++$i < $this->maxIterations && $template !== $old);
150
151 return $template;
152 }
153 }