PHP
6 days ago
LICENSE.md
6 days ago
README.md
6 days ago
class-xmlattributetoken.php
6 days ago
class-xmldecoder.php
6 days ago
class-xmlelement.php
6 days ago
class-xmlnativecursorprocessor.php
6 days ago
class-xmlprocessor.php
6 days ago
class-xmlunsupportedexception.php
6 days ago
composer.json
6 days ago
class-xmlelement.php
94 lines
| 1 | <?php |
| 2 | namespace WordPress\XML; |
| 3 | |
| 4 | /** |
| 5 | * XML API: XMLElement class |
| 6 | * |
| 7 | * @package WordPress |
| 8 | * @subpackage XML-API |
| 9 | * @since 6.2.0 |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * Core class used by the XML tag processor as a data structure for the attribute token, |
| 14 | * allowing to drastically improve performance. |
| 15 | * |
| 16 | * This class is for internal usage of the XMLProcessor class. |
| 17 | * |
| 18 | * @see XMLProcessor |
| 19 | */ |
| 20 | class XMLElement { |
| 21 | /** |
| 22 | * Local name. |
| 23 | * |
| 24 | * @var string |
| 25 | */ |
| 26 | public $local_name; |
| 27 | |
| 28 | /** |
| 29 | * Namespace Prefix. |
| 30 | * |
| 31 | * @var string |
| 32 | */ |
| 33 | public $namespace_prefix; |
| 34 | |
| 35 | /** |
| 36 | * Full XML namespace name. |
| 37 | * |
| 38 | * @var string |
| 39 | */ |
| 40 | public $namespace; |
| 41 | |
| 42 | /** |
| 43 | * Namespaces in current element's scope. |
| 44 | * |
| 45 | * @var array<string, string> |
| 46 | */ |
| 47 | public $namespaces_in_scope; |
| 48 | |
| 49 | /** |
| 50 | * Qualified name. |
| 51 | * |
| 52 | * @var string |
| 53 | */ |
| 54 | public $qualified_name; |
| 55 | |
| 56 | /** |
| 57 | * Constructor. |
| 58 | * |
| 59 | * @param string $local_name Local name. |
| 60 | * @param string $xml_namespace_prefix Namespace prefix. |
| 61 | * @param string $xml_namespace Full XML namespace name. |
| 62 | * @param array<string, string> $namespaces_in_scope Namespaces in current element's scope. |
| 63 | */ |
| 64 | public function __construct( $local_name, $xml_namespace_prefix, $xml_namespace, $namespaces_in_scope ) { |
| 65 | $this->local_name = $local_name; |
| 66 | $this->namespace_prefix = $xml_namespace_prefix; |
| 67 | $this->namespace = $xml_namespace; |
| 68 | $this->namespaces_in_scope = $namespaces_in_scope; |
| 69 | $this->qualified_name = $xml_namespace_prefix ? $xml_namespace_prefix . ':' . $local_name : $local_name; |
| 70 | } |
| 71 | |
| 72 | public function get_full_name() { |
| 73 | return $this->namespace ? '{' . $this->namespace . '}' . $this->local_name : $this->local_name; |
| 74 | } |
| 75 | |
| 76 | public function to_array() { |
| 77 | return array( |
| 78 | 'local_name' => $this->local_name, |
| 79 | 'namespace_prefix' => $this->namespace_prefix, |
| 80 | 'namespace' => $this->namespace, |
| 81 | 'namespaces_in_scope' => $this->namespaces_in_scope, |
| 82 | ); |
| 83 | } |
| 84 | |
| 85 | public static function from_array( $array_value ) { |
| 86 | return new self( |
| 87 | $array_value['local_name'], |
| 88 | $array_value['namespace_prefix'], |
| 89 | $array_value['namespace'], |
| 90 | $array_value['namespaces_in_scope'] |
| 91 | ); |
| 92 | } |
| 93 | } |
| 94 |