‪TYPO3CMS  ‪main
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  {
61  }
62 
63  public function ‪getType(): int
64  {
66  }
67 
68  public function ‪getIndex(): int
69  {
71  }
72 
73  public function ‪getElementName(): ?string
74  {
75  if ($this->‪getType() !== self::TYPE_ELEMENT) {
76  return null;
77  }
78  if (!preg_match('#^<(?P<name>[a-z][a-z0-9-]*)\b#i', $this->string, $matches)) {
79  return null;
80  }
81  return $matches['name'];
82  }
83 }
‪TYPO3\CMS\Core\Html
Definition: DefaultSanitizerBuilder.php:18
‪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
‪getType()
Definition: SimpleNode.php:60
‪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:70
‪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\getIndex
‪getIndex()
Definition: SimpleNode.php:65
‪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\$type
‪int $type
Definition: SimpleNode.php:33