@@ -19,16 +19,16 @@ |
||
19 | 19 | */ |
20 | 20 | class FileNotFoundException extends IOException |
21 | 21 | { |
22 | - public function __construct(string $message = null, int $code = 0, \Throwable $previous = null, string $path = null) |
|
23 | - { |
|
24 | - if (null === $message) { |
|
25 | - if (null === $path) { |
|
26 | - $message = 'File could not be found.'; |
|
27 | - } else { |
|
28 | - $message = sprintf('File "%s" could not be found.', $path); |
|
29 | - } |
|
30 | - } |
|
22 | + public function __construct(string $message = null, int $code = 0, \Throwable $previous = null, string $path = null) |
|
23 | + { |
|
24 | + if (null === $message) { |
|
25 | + if (null === $path) { |
|
26 | + $message = 'File could not be found.'; |
|
27 | + } else { |
|
28 | + $message = sprintf('File "%s" could not be found.', $path); |
|
29 | + } |
|
30 | + } |
|
31 | 31 | |
32 | - parent::__construct($message, $code, $previous, $path); |
|
33 | - } |
|
32 | + parent::__construct($message, $code, $previous, $path); |
|
33 | + } |
|
34 | 34 | } |
@@ -20,20 +20,20 @@ |
||
20 | 20 | */ |
21 | 21 | class IOException extends \RuntimeException implements IOExceptionInterface |
22 | 22 | { |
23 | - private $path; |
|
23 | + private $path; |
|
24 | 24 | |
25 | - public function __construct(string $message, int $code = 0, \Throwable $previous = null, string $path = null) |
|
26 | - { |
|
27 | - $this->path = $path; |
|
25 | + public function __construct(string $message, int $code = 0, \Throwable $previous = null, string $path = null) |
|
26 | + { |
|
27 | + $this->path = $path; |
|
28 | 28 | |
29 | - parent::__construct($message, $code, $previous); |
|
30 | - } |
|
29 | + parent::__construct($message, $code, $previous); |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * {@inheritdoc} |
|
34 | - */ |
|
35 | - public function getPath() |
|
36 | - { |
|
37 | - return $this->path; |
|
38 | - } |
|
32 | + /** |
|
33 | + * {@inheritdoc} |
|
34 | + */ |
|
35 | + public function getPath() |
|
36 | + { |
|
37 | + return $this->path; |
|
38 | + } |
|
39 | 39 | } |
@@ -18,15 +18,15 @@ |
||
18 | 18 | */ |
19 | 19 | class LazyIterator implements \IteratorAggregate |
20 | 20 | { |
21 | - private $iteratorFactory; |
|
21 | + private $iteratorFactory; |
|
22 | 22 | |
23 | - public function __construct(callable $iteratorFactory) |
|
24 | - { |
|
25 | - $this->iteratorFactory = $iteratorFactory; |
|
26 | - } |
|
23 | + public function __construct(callable $iteratorFactory) |
|
24 | + { |
|
25 | + $this->iteratorFactory = $iteratorFactory; |
|
26 | + } |
|
27 | 27 | |
28 | - public function getIterator(): \Traversable |
|
29 | - { |
|
30 | - yield from ($this->iteratorFactory)(); |
|
31 | - } |
|
28 | + public function getIterator(): \Traversable |
|
29 | + { |
|
30 | + yield from ($this->iteratorFactory)(); |
|
31 | + } |
|
32 | 32 | } |
@@ -18,89 +18,89 @@ |
||
18 | 18 | */ |
19 | 19 | abstract class MultiplePcreFilterIterator extends \FilterIterator |
20 | 20 | { |
21 | - protected $matchRegexps = []; |
|
22 | - protected $noMatchRegexps = []; |
|
21 | + protected $matchRegexps = []; |
|
22 | + protected $noMatchRegexps = []; |
|
23 | 23 | |
24 | - /** |
|
25 | - * @param \Iterator $iterator The Iterator to filter |
|
26 | - * @param string[] $matchPatterns An array of patterns that need to match |
|
27 | - * @param string[] $noMatchPatterns An array of patterns that need to not match |
|
28 | - */ |
|
29 | - public function __construct(\Iterator $iterator, array $matchPatterns, array $noMatchPatterns) |
|
30 | - { |
|
31 | - foreach ($matchPatterns as $pattern) { |
|
32 | - $this->matchRegexps[] = $this->toRegex($pattern); |
|
33 | - } |
|
24 | + /** |
|
25 | + * @param \Iterator $iterator The Iterator to filter |
|
26 | + * @param string[] $matchPatterns An array of patterns that need to match |
|
27 | + * @param string[] $noMatchPatterns An array of patterns that need to not match |
|
28 | + */ |
|
29 | + public function __construct(\Iterator $iterator, array $matchPatterns, array $noMatchPatterns) |
|
30 | + { |
|
31 | + foreach ($matchPatterns as $pattern) { |
|
32 | + $this->matchRegexps[] = $this->toRegex($pattern); |
|
33 | + } |
|
34 | 34 | |
35 | - foreach ($noMatchPatterns as $pattern) { |
|
36 | - $this->noMatchRegexps[] = $this->toRegex($pattern); |
|
37 | - } |
|
35 | + foreach ($noMatchPatterns as $pattern) { |
|
36 | + $this->noMatchRegexps[] = $this->toRegex($pattern); |
|
37 | + } |
|
38 | 38 | |
39 | - parent::__construct($iterator); |
|
40 | - } |
|
39 | + parent::__construct($iterator); |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * Checks whether the string is accepted by the regex filters. |
|
44 | - * |
|
45 | - * If there is no regexps defined in the class, this method will accept the string. |
|
46 | - * Such case can be handled by child classes before calling the method if they want to |
|
47 | - * apply a different behavior. |
|
48 | - * |
|
49 | - * @return bool |
|
50 | - */ |
|
51 | - protected function isAccepted(string $string) |
|
52 | - { |
|
53 | - // should at least not match one rule to exclude |
|
54 | - foreach ($this->noMatchRegexps as $regex) { |
|
55 | - if (preg_match($regex, $string)) { |
|
56 | - return false; |
|
57 | - } |
|
58 | - } |
|
42 | + /** |
|
43 | + * Checks whether the string is accepted by the regex filters. |
|
44 | + * |
|
45 | + * If there is no regexps defined in the class, this method will accept the string. |
|
46 | + * Such case can be handled by child classes before calling the method if they want to |
|
47 | + * apply a different behavior. |
|
48 | + * |
|
49 | + * @return bool |
|
50 | + */ |
|
51 | + protected function isAccepted(string $string) |
|
52 | + { |
|
53 | + // should at least not match one rule to exclude |
|
54 | + foreach ($this->noMatchRegexps as $regex) { |
|
55 | + if (preg_match($regex, $string)) { |
|
56 | + return false; |
|
57 | + } |
|
58 | + } |
|
59 | 59 | |
60 | - // should at least match one rule |
|
61 | - if ($this->matchRegexps) { |
|
62 | - foreach ($this->matchRegexps as $regex) { |
|
63 | - if (preg_match($regex, $string)) { |
|
64 | - return true; |
|
65 | - } |
|
66 | - } |
|
60 | + // should at least match one rule |
|
61 | + if ($this->matchRegexps) { |
|
62 | + foreach ($this->matchRegexps as $regex) { |
|
63 | + if (preg_match($regex, $string)) { |
|
64 | + return true; |
|
65 | + } |
|
66 | + } |
|
67 | 67 | |
68 | - return false; |
|
69 | - } |
|
68 | + return false; |
|
69 | + } |
|
70 | 70 | |
71 | - // If there is no match rules, the file is accepted |
|
72 | - return true; |
|
73 | - } |
|
71 | + // If there is no match rules, the file is accepted |
|
72 | + return true; |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Checks whether the string is a regex. |
|
77 | - * |
|
78 | - * @return bool |
|
79 | - */ |
|
80 | - protected function isRegex(string $str) |
|
81 | - { |
|
82 | - if (preg_match('/^(.{3,}?)[imsxuADU]*$/', $str, $m)) { |
|
83 | - $start = substr($m[1], 0, 1); |
|
84 | - $end = substr($m[1], -1); |
|
75 | + /** |
|
76 | + * Checks whether the string is a regex. |
|
77 | + * |
|
78 | + * @return bool |
|
79 | + */ |
|
80 | + protected function isRegex(string $str) |
|
81 | + { |
|
82 | + if (preg_match('/^(.{3,}?)[imsxuADU]*$/', $str, $m)) { |
|
83 | + $start = substr($m[1], 0, 1); |
|
84 | + $end = substr($m[1], -1); |
|
85 | 85 | |
86 | - if ($start === $end) { |
|
87 | - return !preg_match('/[*?[:alnum:] \\\\]/', $start); |
|
88 | - } |
|
86 | + if ($start === $end) { |
|
87 | + return !preg_match('/[*?[:alnum:] \\\\]/', $start); |
|
88 | + } |
|
89 | 89 | |
90 | - foreach ([['{', '}'], ['(', ')'], ['[', ']'], ['<', '>']] as $delimiters) { |
|
91 | - if ($start === $delimiters[0] && $end === $delimiters[1]) { |
|
92 | - return true; |
|
93 | - } |
|
94 | - } |
|
95 | - } |
|
90 | + foreach ([['{', '}'], ['(', ')'], ['[', ']'], ['<', '>']] as $delimiters) { |
|
91 | + if ($start === $delimiters[0] && $end === $delimiters[1]) { |
|
92 | + return true; |
|
93 | + } |
|
94 | + } |
|
95 | + } |
|
96 | 96 | |
97 | - return false; |
|
98 | - } |
|
97 | + return false; |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * Converts string into regexp. |
|
102 | - * |
|
103 | - * @return string |
|
104 | - */ |
|
105 | - abstract protected function toRegex(string $str); |
|
100 | + /** |
|
101 | + * Converts string into regexp. |
|
102 | + * |
|
103 | + * @return string |
|
104 | + */ |
|
105 | + abstract protected function toRegex(string $str); |
|
106 | 106 | } |
@@ -35,77 +35,77 @@ |
||
35 | 35 | */ |
36 | 36 | class Glob |
37 | 37 | { |
38 | - /** |
|
39 | - * Returns a regexp which is the equivalent of the glob pattern. |
|
40 | - * |
|
41 | - * @return string |
|
42 | - */ |
|
43 | - public static function toRegex(string $glob, bool $strictLeadingDot = true, bool $strictWildcardSlash = true, string $delimiter = '#') |
|
44 | - { |
|
45 | - $firstByte = true; |
|
46 | - $escaping = false; |
|
47 | - $inCurlies = 0; |
|
48 | - $regex = ''; |
|
49 | - $sizeGlob = \strlen($glob); |
|
50 | - for ($i = 0; $i < $sizeGlob; ++$i) { |
|
51 | - $car = $glob[$i]; |
|
52 | - if ($firstByte && $strictLeadingDot && '.' !== $car) { |
|
53 | - $regex .= '(?=[^\.])'; |
|
54 | - } |
|
38 | + /** |
|
39 | + * Returns a regexp which is the equivalent of the glob pattern. |
|
40 | + * |
|
41 | + * @return string |
|
42 | + */ |
|
43 | + public static function toRegex(string $glob, bool $strictLeadingDot = true, bool $strictWildcardSlash = true, string $delimiter = '#') |
|
44 | + { |
|
45 | + $firstByte = true; |
|
46 | + $escaping = false; |
|
47 | + $inCurlies = 0; |
|
48 | + $regex = ''; |
|
49 | + $sizeGlob = \strlen($glob); |
|
50 | + for ($i = 0; $i < $sizeGlob; ++$i) { |
|
51 | + $car = $glob[$i]; |
|
52 | + if ($firstByte && $strictLeadingDot && '.' !== $car) { |
|
53 | + $regex .= '(?=[^\.])'; |
|
54 | + } |
|
55 | 55 | |
56 | - $firstByte = '/' === $car; |
|
56 | + $firstByte = '/' === $car; |
|
57 | 57 | |
58 | - if ($firstByte && $strictWildcardSlash && isset($glob[$i + 2]) && '**' === $glob[$i + 1].$glob[$i + 2] && (!isset($glob[$i + 3]) || '/' === $glob[$i + 3])) { |
|
59 | - $car = '[^/]++/'; |
|
60 | - if (!isset($glob[$i + 3])) { |
|
61 | - $car .= '?'; |
|
62 | - } |
|
58 | + if ($firstByte && $strictWildcardSlash && isset($glob[$i + 2]) && '**' === $glob[$i + 1].$glob[$i + 2] && (!isset($glob[$i + 3]) || '/' === $glob[$i + 3])) { |
|
59 | + $car = '[^/]++/'; |
|
60 | + if (!isset($glob[$i + 3])) { |
|
61 | + $car .= '?'; |
|
62 | + } |
|
63 | 63 | |
64 | - if ($strictLeadingDot) { |
|
65 | - $car = '(?=[^\.])'.$car; |
|
66 | - } |
|
64 | + if ($strictLeadingDot) { |
|
65 | + $car = '(?=[^\.])'.$car; |
|
66 | + } |
|
67 | 67 | |
68 | - $car = '/(?:'.$car.')*'; |
|
69 | - $i += 2 + isset($glob[$i + 3]); |
|
68 | + $car = '/(?:'.$car.')*'; |
|
69 | + $i += 2 + isset($glob[$i + 3]); |
|
70 | 70 | |
71 | - if ('/' === $delimiter) { |
|
72 | - $car = str_replace('/', '\\/', $car); |
|
73 | - } |
|
74 | - } |
|
71 | + if ('/' === $delimiter) { |
|
72 | + $car = str_replace('/', '\\/', $car); |
|
73 | + } |
|
74 | + } |
|
75 | 75 | |
76 | - if ($delimiter === $car || '.' === $car || '(' === $car || ')' === $car || '|' === $car || '+' === $car || '^' === $car || '$' === $car) { |
|
77 | - $regex .= "\\$car"; |
|
78 | - } elseif ('*' === $car) { |
|
79 | - $regex .= $escaping ? '\\*' : ($strictWildcardSlash ? '[^/]*' : '.*'); |
|
80 | - } elseif ('?' === $car) { |
|
81 | - $regex .= $escaping ? '\\?' : ($strictWildcardSlash ? '[^/]' : '.'); |
|
82 | - } elseif ('{' === $car) { |
|
83 | - $regex .= $escaping ? '\\{' : '('; |
|
84 | - if (!$escaping) { |
|
85 | - ++$inCurlies; |
|
86 | - } |
|
87 | - } elseif ('}' === $car && $inCurlies) { |
|
88 | - $regex .= $escaping ? '}' : ')'; |
|
89 | - if (!$escaping) { |
|
90 | - --$inCurlies; |
|
91 | - } |
|
92 | - } elseif (',' === $car && $inCurlies) { |
|
93 | - $regex .= $escaping ? ',' : '|'; |
|
94 | - } elseif ('\\' === $car) { |
|
95 | - if ($escaping) { |
|
96 | - $regex .= '\\\\'; |
|
97 | - $escaping = false; |
|
98 | - } else { |
|
99 | - $escaping = true; |
|
100 | - } |
|
76 | + if ($delimiter === $car || '.' === $car || '(' === $car || ')' === $car || '|' === $car || '+' === $car || '^' === $car || '$' === $car) { |
|
77 | + $regex .= "\\$car"; |
|
78 | + } elseif ('*' === $car) { |
|
79 | + $regex .= $escaping ? '\\*' : ($strictWildcardSlash ? '[^/]*' : '.*'); |
|
80 | + } elseif ('?' === $car) { |
|
81 | + $regex .= $escaping ? '\\?' : ($strictWildcardSlash ? '[^/]' : '.'); |
|
82 | + } elseif ('{' === $car) { |
|
83 | + $regex .= $escaping ? '\\{' : '('; |
|
84 | + if (!$escaping) { |
|
85 | + ++$inCurlies; |
|
86 | + } |
|
87 | + } elseif ('}' === $car && $inCurlies) { |
|
88 | + $regex .= $escaping ? '}' : ')'; |
|
89 | + if (!$escaping) { |
|
90 | + --$inCurlies; |
|
91 | + } |
|
92 | + } elseif (',' === $car && $inCurlies) { |
|
93 | + $regex .= $escaping ? ',' : '|'; |
|
94 | + } elseif ('\\' === $car) { |
|
95 | + if ($escaping) { |
|
96 | + $regex .= '\\\\'; |
|
97 | + $escaping = false; |
|
98 | + } else { |
|
99 | + $escaping = true; |
|
100 | + } |
|
101 | 101 | |
102 | - continue; |
|
103 | - } else { |
|
104 | - $regex .= $car; |
|
105 | - } |
|
106 | - $escaping = false; |
|
107 | - } |
|
102 | + continue; |
|
103 | + } else { |
|
104 | + $regex .= $car; |
|
105 | + } |
|
106 | + $escaping = false; |
|
107 | + } |
|
108 | 108 | |
109 | - return $delimiter.'^'.$regex.'$'.$delimiter; |
|
110 | - } |
|
109 | + return $delimiter.'^'.$regex.'$'.$delimiter; |
|
110 | + } |
|
111 | 111 | } |
@@ -9,10 +9,10 @@ |
||
9 | 9 | $validator->check($data, (object) array('$ref' => 'file://' . realpath('schema.json'))); |
10 | 10 | |
11 | 11 | if ($validator->isValid()) { |
12 | - echo "The supplied JSON validates against the schema.\n"; |
|
12 | + echo "The supplied JSON validates against the schema.\n"; |
|
13 | 13 | } else { |
14 | - echo "JSON does not validate. Violations:\n"; |
|
15 | - foreach ($validator->getErrors() as $error) { |
|
16 | - echo sprintf("[%s] %s\n", $error['property'], $error['message']); |
|
17 | - } |
|
14 | + echo "JSON does not validate. Violations:\n"; |
|
15 | + foreach ($validator->getErrors() as $error) { |
|
16 | + echo sprintf("[%s] %s\n", $error['property'], $error['message']); |
|
17 | + } |
|
18 | 18 | } |
@@ -14,27 +14,27 @@ |
||
14 | 14 | */ |
15 | 15 | class JsonDecodingException extends RuntimeException |
16 | 16 | { |
17 | - public function __construct($code = JSON_ERROR_NONE, \Exception $previous = null) |
|
18 | - { |
|
19 | - switch ($code) { |
|
20 | - case JSON_ERROR_DEPTH: |
|
21 | - $message = 'The maximum stack depth has been exceeded'; |
|
22 | - break; |
|
23 | - case JSON_ERROR_STATE_MISMATCH: |
|
24 | - $message = 'Invalid or malformed JSON'; |
|
25 | - break; |
|
26 | - case JSON_ERROR_CTRL_CHAR: |
|
27 | - $message = 'Control character error, possibly incorrectly encoded'; |
|
28 | - break; |
|
29 | - case JSON_ERROR_UTF8: |
|
30 | - $message = 'Malformed UTF-8 characters, possibly incorrectly encoded'; |
|
31 | - break; |
|
32 | - case JSON_ERROR_SYNTAX: |
|
33 | - $message = 'JSON syntax is malformed'; |
|
34 | - break; |
|
35 | - default: |
|
36 | - $message = 'Syntax error'; |
|
37 | - } |
|
38 | - parent::__construct($message, $code, $previous); |
|
39 | - } |
|
17 | + public function __construct($code = JSON_ERROR_NONE, \Exception $previous = null) |
|
18 | + { |
|
19 | + switch ($code) { |
|
20 | + case JSON_ERROR_DEPTH: |
|
21 | + $message = 'The maximum stack depth has been exceeded'; |
|
22 | + break; |
|
23 | + case JSON_ERROR_STATE_MISMATCH: |
|
24 | + $message = 'Invalid or malformed JSON'; |
|
25 | + break; |
|
26 | + case JSON_ERROR_CTRL_CHAR: |
|
27 | + $message = 'Control character error, possibly incorrectly encoded'; |
|
28 | + break; |
|
29 | + case JSON_ERROR_UTF8: |
|
30 | + $message = 'Malformed UTF-8 characters, possibly incorrectly encoded'; |
|
31 | + break; |
|
32 | + case JSON_ERROR_SYNTAX: |
|
33 | + $message = 'JSON syntax is malformed'; |
|
34 | + break; |
|
35 | + default: |
|
36 | + $message = 'Syntax error'; |
|
37 | + } |
|
38 | + parent::__construct($message, $code, $previous); |
|
39 | + } |
|
40 | 40 | } |
@@ -14,13 +14,13 @@ |
||
14 | 14 | */ |
15 | 15 | interface UriResolverInterface |
16 | 16 | { |
17 | - /** |
|
18 | - * Resolves a URI |
|
19 | - * |
|
20 | - * @param string $uri Absolute or relative |
|
21 | - * @param null|string $baseUri Optional base URI |
|
22 | - * |
|
23 | - * @return string Absolute URI |
|
24 | - */ |
|
25 | - public function resolve($uri, $baseUri = null); |
|
17 | + /** |
|
18 | + * Resolves a URI |
|
19 | + * |
|
20 | + * @param string $uri Absolute or relative |
|
21 | + * @param null|string $baseUri Optional base URI |
|
22 | + * |
|
23 | + * @return string Absolute URI |
|
24 | + */ |
|
25 | + public function resolve($uri, $baseUri = null); |
|
26 | 26 | } |
@@ -4,38 +4,38 @@ |
||
4 | 4 | |
5 | 5 | interface SchemaStorageInterface |
6 | 6 | { |
7 | - /** |
|
8 | - * Adds schema with given identifier |
|
9 | - * |
|
10 | - * @param string $id |
|
11 | - * @param object $schema |
|
12 | - */ |
|
13 | - public function addSchema($id, $schema = null); |
|
7 | + /** |
|
8 | + * Adds schema with given identifier |
|
9 | + * |
|
10 | + * @param string $id |
|
11 | + * @param object $schema |
|
12 | + */ |
|
13 | + public function addSchema($id, $schema = null); |
|
14 | 14 | |
15 | - /** |
|
16 | - * Returns schema for given identifier, or null if it does not exist |
|
17 | - * |
|
18 | - * @param string $id |
|
19 | - * |
|
20 | - * @return object |
|
21 | - */ |
|
22 | - public function getSchema($id); |
|
15 | + /** |
|
16 | + * Returns schema for given identifier, or null if it does not exist |
|
17 | + * |
|
18 | + * @param string $id |
|
19 | + * |
|
20 | + * @return object |
|
21 | + */ |
|
22 | + public function getSchema($id); |
|
23 | 23 | |
24 | - /** |
|
25 | - * Returns schema for given reference with all sub-references resolved |
|
26 | - * |
|
27 | - * @param string $ref |
|
28 | - * |
|
29 | - * @return object |
|
30 | - */ |
|
31 | - public function resolveRef($ref); |
|
24 | + /** |
|
25 | + * Returns schema for given reference with all sub-references resolved |
|
26 | + * |
|
27 | + * @param string $ref |
|
28 | + * |
|
29 | + * @return object |
|
30 | + */ |
|
31 | + public function resolveRef($ref); |
|
32 | 32 | |
33 | - /** |
|
34 | - * Returns schema referenced by '$ref' property |
|
35 | - * |
|
36 | - * @param mixed $refSchema |
|
37 | - * |
|
38 | - * @return object |
|
39 | - */ |
|
40 | - public function resolveRefSchema($refSchema); |
|
33 | + /** |
|
34 | + * Returns schema referenced by '$ref' property |
|
35 | + * |
|
36 | + * @param mixed $refSchema |
|
37 | + * |
|
38 | + * @return object |
|
39 | + */ |
|
40 | + public function resolveRefSchema($refSchema); |
|
41 | 41 | } |