Skip to content

Commit 1156c1f

Browse files
committed
Fix namespace exclusion: s/self/static
1 parent 7fec9e3 commit 1156c1f

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

src/XML/ExtendableAttributesTrait.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ protected static function getAttributesNSFromXML(
9797
DOMElement $xml,
9898
string|array|null $namespace = null,
9999
): array {
100-
$namespace = $namespace ?? self::XS_ANY_ATTR_NAMESPACE;
100+
$namespace = $namespace ?? static::XS_ANY_ATTR_NAMESPACE;
101101
$exclusionList = self::getAttributeExclusions();
102102
$attributes = [];
103103

@@ -107,7 +107,11 @@ protected static function getAttributesNSFromXML(
107107
Assert::oneOf($namespace, NS::$PREDEFINED);
108108

109109
foreach ($xml->attributes as $a) {
110-
if (in_array([$a->namespaceURI, $a->localName], $exclusionList, true)) {
110+
if (
111+
$exclusionList
112+
&& (in_array([$a->namespaceURI, $a->localName], $exclusionList, true)
113+
|| in_array([$a->namespaceURI, '*'], $exclusionList, true))
114+
) {
111115
continue;
112116
} elseif ($namespace === NS::OTHER && in_array($a->namespaceURI, [self::NS, null], true)) {
113117
continue;
@@ -254,13 +258,13 @@ function (Attribute $attr) {
254258
public function getAttributeNamespace(): array|string
255259
{
256260
Assert::true(
257-
defined('self::XS_ANY_ATTR_NAMESPACE'),
261+
defined('static::XS_ANY_ATTR_NAMESPACE'),
258262
self::getClassName(self::class)
259263
. '::XS_ANY_ATTR_NAMESPACE constant must be defined and set to the namespace for the xs:anyAttribute.',
260264
RuntimeException::class,
261265
);
262266

263-
return self::XS_ANY_ATTR_NAMESPACE;
267+
return static::XS_ANY_ATTR_NAMESPACE;
264268
}
265269

266270

@@ -271,8 +275,8 @@ public function getAttributeNamespace(): array|string
271275
*/
272276
public static function getAttributeExclusions(): array
273277
{
274-
if (defined('self::XS_ANY_ATTR_EXCLUSIONS')) {
275-
return self::XS_ANY_ATTR_EXCLUSIONS;
278+
if (defined('static::XS_ANY_ATTR_EXCLUSIONS')) {
279+
return static::XS_ANY_ATTR_EXCLUSIONS;
276280
}
277281

278282
return [];

src/XML/ExtendableElementTrait.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ protected static function getChildElementsFromXML(
4545
DOMElement $xml,
4646
string|array|null $namespace = null,
4747
): array {
48-
$namespace = $namespace ?? self::XS_ANY_ELT_NAMESPACE;
48+
$namespace = $namespace ?? static::XS_ANY_ELT_NAMESPACE;
4949
$exclusionList = self::getElementExclusions();
5050
$registry = ElementRegistry::getInstance();
5151
$elements = [];
@@ -58,7 +58,11 @@ protected static function getChildElementsFromXML(
5858
foreach ($xml->childNodes as $elt) {
5959
if (!($elt instanceof DOMElement)) {
6060
continue;
61-
} elseif (in_array([$elt->namespaceURI, $elt->localName], $exclusionList, true)) {
61+
} elseif (
62+
$exclusionList
63+
&& (in_array([$elt->namespaceURI, $elt->localName], $exclusionList, true)
64+
|| in_array([$elt->namespaceURI, '*'], $exclusionList, true))
65+
) {
6266
continue;
6367
} elseif ($namespace === NS::OTHER && in_array($elt->namespaceURI, [self::NS, null], true)) {
6468
continue;
@@ -205,13 +209,13 @@ public function getElements(): array
205209
public function getElementNamespace(): array|string
206210
{
207211
Assert::true(
208-
defined('self::XS_ANY_ELT_NAMESPACE'),
212+
defined('static::XS_ANY_ELT_NAMESPACE'),
209213
self::getClassName(self::class)
210214
. '::XS_ANY_ELT_NAMESPACE constant must be defined and set to the namespace for the xs:any element.',
211215
RuntimeException::class,
212216
);
213217

214-
return self::XS_ANY_ELT_NAMESPACE;
218+
return static::XS_ANY_ELT_NAMESPACE;
215219
}
216220

217221

@@ -222,8 +226,8 @@ public function getElementNamespace(): array|string
222226
*/
223227
public static function getElementExclusions(): array
224228
{
225-
if (defined('self::XS_ANY_ELT_EXCLUSIONS')) {
226-
return self::XS_ANY_ELT_EXCLUSIONS;
229+
if (defined('static::XS_ANY_ELT_EXCLUSIONS')) {
230+
return static::XS_ANY_ELT_EXCLUSIONS;
227231
}
228232

229233
return [];

src/XMLSchema/XML/AbstractOpenAttrs.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
*/
1414
abstract class AbstractOpenAttrs extends AbstractAnyType
1515
{
16-
/** The namespace-attribute for the xs:any element */
17-
public const array XS_ANY_ELT_NAMESPACE = [];
18-
1916
/** The namespace-attribute for the xs:anyAttribute element */
2017
public const string XS_ANY_ATTR_NAMESPACE = NS::OTHER;
2118

0 commit comments

Comments
 (0)