‪TYPO3CMS  10.4
SimpleNode.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
18 namespace ‪TYPO3\CMS\Core\Html;
19 
24 {
25  // similar to https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
26  public const ‪TYPE_ELEMENT = 1;
27  public const ‪TYPE_TEXT = 3;
28  public const ‪TYPE_CDATA = 4;
29  public const ‪TYPE_COMMENT = 8;
30 
34  protected ‪$type;
35 
39  protected ‪$index;
40 
44  protected ‪$string;
45 
46  public static function ‪fromString(int ‪$type, int ‪$index, string ‪$string): self
47  {
48  return new self(‪$type, ‪$index, ‪$string);
49  }
50 
51  public function ‪__construct(int ‪$type, int ‪$index, string ‪$string)
52  {
53  $this->type = ‪$type;
54  $this->index = ‪$index;
55  $this->string = ‪$string;
56  }
57 
58  public function ‪__toString(): string
59  {
60  return ‪$this->string;
61  }
62 
66  public function ‪getType(): int
67  {
68  return ‪$this->type;
69  }
70 
74  public function ‪getIndex(): int
75  {
77  }
78 
79  public function ‪getElementName(): ?string
80  {
81  if ($this->‪getType() !== self::TYPE_ELEMENT) {
82  return null;
83  }
84  if (!preg_match('#^<(?P<name>[a-z][a-z0-9-]*)\b#i', $this->string, $matches)) {
85  return null;
86  }
87  return $matches['name'];
88  }
89 }
‪TYPO3\CMS\Core\Html
Definition: DefaultSanitizerBuilder.php:15
‪TYPO3\CMS\Core\Html\SimpleNode\__toString
‪__toString()
Definition: SimpleNode.php:55
‪TYPO3\CMS\Core\Html\SimpleNode\$string
‪string $string
Definition: SimpleNode.php:41
‪TYPO3\CMS\Core\Html\SimpleNode\getType
‪int getType()
Definition: SimpleNode.php:63
‪TYPO3\CMS\Core\Html\SimpleNode\TYPE_ELEMENT
‪const TYPE_ELEMENT
Definition: SimpleNode.php:26
‪TYPO3\CMS\Core\Html\SimpleNode\fromString
‪static fromString(int $type, int $index, string $string)
Definition: SimpleNode.php:43
‪TYPO3\CMS\Core\Html\SimpleNode\getElementName
‪getElementName()
Definition: SimpleNode.php:76
‪TYPO3\CMS\Core\Html\SimpleNode\$index
‪int $index
Definition: SimpleNode.php:37
‪TYPO3\CMS\Core\Html\SimpleNode\TYPE_TEXT
‪const TYPE_TEXT
Definition: SimpleNode.php:27
‪TYPO3\CMS\Core\Html\SimpleNode\TYPE_COMMENT
‪const TYPE_COMMENT
Definition: SimpleNode.php:29
‪TYPO3\CMS\Core\Html\SimpleNode\__construct
‪__construct(int $type, int $index, string $string)
Definition: SimpleNode.php:48
‪TYPO3\CMS\Core\Html\SimpleNode\TYPE_CDATA
‪const TYPE_CDATA
Definition: SimpleNode.php:28
‪TYPO3\CMS\Core\Html\SimpleNode
Definition: SimpleNode.php:24
‪TYPO3\CMS\Core\Html\SimpleNode\getIndex
‪int getIndex()
Definition: SimpleNode.php:71
‪TYPO3\CMS\Core\Html\SimpleNode\$type
‪int $type
Definition: SimpleNode.php:33