1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\XML\Type; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use PREG_UNMATCHED_AS_NULL; |
|
|
|
|
9
|
|
|
use SimpleSAML\XML\Assert\Assert; |
10
|
|
|
use SimpleSAML\XML\Exception\SchemaViolationException; |
11
|
|
|
use SimpleSAML\XML\Type\{AnyURIValue, NCNameValue}; |
|
|
|
|
12
|
|
|
|
13
|
|
|
use function preg_match; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @package simplesaml/xml-common |
17
|
|
|
*/ |
18
|
|
|
class QNameValue extends AbstractValueType |
19
|
|
|
{ |
20
|
|
|
protected ?AnyURIValue $namespaceURI; |
21
|
|
|
protected ?NCNameValue $namespacePrefix; |
22
|
|
|
protected NCNameValue $localName; |
23
|
|
|
|
24
|
|
|
private static string $qname_regex = '/^ |
25
|
|
|
(?: |
26
|
|
|
\{ # Match a literal { |
27
|
|
|
(\S+) # Match one or more non-whitespace character |
28
|
|
|
\} # Match a literal } |
29
|
|
|
(?: |
30
|
|
|
([\w_][\w.-]*) # Match a-z or underscore followed by any word-character, dot or dash |
31
|
|
|
: # Match a literal : |
32
|
|
|
)? |
33
|
|
|
)? # Namespace and prefix are optional |
34
|
|
|
([\w_][\w.-]*) # Match a-z or underscore followed by any word-character, dot or dash |
35
|
|
|
$/Dimx'; |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Sanitize the value. |
40
|
|
|
* |
41
|
|
|
* @param string $value The unsanitized value |
42
|
|
|
* @return string |
43
|
|
|
*/ |
44
|
|
|
protected function sanitizeValue(string $value): string |
45
|
|
|
{ |
46
|
|
|
return static::collapseWhitespace(static::normalizeWhitespace($value)); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Validate the value. |
52
|
|
|
* |
53
|
|
|
* @param string $value |
54
|
|
|
* @throws \SimpleSAML\XML\Exception\SchemaViolationException on failure |
55
|
|
|
* @return void |
56
|
|
|
*/ |
57
|
|
|
protected function validateValue(string $value): void |
58
|
|
|
{ |
59
|
|
|
$qName = $this->sanitizeValue($value); |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Split our custom format of {<namespaceURI>}<prefix>:<localName> into individual parts |
63
|
|
|
*/ |
64
|
|
|
$result = preg_match( |
65
|
|
|
self::$qname_regex, |
66
|
|
|
$qName, |
67
|
|
|
$matches, |
68
|
|
|
PREG_UNMATCHED_AS_NULL, |
69
|
|
|
); |
70
|
|
|
|
71
|
|
|
if ($result && count($matches) === 4) { |
72
|
|
|
list($qName, $namespaceURI, $namespacePrefix, $localName) = $matches; |
73
|
|
|
|
74
|
|
|
$this->namespaceURI = ($namespaceURI !== null) ? AnyURIValue::fromString($namespaceURI) : null; |
75
|
|
|
$this->namespacePrefix = ($namespacePrefix !== null) ? NCNameValue::fromString($namespacePrefix) : null; |
76
|
|
|
$this->localName = NCNameValue::fromString($localName); |
77
|
|
|
} else { |
78
|
|
|
throw new SchemaViolationException(sprintf('\'%s\' is not a valid xs:QName.', $qName)); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Get the value. |
85
|
|
|
* |
86
|
|
|
* @return string |
87
|
|
|
*/ |
88
|
|
|
public function getValue(): string |
89
|
|
|
{ |
90
|
|
|
return $this->getNamespacePrefix() . ':' . $this->getLocalName(); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Get the namespaceURI for this qualified name. |
96
|
|
|
* |
97
|
|
|
* @return \SimpleSAML\SAML11\Type\AnyURIValue|null |
|
|
|
|
98
|
|
|
*/ |
99
|
|
|
public function getNamespaceURI(): ?AnyURIValue |
100
|
|
|
{ |
101
|
|
|
return $this->namespaceURI; |
|
|
|
|
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Get the namespace-prefix for this qualified name. |
107
|
|
|
* |
108
|
|
|
* @return \SimpleSAML\XML\Type\NCNameValue|null |
109
|
|
|
*/ |
110
|
|
|
public function getNamespacePrefix(): ?NCNameValue |
111
|
|
|
{ |
112
|
|
|
return $this->namespacePrefix; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Get the local name for this qualified name. |
118
|
|
|
* |
119
|
|
|
* @return \SimpleSAML\XML\Type\NCNameValue |
120
|
|
|
*/ |
121
|
|
|
public function getLocalName(): NCNameValue |
122
|
|
|
{ |
123
|
|
|
return $this->localName; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @param \SimpleSAML\XML\Type\NCNameValue $localName |
129
|
|
|
* @param \SimpleSAML\XML\Type\AnyURIValue|null $namespaceURI |
130
|
|
|
* @param \SimpleSAML\XML\Type\NCNameValue|null $namespacePrefix |
131
|
|
|
* @return static |
132
|
|
|
*/ |
133
|
|
|
public static function fromParts( |
134
|
|
|
NCNameValue $localName, |
135
|
|
|
?AnyURIValue $namespaceURI, |
136
|
|
|
?NCNameValue $namespacePrefix, |
137
|
|
|
): static { |
138
|
|
|
if ($namespaceURI === null) { |
139
|
|
|
// If we don't have a namespace, we can't have a prefix either |
140
|
|
|
Assert::null($namespacePrefix, SchemaViolationException::class); |
141
|
|
|
return new static($localName); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
return new static( |
145
|
|
|
'{' . $namespaceURI->getValue() . '}' |
146
|
|
|
. ($namespacePrefix ? ($namespacePrefix->getValue() . ':') : '') |
147
|
|
|
. $localName, |
148
|
|
|
); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @param string $qname |
154
|
|
|
*/ |
155
|
|
|
public static function fromDocument( |
156
|
|
|
string $qName, |
157
|
|
|
DOMElement $element, |
158
|
|
|
) { |
159
|
|
|
$namespacePrefix = null; |
160
|
|
|
if (str_contains($qName, ':')) { |
161
|
|
|
list($namespacePrefix, $localName) = explode(':', $qName, 2); |
162
|
|
|
} else { |
163
|
|
|
// No prefix |
164
|
|
|
$localName = $qName; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
// Will return the default namespace (if any) when prefix is NULL |
168
|
|
|
$namespaceURI = $element->lookupNamespaceUri($namespacePrefix); |
169
|
|
|
|
170
|
|
|
return new static('{' . $namespaceURI . '}' . $namespacePrefix . ':' . $localName); |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths