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 |
AddAttributeValueToElements.php
01 <?php declare(strict_types=1);
02
03 /**
04 * @package s9e\TextFormatter
05 * @copyright Copyright (c) 2010-2022 The s9e authors
06 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
07 */
08 namespace s9e\TextFormatter\Configurator\TemplateNormalizations;
09
10 use DOMElement;
11
12 /**
13 * Add a value to a list of space-separated value
14 */
15 class AddAttributeValueToElements extends AbstractNormalization
16 {
17 /**
18 * @var string Name of the attribute to modify
19 */
20 protected $attrName;
21
22 /**
23 * @var string Value to be added to the attribute
24 */
25 protected $value;
26
27 /**
28 * @param string $query XPath query used to locate elements
29 * @param string $attrName Name of the attribute to modify
30 * @param string $value Value to be added to the attribute
31 */
32 public function __construct(string $query, string $attrName, string $value)
33 {
34 $this->attrName = $attrName;
35 $this->queries = [$query];
36 $this->value = $value;
37 }
38
39 /**
40 * Explode a string of space-separated values into an array
41 *
42 * @param string $attrValue Attribute's value
43 * @return string[]
44 */
45 protected function getValues(string $attrValue): array
46 {
47 return preg_match_all('(\\S++)', $attrValue, $m) ? $m[0] : [];
48 }
49
50 /**
51 * {@inheritdoc}
52 */
53 protected function normalizeElement(DOMElement $element): void
54 {
55 $currentValues = $this->getValues($element->getAttribute($this->attrName));
56 if (!in_array($this->value, $currentValues, true))
57 {
58 $currentValues[] = $this->value;
59
60 $element->setAttribute($this->attrName, implode(' ', $currentValues));
61 }
62 }
63 }