@@ -4,27 +4,27 @@ |
||
4 | 4 | |
5 | 5 | class Rfc3339 |
6 | 6 | { |
7 | - const REGEX = '/^(\d{4}-\d{2}-\d{2}[T ]{1}\d{2}:\d{2}:\d{2})(\.\d+)?(Z|([+-]\d{2}):?(\d{2}))$/'; |
|
7 | + const REGEX = '/^(\d{4}-\d{2}-\d{2}[T ]{1}\d{2}:\d{2}:\d{2})(\.\d+)?(Z|([+-]\d{2}):?(\d{2}))$/'; |
|
8 | 8 | |
9 | - /** |
|
10 | - * Try creating a DateTime instance |
|
11 | - * |
|
12 | - * @param string $string |
|
13 | - * |
|
14 | - * @return \DateTime|null |
|
15 | - */ |
|
16 | - public static function createFromString($string) |
|
17 | - { |
|
18 | - if (!preg_match(self::REGEX, strtoupper($string), $matches)) { |
|
19 | - return null; |
|
20 | - } |
|
9 | + /** |
|
10 | + * Try creating a DateTime instance |
|
11 | + * |
|
12 | + * @param string $string |
|
13 | + * |
|
14 | + * @return \DateTime|null |
|
15 | + */ |
|
16 | + public static function createFromString($string) |
|
17 | + { |
|
18 | + if (!preg_match(self::REGEX, strtoupper($string), $matches)) { |
|
19 | + return null; |
|
20 | + } |
|
21 | 21 | |
22 | - $dateAndTime = $matches[1]; |
|
23 | - $microseconds = $matches[2] ?: '.000000'; |
|
24 | - $timeZone = 'Z' !== $matches[3] ? $matches[4] . ':' . $matches[5] : '+00:00'; |
|
25 | - $dateFormat = strpos($dateAndTime, 'T') === false ? 'Y-m-d H:i:s.uP' : 'Y-m-d\TH:i:s.uP'; |
|
26 | - $dateTime = \DateTime::createFromFormat($dateFormat, $dateAndTime . $microseconds . $timeZone, new \DateTimeZone('UTC')); |
|
22 | + $dateAndTime = $matches[1]; |
|
23 | + $microseconds = $matches[2] ?: '.000000'; |
|
24 | + $timeZone = 'Z' !== $matches[3] ? $matches[4] . ':' . $matches[5] : '+00:00'; |
|
25 | + $dateFormat = strpos($dateAndTime, 'T') === false ? 'Y-m-d H:i:s.uP' : 'Y-m-d\TH:i:s.uP'; |
|
26 | + $dateTime = \DateTime::createFromFormat($dateFormat, $dateAndTime . $microseconds . $timeZone, new \DateTimeZone('UTC')); |
|
27 | 27 | |
28 | - return $dateTime ?: null; |
|
29 | - } |
|
28 | + return $dateTime ?: null; |
|
29 | + } |
|
30 | 30 | } |
@@ -10,160 +10,160 @@ |
||
10 | 10 | |
11 | 11 | class SchemaStorage implements SchemaStorageInterface |
12 | 12 | { |
13 | - const INTERNAL_PROVIDED_SCHEMA_URI = 'internal://provided-schema/'; |
|
14 | - |
|
15 | - protected $uriRetriever; |
|
16 | - protected $uriResolver; |
|
17 | - protected $schemas = array(); |
|
18 | - |
|
19 | - public function __construct( |
|
20 | - UriRetrieverInterface $uriRetriever = null, |
|
21 | - UriResolverInterface $uriResolver = null |
|
22 | - ) { |
|
23 | - $this->uriRetriever = $uriRetriever ?: new UriRetriever(); |
|
24 | - $this->uriResolver = $uriResolver ?: new UriResolver(); |
|
25 | - } |
|
26 | - |
|
27 | - /** |
|
28 | - * @return UriRetrieverInterface |
|
29 | - */ |
|
30 | - public function getUriRetriever() |
|
31 | - { |
|
32 | - return $this->uriRetriever; |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * @return UriResolverInterface |
|
37 | - */ |
|
38 | - public function getUriResolver() |
|
39 | - { |
|
40 | - return $this->uriResolver; |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * {@inheritdoc} |
|
45 | - */ |
|
46 | - public function addSchema($id, $schema = null) |
|
47 | - { |
|
48 | - if (is_null($schema) && $id !== self::INTERNAL_PROVIDED_SCHEMA_URI) { |
|
49 | - // if the schema was user-provided to Validator and is still null, then assume this is |
|
50 | - // what the user intended, as there's no way for us to retrieve anything else. User-supplied |
|
51 | - // schemas do not have an associated URI when passed via Validator::validate(). |
|
52 | - $schema = $this->uriRetriever->retrieve($id); |
|
53 | - } |
|
54 | - |
|
55 | - // cast array schemas to object |
|
56 | - if (is_array($schema)) { |
|
57 | - $schema = BaseConstraint::arrayToObjectRecursive($schema); |
|
58 | - } |
|
59 | - |
|
60 | - // workaround for bug in draft-03 & draft-04 meta-schemas (id & $ref defined with incorrect format) |
|
61 | - // see https://github.com/json-schema-org/JSON-Schema-Test-Suite/issues/177#issuecomment-293051367 |
|
62 | - if (is_object($schema) && property_exists($schema, 'id')) { |
|
63 | - if ($schema->id == 'http://json-schema.org/draft-04/schema#') { |
|
64 | - $schema->properties->id->format = 'uri-reference'; |
|
65 | - } elseif ($schema->id == 'http://json-schema.org/draft-03/schema#') { |
|
66 | - $schema->properties->id->format = 'uri-reference'; |
|
67 | - $schema->properties->{'$ref'}->format = 'uri-reference'; |
|
68 | - } |
|
69 | - } |
|
70 | - |
|
71 | - // resolve references |
|
72 | - $this->expandRefs($schema, $id); |
|
73 | - |
|
74 | - $this->schemas[$id] = $schema; |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Recursively resolve all references against the provided base |
|
79 | - * |
|
80 | - * @param mixed $schema |
|
81 | - * @param string $base |
|
82 | - */ |
|
83 | - private function expandRefs(&$schema, $base = null) |
|
84 | - { |
|
85 | - if (!is_object($schema)) { |
|
86 | - if (is_array($schema)) { |
|
87 | - foreach ($schema as &$member) { |
|
88 | - $this->expandRefs($member, $base); |
|
89 | - } |
|
90 | - } |
|
91 | - |
|
92 | - return; |
|
93 | - } |
|
94 | - |
|
95 | - if (property_exists($schema, 'id') && is_string($schema->id) && $base != $schema->id) { |
|
96 | - $base = $this->uriResolver->resolve($schema->id, $base); |
|
97 | - } |
|
98 | - |
|
99 | - if (property_exists($schema, '$ref') && is_string($schema->{'$ref'})) { |
|
100 | - $refPointer = new JsonPointer($this->uriResolver->resolve($schema->{'$ref'}, $base)); |
|
101 | - $schema->{'$ref'} = (string) $refPointer; |
|
102 | - } |
|
103 | - |
|
104 | - foreach ($schema as &$member) { |
|
105 | - $this->expandRefs($member, $base); |
|
106 | - } |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * {@inheritdoc} |
|
111 | - */ |
|
112 | - public function getSchema($id) |
|
113 | - { |
|
114 | - if (!array_key_exists($id, $this->schemas)) { |
|
115 | - $this->addSchema($id); |
|
116 | - } |
|
117 | - |
|
118 | - return $this->schemas[$id]; |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * {@inheritdoc} |
|
123 | - */ |
|
124 | - public function resolveRef($ref) |
|
125 | - { |
|
126 | - $jsonPointer = new JsonPointer($ref); |
|
127 | - |
|
128 | - // resolve filename for pointer |
|
129 | - $fileName = $jsonPointer->getFilename(); |
|
130 | - if (!strlen($fileName)) { |
|
131 | - throw new UnresolvableJsonPointerException(sprintf( |
|
132 | - "Could not resolve fragment '%s': no file is defined", |
|
133 | - $jsonPointer->getPropertyPathAsString() |
|
134 | - )); |
|
135 | - } |
|
136 | - |
|
137 | - // get & process the schema |
|
138 | - $refSchema = $this->getSchema($fileName); |
|
139 | - foreach ($jsonPointer->getPropertyPaths() as $path) { |
|
140 | - if (is_object($refSchema) && property_exists($refSchema, $path)) { |
|
141 | - $refSchema = $this->resolveRefSchema($refSchema->{$path}); |
|
142 | - } elseif (is_array($refSchema) && array_key_exists($path, $refSchema)) { |
|
143 | - $refSchema = $this->resolveRefSchema($refSchema[$path]); |
|
144 | - } else { |
|
145 | - throw new UnresolvableJsonPointerException(sprintf( |
|
146 | - 'File: %s is found, but could not resolve fragment: %s', |
|
147 | - $jsonPointer->getFilename(), |
|
148 | - $jsonPointer->getPropertyPathAsString() |
|
149 | - )); |
|
150 | - } |
|
151 | - } |
|
152 | - |
|
153 | - return $refSchema; |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * {@inheritdoc} |
|
158 | - */ |
|
159 | - public function resolveRefSchema($refSchema) |
|
160 | - { |
|
161 | - if (is_object($refSchema) && property_exists($refSchema, '$ref') && is_string($refSchema->{'$ref'})) { |
|
162 | - $newSchema = $this->resolveRef($refSchema->{'$ref'}); |
|
163 | - $refSchema = (object) (get_object_vars($refSchema) + get_object_vars($newSchema)); |
|
164 | - unset($refSchema->{'$ref'}); |
|
165 | - } |
|
166 | - |
|
167 | - return $refSchema; |
|
168 | - } |
|
13 | + const INTERNAL_PROVIDED_SCHEMA_URI = 'internal://provided-schema/'; |
|
14 | + |
|
15 | + protected $uriRetriever; |
|
16 | + protected $uriResolver; |
|
17 | + protected $schemas = array(); |
|
18 | + |
|
19 | + public function __construct( |
|
20 | + UriRetrieverInterface $uriRetriever = null, |
|
21 | + UriResolverInterface $uriResolver = null |
|
22 | + ) { |
|
23 | + $this->uriRetriever = $uriRetriever ?: new UriRetriever(); |
|
24 | + $this->uriResolver = $uriResolver ?: new UriResolver(); |
|
25 | + } |
|
26 | + |
|
27 | + /** |
|
28 | + * @return UriRetrieverInterface |
|
29 | + */ |
|
30 | + public function getUriRetriever() |
|
31 | + { |
|
32 | + return $this->uriRetriever; |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * @return UriResolverInterface |
|
37 | + */ |
|
38 | + public function getUriResolver() |
|
39 | + { |
|
40 | + return $this->uriResolver; |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * {@inheritdoc} |
|
45 | + */ |
|
46 | + public function addSchema($id, $schema = null) |
|
47 | + { |
|
48 | + if (is_null($schema) && $id !== self::INTERNAL_PROVIDED_SCHEMA_URI) { |
|
49 | + // if the schema was user-provided to Validator and is still null, then assume this is |
|
50 | + // what the user intended, as there's no way for us to retrieve anything else. User-supplied |
|
51 | + // schemas do not have an associated URI when passed via Validator::validate(). |
|
52 | + $schema = $this->uriRetriever->retrieve($id); |
|
53 | + } |
|
54 | + |
|
55 | + // cast array schemas to object |
|
56 | + if (is_array($schema)) { |
|
57 | + $schema = BaseConstraint::arrayToObjectRecursive($schema); |
|
58 | + } |
|
59 | + |
|
60 | + // workaround for bug in draft-03 & draft-04 meta-schemas (id & $ref defined with incorrect format) |
|
61 | + // see https://github.com/json-schema-org/JSON-Schema-Test-Suite/issues/177#issuecomment-293051367 |
|
62 | + if (is_object($schema) && property_exists($schema, 'id')) { |
|
63 | + if ($schema->id == 'http://json-schema.org/draft-04/schema#') { |
|
64 | + $schema->properties->id->format = 'uri-reference'; |
|
65 | + } elseif ($schema->id == 'http://json-schema.org/draft-03/schema#') { |
|
66 | + $schema->properties->id->format = 'uri-reference'; |
|
67 | + $schema->properties->{'$ref'}->format = 'uri-reference'; |
|
68 | + } |
|
69 | + } |
|
70 | + |
|
71 | + // resolve references |
|
72 | + $this->expandRefs($schema, $id); |
|
73 | + |
|
74 | + $this->schemas[$id] = $schema; |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Recursively resolve all references against the provided base |
|
79 | + * |
|
80 | + * @param mixed $schema |
|
81 | + * @param string $base |
|
82 | + */ |
|
83 | + private function expandRefs(&$schema, $base = null) |
|
84 | + { |
|
85 | + if (!is_object($schema)) { |
|
86 | + if (is_array($schema)) { |
|
87 | + foreach ($schema as &$member) { |
|
88 | + $this->expandRefs($member, $base); |
|
89 | + } |
|
90 | + } |
|
91 | + |
|
92 | + return; |
|
93 | + } |
|
94 | + |
|
95 | + if (property_exists($schema, 'id') && is_string($schema->id) && $base != $schema->id) { |
|
96 | + $base = $this->uriResolver->resolve($schema->id, $base); |
|
97 | + } |
|
98 | + |
|
99 | + if (property_exists($schema, '$ref') && is_string($schema->{'$ref'})) { |
|
100 | + $refPointer = new JsonPointer($this->uriResolver->resolve($schema->{'$ref'}, $base)); |
|
101 | + $schema->{'$ref'} = (string) $refPointer; |
|
102 | + } |
|
103 | + |
|
104 | + foreach ($schema as &$member) { |
|
105 | + $this->expandRefs($member, $base); |
|
106 | + } |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * {@inheritdoc} |
|
111 | + */ |
|
112 | + public function getSchema($id) |
|
113 | + { |
|
114 | + if (!array_key_exists($id, $this->schemas)) { |
|
115 | + $this->addSchema($id); |
|
116 | + } |
|
117 | + |
|
118 | + return $this->schemas[$id]; |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * {@inheritdoc} |
|
123 | + */ |
|
124 | + public function resolveRef($ref) |
|
125 | + { |
|
126 | + $jsonPointer = new JsonPointer($ref); |
|
127 | + |
|
128 | + // resolve filename for pointer |
|
129 | + $fileName = $jsonPointer->getFilename(); |
|
130 | + if (!strlen($fileName)) { |
|
131 | + throw new UnresolvableJsonPointerException(sprintf( |
|
132 | + "Could not resolve fragment '%s': no file is defined", |
|
133 | + $jsonPointer->getPropertyPathAsString() |
|
134 | + )); |
|
135 | + } |
|
136 | + |
|
137 | + // get & process the schema |
|
138 | + $refSchema = $this->getSchema($fileName); |
|
139 | + foreach ($jsonPointer->getPropertyPaths() as $path) { |
|
140 | + if (is_object($refSchema) && property_exists($refSchema, $path)) { |
|
141 | + $refSchema = $this->resolveRefSchema($refSchema->{$path}); |
|
142 | + } elseif (is_array($refSchema) && array_key_exists($path, $refSchema)) { |
|
143 | + $refSchema = $this->resolveRefSchema($refSchema[$path]); |
|
144 | + } else { |
|
145 | + throw new UnresolvableJsonPointerException(sprintf( |
|
146 | + 'File: %s is found, but could not resolve fragment: %s', |
|
147 | + $jsonPointer->getFilename(), |
|
148 | + $jsonPointer->getPropertyPathAsString() |
|
149 | + )); |
|
150 | + } |
|
151 | + } |
|
152 | + |
|
153 | + return $refSchema; |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * {@inheritdoc} |
|
158 | + */ |
|
159 | + public function resolveRefSchema($refSchema) |
|
160 | + { |
|
161 | + if (is_object($refSchema) && property_exists($refSchema, '$ref') && is_string($refSchema->{'$ref'})) { |
|
162 | + $newSchema = $this->resolveRef($refSchema->{'$ref'}); |
|
163 | + $refSchema = (object) (get_object_vars($refSchema) + get_object_vars($newSchema)); |
|
164 | + unset($refSchema->{'$ref'}); |
|
165 | + } |
|
166 | + |
|
167 | + return $refSchema; |
|
168 | + } |
|
169 | 169 | } |
@@ -4,47 +4,47 @@ |
||
4 | 4 | |
5 | 5 | class Relative extends \PhpParser\Node\Name |
6 | 6 | { |
7 | - /** |
|
8 | - * Checks whether the name is unqualified. (E.g. Name) |
|
9 | - * |
|
10 | - * @return bool Whether the name is unqualified |
|
11 | - */ |
|
12 | - public function isUnqualified() : bool { |
|
13 | - return false; |
|
14 | - } |
|
7 | + /** |
|
8 | + * Checks whether the name is unqualified. (E.g. Name) |
|
9 | + * |
|
10 | + * @return bool Whether the name is unqualified |
|
11 | + */ |
|
12 | + public function isUnqualified() : bool { |
|
13 | + return false; |
|
14 | + } |
|
15 | 15 | |
16 | - /** |
|
17 | - * Checks whether the name is qualified. (E.g. Name\Name) |
|
18 | - * |
|
19 | - * @return bool Whether the name is qualified |
|
20 | - */ |
|
21 | - public function isQualified() : bool { |
|
22 | - return false; |
|
23 | - } |
|
16 | + /** |
|
17 | + * Checks whether the name is qualified. (E.g. Name\Name) |
|
18 | + * |
|
19 | + * @return bool Whether the name is qualified |
|
20 | + */ |
|
21 | + public function isQualified() : bool { |
|
22 | + return false; |
|
23 | + } |
|
24 | 24 | |
25 | - /** |
|
26 | - * Checks whether the name is fully qualified. (E.g. \Name) |
|
27 | - * |
|
28 | - * @return bool Whether the name is fully qualified |
|
29 | - */ |
|
30 | - public function isFullyQualified() : bool { |
|
31 | - return false; |
|
32 | - } |
|
25 | + /** |
|
26 | + * Checks whether the name is fully qualified. (E.g. \Name) |
|
27 | + * |
|
28 | + * @return bool Whether the name is fully qualified |
|
29 | + */ |
|
30 | + public function isFullyQualified() : bool { |
|
31 | + return false; |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * Checks whether the name is explicitly relative to the current namespace. (E.g. namespace\Name) |
|
36 | - * |
|
37 | - * @return bool Whether the name is relative |
|
38 | - */ |
|
39 | - public function isRelative() : bool { |
|
40 | - return true; |
|
41 | - } |
|
34 | + /** |
|
35 | + * Checks whether the name is explicitly relative to the current namespace. (E.g. namespace\Name) |
|
36 | + * |
|
37 | + * @return bool Whether the name is relative |
|
38 | + */ |
|
39 | + public function isRelative() : bool { |
|
40 | + return true; |
|
41 | + } |
|
42 | 42 | |
43 | - public function toCodeString() : string { |
|
44 | - return 'namespace\\' . $this->toString(); |
|
45 | - } |
|
43 | + public function toCodeString() : string { |
|
44 | + return 'namespace\\' . $this->toString(); |
|
45 | + } |
|
46 | 46 | |
47 | - public function getType() : string { |
|
48 | - return 'Name_Relative'; |
|
49 | - } |
|
47 | + public function getType() : string { |
|
48 | + return 'Name_Relative'; |
|
49 | + } |
|
50 | 50 | } |
@@ -4,47 +4,47 @@ |
||
4 | 4 | |
5 | 5 | class FullyQualified extends \PhpParser\Node\Name |
6 | 6 | { |
7 | - /** |
|
8 | - * Checks whether the name is unqualified. (E.g. Name) |
|
9 | - * |
|
10 | - * @return bool Whether the name is unqualified |
|
11 | - */ |
|
12 | - public function isUnqualified() : bool { |
|
13 | - return false; |
|
14 | - } |
|
7 | + /** |
|
8 | + * Checks whether the name is unqualified. (E.g. Name) |
|
9 | + * |
|
10 | + * @return bool Whether the name is unqualified |
|
11 | + */ |
|
12 | + public function isUnqualified() : bool { |
|
13 | + return false; |
|
14 | + } |
|
15 | 15 | |
16 | - /** |
|
17 | - * Checks whether the name is qualified. (E.g. Name\Name) |
|
18 | - * |
|
19 | - * @return bool Whether the name is qualified |
|
20 | - */ |
|
21 | - public function isQualified() : bool { |
|
22 | - return false; |
|
23 | - } |
|
16 | + /** |
|
17 | + * Checks whether the name is qualified. (E.g. Name\Name) |
|
18 | + * |
|
19 | + * @return bool Whether the name is qualified |
|
20 | + */ |
|
21 | + public function isQualified() : bool { |
|
22 | + return false; |
|
23 | + } |
|
24 | 24 | |
25 | - /** |
|
26 | - * Checks whether the name is fully qualified. (E.g. \Name) |
|
27 | - * |
|
28 | - * @return bool Whether the name is fully qualified |
|
29 | - */ |
|
30 | - public function isFullyQualified() : bool { |
|
31 | - return true; |
|
32 | - } |
|
25 | + /** |
|
26 | + * Checks whether the name is fully qualified. (E.g. \Name) |
|
27 | + * |
|
28 | + * @return bool Whether the name is fully qualified |
|
29 | + */ |
|
30 | + public function isFullyQualified() : bool { |
|
31 | + return true; |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * Checks whether the name is explicitly relative to the current namespace. (E.g. namespace\Name) |
|
36 | - * |
|
37 | - * @return bool Whether the name is relative |
|
38 | - */ |
|
39 | - public function isRelative() : bool { |
|
40 | - return false; |
|
41 | - } |
|
34 | + /** |
|
35 | + * Checks whether the name is explicitly relative to the current namespace. (E.g. namespace\Name) |
|
36 | + * |
|
37 | + * @return bool Whether the name is relative |
|
38 | + */ |
|
39 | + public function isRelative() : bool { |
|
40 | + return false; |
|
41 | + } |
|
42 | 42 | |
43 | - public function toCodeString() : string { |
|
44 | - return '\\' . $this->toString(); |
|
45 | - } |
|
43 | + public function toCodeString() : string { |
|
44 | + return '\\' . $this->toString(); |
|
45 | + } |
|
46 | 46 | |
47 | - public function getType() : string { |
|
48 | - return 'Name_FullyQualified'; |
|
49 | - } |
|
47 | + public function getType() : string { |
|
48 | + return 'Name_FullyQualified'; |
|
49 | + } |
|
50 | 50 | } |
@@ -4,25 +4,25 @@ |
||
4 | 4 | |
5 | 5 | class UnionType extends ComplexType |
6 | 6 | { |
7 | - /** @var (Identifier|Name)[] Types */ |
|
8 | - public $types; |
|
7 | + /** @var (Identifier|Name)[] Types */ |
|
8 | + public $types; |
|
9 | 9 | |
10 | - /** |
|
11 | - * Constructs a union type. |
|
12 | - * |
|
13 | - * @param (Identifier|Name)[] $types Types |
|
14 | - * @param array $attributes Additional attributes |
|
15 | - */ |
|
16 | - public function __construct(array $types, array $attributes = []) { |
|
17 | - $this->attributes = $attributes; |
|
18 | - $this->types = $types; |
|
19 | - } |
|
10 | + /** |
|
11 | + * Constructs a union type. |
|
12 | + * |
|
13 | + * @param (Identifier|Name)[] $types Types |
|
14 | + * @param array $attributes Additional attributes |
|
15 | + */ |
|
16 | + public function __construct(array $types, array $attributes = []) { |
|
17 | + $this->attributes = $attributes; |
|
18 | + $this->types = $types; |
|
19 | + } |
|
20 | 20 | |
21 | - public function getSubNodeNames() : array { |
|
22 | - return ['types']; |
|
23 | - } |
|
21 | + public function getSubNodeNames() : array { |
|
22 | + return ['types']; |
|
23 | + } |
|
24 | 24 | |
25 | - public function getType() : string { |
|
26 | - return 'UnionType'; |
|
27 | - } |
|
25 | + public function getType() : string { |
|
26 | + return 'UnionType'; |
|
27 | + } |
|
28 | 28 | } |
@@ -7,25 +7,25 @@ |
||
7 | 7 | |
8 | 8 | class Encapsed extends Scalar |
9 | 9 | { |
10 | - /** @var Expr[] list of string parts */ |
|
11 | - public $parts; |
|
10 | + /** @var Expr[] list of string parts */ |
|
11 | + public $parts; |
|
12 | 12 | |
13 | - /** |
|
14 | - * Constructs an encapsed string node. |
|
15 | - * |
|
16 | - * @param Expr[] $parts Encaps list |
|
17 | - * @param array $attributes Additional attributes |
|
18 | - */ |
|
19 | - public function __construct(array $parts, array $attributes = []) { |
|
20 | - $this->attributes = $attributes; |
|
21 | - $this->parts = $parts; |
|
22 | - } |
|
13 | + /** |
|
14 | + * Constructs an encapsed string node. |
|
15 | + * |
|
16 | + * @param Expr[] $parts Encaps list |
|
17 | + * @param array $attributes Additional attributes |
|
18 | + */ |
|
19 | + public function __construct(array $parts, array $attributes = []) { |
|
20 | + $this->attributes = $attributes; |
|
21 | + $this->parts = $parts; |
|
22 | + } |
|
23 | 23 | |
24 | - public function getSubNodeNames() : array { |
|
25 | - return ['parts']; |
|
26 | - } |
|
24 | + public function getSubNodeNames() : array { |
|
25 | + return ['parts']; |
|
26 | + } |
|
27 | 27 | |
28 | - public function getType() : string { |
|
29 | - return 'Scalar_Encapsed'; |
|
30 | - } |
|
28 | + public function getType() : string { |
|
29 | + return 'Scalar_Encapsed'; |
|
30 | + } |
|
31 | 31 | } |
@@ -6,65 +6,65 @@ |
||
6 | 6 | |
7 | 7 | class DNumber extends Scalar |
8 | 8 | { |
9 | - /** @var float Number value */ |
|
10 | - public $value; |
|
9 | + /** @var float Number value */ |
|
10 | + public $value; |
|
11 | 11 | |
12 | - /** |
|
13 | - * Constructs a float number scalar node. |
|
14 | - * |
|
15 | - * @param float $value Value of the number |
|
16 | - * @param array $attributes Additional attributes |
|
17 | - */ |
|
18 | - public function __construct(float $value, array $attributes = []) { |
|
19 | - $this->attributes = $attributes; |
|
20 | - $this->value = $value; |
|
21 | - } |
|
12 | + /** |
|
13 | + * Constructs a float number scalar node. |
|
14 | + * |
|
15 | + * @param float $value Value of the number |
|
16 | + * @param array $attributes Additional attributes |
|
17 | + */ |
|
18 | + public function __construct(float $value, array $attributes = []) { |
|
19 | + $this->attributes = $attributes; |
|
20 | + $this->value = $value; |
|
21 | + } |
|
22 | 22 | |
23 | - public function getSubNodeNames() : array { |
|
24 | - return ['value']; |
|
25 | - } |
|
23 | + public function getSubNodeNames() : array { |
|
24 | + return ['value']; |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * @internal |
|
29 | - * |
|
30 | - * Parses a DNUMBER token like PHP would. |
|
31 | - * |
|
32 | - * @param string $str A string number |
|
33 | - * |
|
34 | - * @return float The parsed number |
|
35 | - */ |
|
36 | - public static function parse(string $str) : float { |
|
37 | - $str = str_replace('_', '', $str); |
|
27 | + /** |
|
28 | + * @internal |
|
29 | + * |
|
30 | + * Parses a DNUMBER token like PHP would. |
|
31 | + * |
|
32 | + * @param string $str A string number |
|
33 | + * |
|
34 | + * @return float The parsed number |
|
35 | + */ |
|
36 | + public static function parse(string $str) : float { |
|
37 | + $str = str_replace('_', '', $str); |
|
38 | 38 | |
39 | - // if string contains any of .eE just cast it to float |
|
40 | - if (false !== strpbrk($str, '.eE')) { |
|
41 | - return (float) $str; |
|
42 | - } |
|
39 | + // if string contains any of .eE just cast it to float |
|
40 | + if (false !== strpbrk($str, '.eE')) { |
|
41 | + return (float) $str; |
|
42 | + } |
|
43 | 43 | |
44 | - // otherwise it's an integer notation that overflowed into a float |
|
45 | - // if it starts with 0 it's one of the special integer notations |
|
46 | - if ('0' === $str[0]) { |
|
47 | - // hex |
|
48 | - if ('x' === $str[1] || 'X' === $str[1]) { |
|
49 | - return hexdec($str); |
|
50 | - } |
|
44 | + // otherwise it's an integer notation that overflowed into a float |
|
45 | + // if it starts with 0 it's one of the special integer notations |
|
46 | + if ('0' === $str[0]) { |
|
47 | + // hex |
|
48 | + if ('x' === $str[1] || 'X' === $str[1]) { |
|
49 | + return hexdec($str); |
|
50 | + } |
|
51 | 51 | |
52 | - // bin |
|
53 | - if ('b' === $str[1] || 'B' === $str[1]) { |
|
54 | - return bindec($str); |
|
55 | - } |
|
52 | + // bin |
|
53 | + if ('b' === $str[1] || 'B' === $str[1]) { |
|
54 | + return bindec($str); |
|
55 | + } |
|
56 | 56 | |
57 | - // oct |
|
58 | - // substr($str, 0, strcspn($str, '89')) cuts the string at the first invalid digit (8 or 9) |
|
59 | - // so that only the digits before that are used |
|
60 | - return octdec(substr($str, 0, strcspn($str, '89'))); |
|
61 | - } |
|
57 | + // oct |
|
58 | + // substr($str, 0, strcspn($str, '89')) cuts the string at the first invalid digit (8 or 9) |
|
59 | + // so that only the digits before that are used |
|
60 | + return octdec(substr($str, 0, strcspn($str, '89'))); |
|
61 | + } |
|
62 | 62 | |
63 | - // dec |
|
64 | - return (float) $str; |
|
65 | - } |
|
63 | + // dec |
|
64 | + return (float) $str; |
|
65 | + } |
|
66 | 66 | |
67 | - public function getType() : string { |
|
68 | - return 'Scalar_DNumber'; |
|
69 | - } |
|
67 | + public function getType() : string { |
|
68 | + return 'Scalar_DNumber'; |
|
69 | + } |
|
70 | 70 | } |
@@ -7,72 +7,72 @@ |
||
7 | 7 | |
8 | 8 | class LNumber extends Scalar |
9 | 9 | { |
10 | - /* For use in "kind" attribute */ |
|
11 | - const KIND_BIN = 2; |
|
12 | - const KIND_OCT = 8; |
|
13 | - const KIND_DEC = 10; |
|
14 | - const KIND_HEX = 16; |
|
10 | + /* For use in "kind" attribute */ |
|
11 | + const KIND_BIN = 2; |
|
12 | + const KIND_OCT = 8; |
|
13 | + const KIND_DEC = 10; |
|
14 | + const KIND_HEX = 16; |
|
15 | 15 | |
16 | - /** @var int Number value */ |
|
17 | - public $value; |
|
16 | + /** @var int Number value */ |
|
17 | + public $value; |
|
18 | 18 | |
19 | - /** |
|
20 | - * Constructs an integer number scalar node. |
|
21 | - * |
|
22 | - * @param int $value Value of the number |
|
23 | - * @param array $attributes Additional attributes |
|
24 | - */ |
|
25 | - public function __construct(int $value, array $attributes = []) { |
|
26 | - $this->attributes = $attributes; |
|
27 | - $this->value = $value; |
|
28 | - } |
|
19 | + /** |
|
20 | + * Constructs an integer number scalar node. |
|
21 | + * |
|
22 | + * @param int $value Value of the number |
|
23 | + * @param array $attributes Additional attributes |
|
24 | + */ |
|
25 | + public function __construct(int $value, array $attributes = []) { |
|
26 | + $this->attributes = $attributes; |
|
27 | + $this->value = $value; |
|
28 | + } |
|
29 | 29 | |
30 | - public function getSubNodeNames() : array { |
|
31 | - return ['value']; |
|
32 | - } |
|
30 | + public function getSubNodeNames() : array { |
|
31 | + return ['value']; |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * Constructs an LNumber node from a string number literal. |
|
36 | - * |
|
37 | - * @param string $str String number literal (decimal, octal, hex or binary) |
|
38 | - * @param array $attributes Additional attributes |
|
39 | - * @param bool $allowInvalidOctal Whether to allow invalid octal numbers (PHP 5) |
|
40 | - * |
|
41 | - * @return LNumber The constructed LNumber, including kind attribute |
|
42 | - */ |
|
43 | - public static function fromString(string $str, array $attributes = [], bool $allowInvalidOctal = false) : LNumber { |
|
44 | - $str = str_replace('_', '', $str); |
|
34 | + /** |
|
35 | + * Constructs an LNumber node from a string number literal. |
|
36 | + * |
|
37 | + * @param string $str String number literal (decimal, octal, hex or binary) |
|
38 | + * @param array $attributes Additional attributes |
|
39 | + * @param bool $allowInvalidOctal Whether to allow invalid octal numbers (PHP 5) |
|
40 | + * |
|
41 | + * @return LNumber The constructed LNumber, including kind attribute |
|
42 | + */ |
|
43 | + public static function fromString(string $str, array $attributes = [], bool $allowInvalidOctal = false) : LNumber { |
|
44 | + $str = str_replace('_', '', $str); |
|
45 | 45 | |
46 | - if ('0' !== $str[0] || '0' === $str) { |
|
47 | - $attributes['kind'] = LNumber::KIND_DEC; |
|
48 | - return new LNumber((int) $str, $attributes); |
|
49 | - } |
|
46 | + if ('0' !== $str[0] || '0' === $str) { |
|
47 | + $attributes['kind'] = LNumber::KIND_DEC; |
|
48 | + return new LNumber((int) $str, $attributes); |
|
49 | + } |
|
50 | 50 | |
51 | - if ('x' === $str[1] || 'X' === $str[1]) { |
|
52 | - $attributes['kind'] = LNumber::KIND_HEX; |
|
53 | - return new LNumber(hexdec($str), $attributes); |
|
54 | - } |
|
51 | + if ('x' === $str[1] || 'X' === $str[1]) { |
|
52 | + $attributes['kind'] = LNumber::KIND_HEX; |
|
53 | + return new LNumber(hexdec($str), $attributes); |
|
54 | + } |
|
55 | 55 | |
56 | - if ('b' === $str[1] || 'B' === $str[1]) { |
|
57 | - $attributes['kind'] = LNumber::KIND_BIN; |
|
58 | - return new LNumber(bindec($str), $attributes); |
|
59 | - } |
|
56 | + if ('b' === $str[1] || 'B' === $str[1]) { |
|
57 | + $attributes['kind'] = LNumber::KIND_BIN; |
|
58 | + return new LNumber(bindec($str), $attributes); |
|
59 | + } |
|
60 | 60 | |
61 | - if (!$allowInvalidOctal && strpbrk($str, '89')) { |
|
62 | - throw new Error('Invalid numeric literal', $attributes); |
|
63 | - } |
|
61 | + if (!$allowInvalidOctal && strpbrk($str, '89')) { |
|
62 | + throw new Error('Invalid numeric literal', $attributes); |
|
63 | + } |
|
64 | 64 | |
65 | - // Strip optional explicit octal prefix. |
|
66 | - if ('o' === $str[1] || 'O' === $str[1]) { |
|
67 | - $str = substr($str, 2); |
|
68 | - } |
|
65 | + // Strip optional explicit octal prefix. |
|
66 | + if ('o' === $str[1] || 'O' === $str[1]) { |
|
67 | + $str = substr($str, 2); |
|
68 | + } |
|
69 | 69 | |
70 | - // use intval instead of octdec to get proper cutting behavior with malformed numbers |
|
71 | - $attributes['kind'] = LNumber::KIND_OCT; |
|
72 | - return new LNumber(intval($str, 8), $attributes); |
|
73 | - } |
|
70 | + // use intval instead of octdec to get proper cutting behavior with malformed numbers |
|
71 | + $attributes['kind'] = LNumber::KIND_OCT; |
|
72 | + return new LNumber(intval($str, 8), $attributes); |
|
73 | + } |
|
74 | 74 | |
75 | - public function getType() : string { |
|
76 | - return 'Scalar_LNumber'; |
|
77 | - } |
|
75 | + public function getType() : string { |
|
76 | + return 'Scalar_LNumber'; |
|
77 | + } |
|
78 | 78 | } |
@@ -6,25 +6,25 @@ |
||
6 | 6 | |
7 | 7 | class EncapsedStringPart extends Scalar |
8 | 8 | { |
9 | - /** @var string String value */ |
|
10 | - public $value; |
|
9 | + /** @var string String value */ |
|
10 | + public $value; |
|
11 | 11 | |
12 | - /** |
|
13 | - * Constructs a node representing a string part of an encapsed string. |
|
14 | - * |
|
15 | - * @param string $value String value |
|
16 | - * @param array $attributes Additional attributes |
|
17 | - */ |
|
18 | - public function __construct(string $value, array $attributes = []) { |
|
19 | - $this->attributes = $attributes; |
|
20 | - $this->value = $value; |
|
21 | - } |
|
12 | + /** |
|
13 | + * Constructs a node representing a string part of an encapsed string. |
|
14 | + * |
|
15 | + * @param string $value String value |
|
16 | + * @param array $attributes Additional attributes |
|
17 | + */ |
|
18 | + public function __construct(string $value, array $attributes = []) { |
|
19 | + $this->attributes = $attributes; |
|
20 | + $this->value = $value; |
|
21 | + } |
|
22 | 22 | |
23 | - public function getSubNodeNames() : array { |
|
24 | - return ['value']; |
|
25 | - } |
|
23 | + public function getSubNodeNames() : array { |
|
24 | + return ['value']; |
|
25 | + } |
|
26 | 26 | |
27 | - public function getType() : string { |
|
28 | - return 'Scalar_EncapsedStringPart'; |
|
29 | - } |
|
27 | + public function getType() : string { |
|
28 | + return 'Scalar_EncapsedStringPart'; |
|
29 | + } |
|
30 | 30 | } |