[ Index ] |
PHP Cross Reference of phpBB-3.3.14-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package s9e\TextFormatter 5 * @copyright Copyright (c) 2010-2022 The s9e authors 6 * @license http://www.opensource.org/licenses/mit-license'); The MIT License 7 */ 8 namespace s9e\TextFormatter\Configurator; 9 10 use ArrayAccess; 11 use Iterator; 12 use s9e\TextFormatter\Configurator\Collections\TemplateNormalizationList; 13 use s9e\TextFormatter\Configurator\Helpers\TemplateLoader; 14 use s9e\TextFormatter\Configurator\Items\Tag; 15 use s9e\TextFormatter\Configurator\Traits\CollectionProxy; 16 17 /** 18 * @method mixed add(mixed $value, null $void) Add (append) a value to this list 19 * @method mixed append(mixed $value) Append a value to this list 20 * @method array asConfig() 21 * @method void clear() Empty this collection 22 * @method bool contains(mixed $value) Test whether a given value is present in this collection 23 * @method integer count() 24 * @method mixed current() 25 * @method void delete(string $key) Delete a value from this list and remove gaps in keys 26 * @method bool exists(string $key) Test whether an item of given key exists 27 * @method mixed get(string $key) Return a value from this collection 28 * @method mixed indexOf(mixed $value) Find the index of a given value 29 * @method mixed insert(integer $offset, mixed $value) Insert a value at an arbitrary 0-based position 30 * @method integer|string key() 31 * @method mixed next() 32 * @method integer normalizeKey(mixed $key) Ensure that the key is a valid offset 33 * @method AbstractNormalization normalizeValue(mixed $value) Normalize the value to an instance of AbstractNormalization 34 * @method bool offsetExists(string|integer $offset) 35 * @method mixed offsetGet(string|integer $offset) 36 * @method void offsetSet(mixed $offset, mixed $value) Custom offsetSet() implementation to allow assignment with a null offset to append to the 37 * @method void offsetUnset(string|integer $offset) 38 * @method string onDuplicate(string|null $action) Query and set the action to take when add() is called with a key that already exists 39 * @method mixed prepend(mixed $value) Prepend a value to this list 40 * @method integer remove(mixed $value) Remove all items matching given value 41 * @method void rewind() 42 * @method mixed set(string $key, mixed $value) Set and overwrite a value in this collection 43 * @method bool valid() 44 */ 45 class TemplateNormalizer implements ArrayAccess, Iterator 46 { 47 use CollectionProxy; 48 49 /** 50 * @var TemplateNormalizationList Collection of TemplateNormalization instances 51 */ 52 protected $collection; 53 54 /** 55 * @var string[] Default list of normalizations 56 */ 57 protected $defaultNormalizations = [ 58 'PreserveSingleSpaces', 59 'RemoveComments', 60 'RemoveInterElementWhitespace', 61 'NormalizeElementNames', 62 'FixUnescapedCurlyBracesInHtmlAttributes', 63 'EnforceHTMLOmittedEndTags', 64 'InlineCDATA', 65 'InlineElements', 66 'InlineTextElements', 67 'UninlineAttributes', 68 'MinifyXPathExpressions', 69 'NormalizeAttributeNames', 70 'OptimizeConditionalAttributes', 71 'FoldArithmeticConstants', 72 'FoldConstantXPathExpressions', 73 'InlineXPathLiterals', 74 'DeoptimizeIf', 75 'OptimizeChooseDeadBranches', 76 'OptimizeChooseText', 77 'OptimizeChoose', 78 'OptimizeConditionalValueOf', 79 'InlineAttributes', 80 'NormalizeUrls', 81 'InlineInferredValues', 82 'RenameLivePreviewEvent', 83 'SetRelNoreferrerOnTargetedLinks', 84 'MinifyInlineCSS' 85 ]; 86 87 /** 88 * @var integer Maximum number of iterations over a given template 89 */ 90 protected $maxIterations = 100; 91 92 /** 93 * Constructor 94 * 95 * Will load the default normalization rules if no list is passed 96 * 97 * @param array $normalizations List of normalizations 98 */ 99 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 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Mon Nov 25 19:05:08 2024 | Cross-referenced by PHPXref 0.7.1 |