ex
Fork of mbed-os-example-mbed5-blinky by
dumi_doc-master/schema/vendor/justinrainbow/json-schema/src/JsonSchema/Validator.php@44:c1d8923072ba, 2017-07-18 (annotated)
- Committer:
- TMBOY
- Date:
- Tue Jul 18 16:27:22 2017 +0800
- Revision:
- 44:c1d8923072ba
?
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| TMBOY | 44:c1d8923072ba | 1 | <?php |
| TMBOY | 44:c1d8923072ba | 2 | |
| TMBOY | 44:c1d8923072ba | 3 | /* |
| TMBOY | 44:c1d8923072ba | 4 | * This file is part of the JsonSchema package. |
| TMBOY | 44:c1d8923072ba | 5 | * |
| TMBOY | 44:c1d8923072ba | 6 | * For the full copyright and license information, please view the LICENSE |
| TMBOY | 44:c1d8923072ba | 7 | * file that was distributed with this source code. |
| TMBOY | 44:c1d8923072ba | 8 | */ |
| TMBOY | 44:c1d8923072ba | 9 | |
| TMBOY | 44:c1d8923072ba | 10 | namespace JsonSchema; |
| TMBOY | 44:c1d8923072ba | 11 | |
| TMBOY | 44:c1d8923072ba | 12 | use JsonSchema\Constraints\Constraint; |
| TMBOY | 44:c1d8923072ba | 13 | use JsonSchema\Entity\JsonPointer; |
| TMBOY | 44:c1d8923072ba | 14 | |
| TMBOY | 44:c1d8923072ba | 15 | /** |
| TMBOY | 44:c1d8923072ba | 16 | * A JsonSchema Constraint |
| TMBOY | 44:c1d8923072ba | 17 | * |
| TMBOY | 44:c1d8923072ba | 18 | * @author Robert Schönthal <seroscho@googlemail.com> |
| TMBOY | 44:c1d8923072ba | 19 | * @author Bruno Prieto Reis <bruno.p.reis@gmail.com> |
| TMBOY | 44:c1d8923072ba | 20 | * @see README.md |
| TMBOY | 44:c1d8923072ba | 21 | */ |
| TMBOY | 44:c1d8923072ba | 22 | class Validator extends Constraint |
| TMBOY | 44:c1d8923072ba | 23 | { |
| TMBOY | 44:c1d8923072ba | 24 | const SCHEMA_MEDIA_TYPE = 'application/schema+json'; |
| TMBOY | 44:c1d8923072ba | 25 | |
| TMBOY | 44:c1d8923072ba | 26 | /** |
| TMBOY | 44:c1d8923072ba | 27 | * Validates the given data against the schema and returns an object containing the results |
| TMBOY | 44:c1d8923072ba | 28 | * Both the php object and the schema are supposed to be a result of a json_decode call. |
| TMBOY | 44:c1d8923072ba | 29 | * The validation works as defined by the schema proposal in http://json-schema.org |
| TMBOY | 44:c1d8923072ba | 30 | * |
| TMBOY | 44:c1d8923072ba | 31 | * {@inheritDoc} |
| TMBOY | 44:c1d8923072ba | 32 | */ |
| TMBOY | 44:c1d8923072ba | 33 | public function check($value, $schema = null, JsonPointer $path = null, $i = null) |
| TMBOY | 44:c1d8923072ba | 34 | { |
| TMBOY | 44:c1d8923072ba | 35 | $validator = $this->factory->createInstanceFor('schema'); |
| TMBOY | 44:c1d8923072ba | 36 | $validator->check($value, $schema); |
| TMBOY | 44:c1d8923072ba | 37 | |
| TMBOY | 44:c1d8923072ba | 38 | $this->addErrors(array_unique($validator->getErrors(), SORT_REGULAR)); |
| TMBOY | 44:c1d8923072ba | 39 | } |
| TMBOY | 44:c1d8923072ba | 40 | } |
