@@ -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 | } |
@@ -22,67 +22,67 @@ |
||
22 | 22 | */ |
23 | 23 | class Validator extends BaseConstraint |
24 | 24 | { |
25 | - const SCHEMA_MEDIA_TYPE = 'application/schema+json'; |
|
25 | + const SCHEMA_MEDIA_TYPE = 'application/schema+json'; |
|
26 | 26 | |
27 | - const ERROR_NONE = 0x00000000; |
|
28 | - const ERROR_ALL = 0xFFFFFFFF; |
|
29 | - const ERROR_DOCUMENT_VALIDATION = 0x00000001; |
|
30 | - const ERROR_SCHEMA_VALIDATION = 0x00000002; |
|
27 | + const ERROR_NONE = 0x00000000; |
|
28 | + const ERROR_ALL = 0xFFFFFFFF; |
|
29 | + const ERROR_DOCUMENT_VALIDATION = 0x00000001; |
|
30 | + const ERROR_SCHEMA_VALIDATION = 0x00000002; |
|
31 | 31 | |
32 | - /** |
|
33 | - * Validates the given data against the schema and returns an object containing the results |
|
34 | - * Both the php object and the schema are supposed to be a result of a json_decode call. |
|
35 | - * The validation works as defined by the schema proposal in http://json-schema.org. |
|
36 | - * |
|
37 | - * Note that the first argument is passed by reference, so you must pass in a variable. |
|
38 | - */ |
|
39 | - public function validate(&$value, $schema = null, $checkMode = null) |
|
40 | - { |
|
41 | - // make sure $schema is an object |
|
42 | - if (is_array($schema)) { |
|
43 | - $schema = self::arrayToObjectRecursive($schema); |
|
44 | - } |
|
32 | + /** |
|
33 | + * Validates the given data against the schema and returns an object containing the results |
|
34 | + * Both the php object and the schema are supposed to be a result of a json_decode call. |
|
35 | + * The validation works as defined by the schema proposal in http://json-schema.org. |
|
36 | + * |
|
37 | + * Note that the first argument is passed by reference, so you must pass in a variable. |
|
38 | + */ |
|
39 | + public function validate(&$value, $schema = null, $checkMode = null) |
|
40 | + { |
|
41 | + // make sure $schema is an object |
|
42 | + if (is_array($schema)) { |
|
43 | + $schema = self::arrayToObjectRecursive($schema); |
|
44 | + } |
|
45 | 45 | |
46 | - // set checkMode |
|
47 | - $initialCheckMode = $this->factory->getConfig(); |
|
48 | - if ($checkMode !== null) { |
|
49 | - $this->factory->setConfig($checkMode); |
|
50 | - } |
|
46 | + // set checkMode |
|
47 | + $initialCheckMode = $this->factory->getConfig(); |
|
48 | + if ($checkMode !== null) { |
|
49 | + $this->factory->setConfig($checkMode); |
|
50 | + } |
|
51 | 51 | |
52 | - // add provided schema to SchemaStorage with internal URI to allow internal $ref resolution |
|
53 | - if (is_object($schema) && property_exists($schema, 'id')) { |
|
54 | - $schemaURI = $schema->id; |
|
55 | - } else { |
|
56 | - $schemaURI = SchemaStorage::INTERNAL_PROVIDED_SCHEMA_URI; |
|
57 | - } |
|
58 | - $this->factory->getSchemaStorage()->addSchema($schemaURI, $schema); |
|
52 | + // add provided schema to SchemaStorage with internal URI to allow internal $ref resolution |
|
53 | + if (is_object($schema) && property_exists($schema, 'id')) { |
|
54 | + $schemaURI = $schema->id; |
|
55 | + } else { |
|
56 | + $schemaURI = SchemaStorage::INTERNAL_PROVIDED_SCHEMA_URI; |
|
57 | + } |
|
58 | + $this->factory->getSchemaStorage()->addSchema($schemaURI, $schema); |
|
59 | 59 | |
60 | - $validator = $this->factory->createInstanceFor('schema'); |
|
61 | - $validator->check( |
|
62 | - $value, |
|
63 | - $this->factory->getSchemaStorage()->getSchema($schemaURI) |
|
64 | - ); |
|
60 | + $validator = $this->factory->createInstanceFor('schema'); |
|
61 | + $validator->check( |
|
62 | + $value, |
|
63 | + $this->factory->getSchemaStorage()->getSchema($schemaURI) |
|
64 | + ); |
|
65 | 65 | |
66 | - $this->factory->setConfig($initialCheckMode); |
|
66 | + $this->factory->setConfig($initialCheckMode); |
|
67 | 67 | |
68 | - $this->addErrors(array_unique($validator->getErrors(), SORT_REGULAR)); |
|
68 | + $this->addErrors(array_unique($validator->getErrors(), SORT_REGULAR)); |
|
69 | 69 | |
70 | - return $validator->getErrorMask(); |
|
71 | - } |
|
70 | + return $validator->getErrorMask(); |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * Alias to validate(), to maintain backwards-compatibility with the previous API |
|
75 | - */ |
|
76 | - public function check($value, $schema) |
|
77 | - { |
|
78 | - return $this->validate($value, $schema); |
|
79 | - } |
|
73 | + /** |
|
74 | + * Alias to validate(), to maintain backwards-compatibility with the previous API |
|
75 | + */ |
|
76 | + public function check($value, $schema) |
|
77 | + { |
|
78 | + return $this->validate($value, $schema); |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * Alias to validate(), to maintain backwards-compatibility with the previous API |
|
83 | - */ |
|
84 | - public function coerce(&$value, $schema) |
|
85 | - { |
|
86 | - return $this->validate($value, $schema, Constraint::CHECK_MODE_COERCE_TYPES); |
|
87 | - } |
|
81 | + /** |
|
82 | + * Alias to validate(), to maintain backwards-compatibility with the previous API |
|
83 | + */ |
|
84 | + public function coerce(&$value, $schema) |
|
85 | + { |
|
86 | + return $this->validate($value, $schema, Constraint::CHECK_MODE_COERCE_TYPES); |
|
87 | + } |
|
88 | 88 | } |
@@ -18,144 +18,144 @@ |
||
18 | 18 | */ |
19 | 19 | class JsonPointer |
20 | 20 | { |
21 | - /** @var string */ |
|
22 | - private $filename; |
|
23 | - |
|
24 | - /** @var string[] */ |
|
25 | - private $propertyPaths = array(); |
|
26 | - |
|
27 | - /** |
|
28 | - * @var bool Whether the value at this path was set from a schema default |
|
29 | - */ |
|
30 | - private $fromDefault = false; |
|
31 | - |
|
32 | - /** |
|
33 | - * @param string $value |
|
34 | - * |
|
35 | - * @throws InvalidArgumentException when $value is not a string |
|
36 | - */ |
|
37 | - public function __construct($value) |
|
38 | - { |
|
39 | - if (!is_string($value)) { |
|
40 | - throw new InvalidArgumentException('Ref value must be a string'); |
|
41 | - } |
|
42 | - |
|
43 | - $splitRef = explode('#', $value, 2); |
|
44 | - $this->filename = $splitRef[0]; |
|
45 | - if (array_key_exists(1, $splitRef)) { |
|
46 | - $this->propertyPaths = $this->decodePropertyPaths($splitRef[1]); |
|
47 | - } |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * @param string $propertyPathString |
|
52 | - * |
|
53 | - * @return string[] |
|
54 | - */ |
|
55 | - private function decodePropertyPaths($propertyPathString) |
|
56 | - { |
|
57 | - $paths = array(); |
|
58 | - foreach (explode('/', trim($propertyPathString, '/')) as $path) { |
|
59 | - $path = $this->decodePath($path); |
|
60 | - if (is_string($path) && '' !== $path) { |
|
61 | - $paths[] = $path; |
|
62 | - } |
|
63 | - } |
|
64 | - |
|
65 | - return $paths; |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * @return array |
|
70 | - */ |
|
71 | - private function encodePropertyPaths() |
|
72 | - { |
|
73 | - return array_map( |
|
74 | - array($this, 'encodePath'), |
|
75 | - $this->getPropertyPaths() |
|
76 | - ); |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * @param string $path |
|
81 | - * |
|
82 | - * @return string |
|
83 | - */ |
|
84 | - private function decodePath($path) |
|
85 | - { |
|
86 | - return strtr($path, array('~1' => '/', '~0' => '~', '%25' => '%')); |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * @param string $path |
|
91 | - * |
|
92 | - * @return string |
|
93 | - */ |
|
94 | - private function encodePath($path) |
|
95 | - { |
|
96 | - return strtr($path, array('/' => '~1', '~' => '~0', '%' => '%25')); |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - public function getFilename() |
|
103 | - { |
|
104 | - return $this->filename; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @return string[] |
|
109 | - */ |
|
110 | - public function getPropertyPaths() |
|
111 | - { |
|
112 | - return $this->propertyPaths; |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * @param array $propertyPaths |
|
117 | - * |
|
118 | - * @return JsonPointer |
|
119 | - */ |
|
120 | - public function withPropertyPaths(array $propertyPaths) |
|
121 | - { |
|
122 | - $new = clone $this; |
|
123 | - $new->propertyPaths = $propertyPaths; |
|
124 | - |
|
125 | - return $new; |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * @return string |
|
130 | - */ |
|
131 | - public function getPropertyPathAsString() |
|
132 | - { |
|
133 | - return rtrim('#/' . implode('/', $this->encodePropertyPaths()), '/'); |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * @return string |
|
138 | - */ |
|
139 | - public function __toString() |
|
140 | - { |
|
141 | - return $this->getFilename() . $this->getPropertyPathAsString(); |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * Mark the value at this path as being set from a schema default |
|
146 | - */ |
|
147 | - public function setFromDefault() |
|
148 | - { |
|
149 | - $this->fromDefault = true; |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * Check whether the value at this path was set from a schema default |
|
154 | - * |
|
155 | - * @return bool |
|
156 | - */ |
|
157 | - public function fromDefault() |
|
158 | - { |
|
159 | - return $this->fromDefault; |
|
160 | - } |
|
21 | + /** @var string */ |
|
22 | + private $filename; |
|
23 | + |
|
24 | + /** @var string[] */ |
|
25 | + private $propertyPaths = array(); |
|
26 | + |
|
27 | + /** |
|
28 | + * @var bool Whether the value at this path was set from a schema default |
|
29 | + */ |
|
30 | + private $fromDefault = false; |
|
31 | + |
|
32 | + /** |
|
33 | + * @param string $value |
|
34 | + * |
|
35 | + * @throws InvalidArgumentException when $value is not a string |
|
36 | + */ |
|
37 | + public function __construct($value) |
|
38 | + { |
|
39 | + if (!is_string($value)) { |
|
40 | + throw new InvalidArgumentException('Ref value must be a string'); |
|
41 | + } |
|
42 | + |
|
43 | + $splitRef = explode('#', $value, 2); |
|
44 | + $this->filename = $splitRef[0]; |
|
45 | + if (array_key_exists(1, $splitRef)) { |
|
46 | + $this->propertyPaths = $this->decodePropertyPaths($splitRef[1]); |
|
47 | + } |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * @param string $propertyPathString |
|
52 | + * |
|
53 | + * @return string[] |
|
54 | + */ |
|
55 | + private function decodePropertyPaths($propertyPathString) |
|
56 | + { |
|
57 | + $paths = array(); |
|
58 | + foreach (explode('/', trim($propertyPathString, '/')) as $path) { |
|
59 | + $path = $this->decodePath($path); |
|
60 | + if (is_string($path) && '' !== $path) { |
|
61 | + $paths[] = $path; |
|
62 | + } |
|
63 | + } |
|
64 | + |
|
65 | + return $paths; |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * @return array |
|
70 | + */ |
|
71 | + private function encodePropertyPaths() |
|
72 | + { |
|
73 | + return array_map( |
|
74 | + array($this, 'encodePath'), |
|
75 | + $this->getPropertyPaths() |
|
76 | + ); |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * @param string $path |
|
81 | + * |
|
82 | + * @return string |
|
83 | + */ |
|
84 | + private function decodePath($path) |
|
85 | + { |
|
86 | + return strtr($path, array('~1' => '/', '~0' => '~', '%25' => '%')); |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * @param string $path |
|
91 | + * |
|
92 | + * @return string |
|
93 | + */ |
|
94 | + private function encodePath($path) |
|
95 | + { |
|
96 | + return strtr($path, array('/' => '~1', '~' => '~0', '%' => '%25')); |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + public function getFilename() |
|
103 | + { |
|
104 | + return $this->filename; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @return string[] |
|
109 | + */ |
|
110 | + public function getPropertyPaths() |
|
111 | + { |
|
112 | + return $this->propertyPaths; |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * @param array $propertyPaths |
|
117 | + * |
|
118 | + * @return JsonPointer |
|
119 | + */ |
|
120 | + public function withPropertyPaths(array $propertyPaths) |
|
121 | + { |
|
122 | + $new = clone $this; |
|
123 | + $new->propertyPaths = $propertyPaths; |
|
124 | + |
|
125 | + return $new; |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * @return string |
|
130 | + */ |
|
131 | + public function getPropertyPathAsString() |
|
132 | + { |
|
133 | + return rtrim('#/' . implode('/', $this->encodePropertyPaths()), '/'); |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * @return string |
|
138 | + */ |
|
139 | + public function __toString() |
|
140 | + { |
|
141 | + return $this->getFilename() . $this->getPropertyPathAsString(); |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * Mark the value at this path as being set from a schema default |
|
146 | + */ |
|
147 | + public function setFromDefault() |
|
148 | + { |
|
149 | + $this->fromDefault = true; |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * Check whether the value at this path was set from a schema default |
|
154 | + * |
|
155 | + * @return bool |
|
156 | + */ |
|
157 | + public function fromDefault() |
|
158 | + { |
|
159 | + return $this->fromDefault; |
|
160 | + } |
|
161 | 161 | } |
@@ -14,13 +14,13 @@ |
||
14 | 14 | */ |
15 | 15 | interface UriRetrieverInterface |
16 | 16 | { |
17 | - /** |
|
18 | - * Retrieve a URI |
|
19 | - * |
|
20 | - * @param string $uri JSON Schema URI |
|
21 | - * @param null|string $baseUri |
|
22 | - * |
|
23 | - * @return object JSON Schema contents |
|
24 | - */ |
|
25 | - public function retrieve($uri, $baseUri = null); |
|
17 | + /** |
|
18 | + * Retrieve a URI |
|
19 | + * |
|
20 | + * @param string $uri JSON Schema URI |
|
21 | + * @param null|string $baseUri |
|
22 | + * |
|
23 | + * @return object JSON Schema contents |
|
24 | + */ |
|
25 | + public function retrieve($uri, $baseUri = null); |
|
26 | 26 | } |
@@ -4,65 +4,65 @@ |
||
4 | 4 | |
5 | 5 | class LooseTypeCheck implements TypeCheckInterface |
6 | 6 | { |
7 | - public static function isObject($value) |
|
8 | - { |
|
9 | - return |
|
10 | - is_object($value) || |
|
11 | - (is_array($value) && (count($value) == 0 || self::isAssociativeArray($value))); |
|
12 | - } |
|
7 | + public static function isObject($value) |
|
8 | + { |
|
9 | + return |
|
10 | + is_object($value) || |
|
11 | + (is_array($value) && (count($value) == 0 || self::isAssociativeArray($value))); |
|
12 | + } |
|
13 | 13 | |
14 | - public static function isArray($value) |
|
15 | - { |
|
16 | - return |
|
17 | - is_array($value) && |
|
18 | - (count($value) == 0 || !self::isAssociativeArray($value)); |
|
19 | - } |
|
14 | + public static function isArray($value) |
|
15 | + { |
|
16 | + return |
|
17 | + is_array($value) && |
|
18 | + (count($value) == 0 || !self::isAssociativeArray($value)); |
|
19 | + } |
|
20 | 20 | |
21 | - public static function propertyGet($value, $property) |
|
22 | - { |
|
23 | - if (is_object($value)) { |
|
24 | - return $value->{$property}; |
|
25 | - } |
|
21 | + public static function propertyGet($value, $property) |
|
22 | + { |
|
23 | + if (is_object($value)) { |
|
24 | + return $value->{$property}; |
|
25 | + } |
|
26 | 26 | |
27 | - return $value[$property]; |
|
28 | - } |
|
27 | + return $value[$property]; |
|
28 | + } |
|
29 | 29 | |
30 | - public static function propertySet(&$value, $property, $data) |
|
31 | - { |
|
32 | - if (is_object($value)) { |
|
33 | - $value->{$property} = $data; |
|
34 | - } else { |
|
35 | - $value[$property] = $data; |
|
36 | - } |
|
37 | - } |
|
30 | + public static function propertySet(&$value, $property, $data) |
|
31 | + { |
|
32 | + if (is_object($value)) { |
|
33 | + $value->{$property} = $data; |
|
34 | + } else { |
|
35 | + $value[$property] = $data; |
|
36 | + } |
|
37 | + } |
|
38 | 38 | |
39 | - public static function propertyExists($value, $property) |
|
40 | - { |
|
41 | - if (is_object($value)) { |
|
42 | - return property_exists($value, $property); |
|
43 | - } |
|
39 | + public static function propertyExists($value, $property) |
|
40 | + { |
|
41 | + if (is_object($value)) { |
|
42 | + return property_exists($value, $property); |
|
43 | + } |
|
44 | 44 | |
45 | - return array_key_exists($property, $value); |
|
46 | - } |
|
45 | + return array_key_exists($property, $value); |
|
46 | + } |
|
47 | 47 | |
48 | - public static function propertyCount($value) |
|
49 | - { |
|
50 | - if (is_object($value)) { |
|
51 | - return count(get_object_vars($value)); |
|
52 | - } |
|
48 | + public static function propertyCount($value) |
|
49 | + { |
|
50 | + if (is_object($value)) { |
|
51 | + return count(get_object_vars($value)); |
|
52 | + } |
|
53 | 53 | |
54 | - return count($value); |
|
55 | - } |
|
54 | + return count($value); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Check if the provided array is associative or not |
|
59 | - * |
|
60 | - * @param array $arr |
|
61 | - * |
|
62 | - * @return bool |
|
63 | - */ |
|
64 | - private static function isAssociativeArray($arr) |
|
65 | - { |
|
66 | - return array_keys($arr) !== range(0, count($arr) - 1); |
|
67 | - } |
|
57 | + /** |
|
58 | + * Check if the provided array is associative or not |
|
59 | + * |
|
60 | + * @param array $arr |
|
61 | + * |
|
62 | + * @return bool |
|
63 | + */ |
|
64 | + private static function isAssociativeArray($arr) |
|
65 | + { |
|
66 | + return array_keys($arr) !== range(0, count($arr) - 1); |
|
67 | + } |
|
68 | 68 | } |
@@ -4,15 +4,15 @@ |
||
4 | 4 | |
5 | 5 | interface TypeCheckInterface |
6 | 6 | { |
7 | - public static function isObject($value); |
|
7 | + public static function isObject($value); |
|
8 | 8 | |
9 | - public static function isArray($value); |
|
9 | + public static function isArray($value); |
|
10 | 10 | |
11 | - public static function propertyGet($value, $property); |
|
11 | + public static function propertyGet($value, $property); |
|
12 | 12 | |
13 | - public static function propertySet(&$value, $property, $data); |
|
13 | + public static function propertySet(&$value, $property, $data); |
|
14 | 14 | |
15 | - public static function propertyExists($value, $property); |
|
15 | + public static function propertyExists($value, $property); |
|
16 | 16 | |
17 | - public static function propertyCount($value); |
|
17 | + public static function propertyCount($value); |
|
18 | 18 | } |
@@ -4,37 +4,37 @@ |
||
4 | 4 | |
5 | 5 | class StrictTypeCheck implements TypeCheckInterface |
6 | 6 | { |
7 | - public static function isObject($value) |
|
8 | - { |
|
9 | - return is_object($value); |
|
10 | - } |
|
11 | - |
|
12 | - public static function isArray($value) |
|
13 | - { |
|
14 | - return is_array($value); |
|
15 | - } |
|
16 | - |
|
17 | - public static function propertyGet($value, $property) |
|
18 | - { |
|
19 | - return $value->{$property}; |
|
20 | - } |
|
21 | - |
|
22 | - public static function propertySet(&$value, $property, $data) |
|
23 | - { |
|
24 | - $value->{$property} = $data; |
|
25 | - } |
|
26 | - |
|
27 | - public static function propertyExists($value, $property) |
|
28 | - { |
|
29 | - return property_exists($value, $property); |
|
30 | - } |
|
31 | - |
|
32 | - public static function propertyCount($value) |
|
33 | - { |
|
34 | - if (!is_object($value)) { |
|
35 | - return 0; |
|
36 | - } |
|
37 | - |
|
38 | - return count(get_object_vars($value)); |
|
39 | - } |
|
7 | + public static function isObject($value) |
|
8 | + { |
|
9 | + return is_object($value); |
|
10 | + } |
|
11 | + |
|
12 | + public static function isArray($value) |
|
13 | + { |
|
14 | + return is_array($value); |
|
15 | + } |
|
16 | + |
|
17 | + public static function propertyGet($value, $property) |
|
18 | + { |
|
19 | + return $value->{$property}; |
|
20 | + } |
|
21 | + |
|
22 | + public static function propertySet(&$value, $property, $data) |
|
23 | + { |
|
24 | + $value->{$property} = $data; |
|
25 | + } |
|
26 | + |
|
27 | + public static function propertyExists($value, $property) |
|
28 | + { |
|
29 | + return property_exists($value, $property); |
|
30 | + } |
|
31 | + |
|
32 | + public static function propertyCount($value) |
|
33 | + { |
|
34 | + if (!is_object($value)) { |
|
35 | + return 0; |
|
36 | + } |
|
37 | + |
|
38 | + return count(get_object_vars($value)); |
|
39 | + } |
|
40 | 40 | } |