Skip to content
This repository has been archived by the owner on May 12, 2018. It is now read-only.

Commit

Permalink
Merge a048d64 into d496405
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt A committed Apr 23, 2017
2 parents d496405 + a048d64 commit eef9e4d
Show file tree
Hide file tree
Showing 103 changed files with 1,448 additions and 3,221 deletions.
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
language: php

php:
- 5.5
- 5.6
- 7.0
- 7.1
- hhvm

# This triggers builds to run on the new TravisCI infrastructure.
# See: http://docs.travis-ci.com/user/workers/container-based-infrastructure/
Expand All @@ -18,11 +16,11 @@ cache:
before_script:
- travis_retry composer self-update
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-dist
- node tests/server.js &
- COMPOSER_PROCESS_TIMEOUT=0 composer test-server > /dev/null 2>&1 &

script:
- vendor/bin/phpcs --standard=psr2 src/
- vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover

after_script:
- if [[ $TRAVIS_PHP_VERSION != 'hhvm' && $TRAVIS_PHP_VERSION != '7.0' && $TRAVIS_PHP_VERSION != '7.1' ]]; then php vendor/bin/ocular code-coverage:upload --format=php-clover coverage.clover; fi
- if [[ $TRAVIS_PHP_VERSION != '7.0' && $TRAVIS_PHP_VERSION != '7.1' ]]; then php vendor/bin/ocular code-coverage:upload --format=php-clover coverage.clover; fi
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).

* Allow redirects by default with the CurlWebLoader.
* All constraints now implement a single interface. See `League\JsonGuard\Constraints\Constraint` for more info. If you are using custom constraints you should update them to match the new signature.
* The Dereferencer now accepts a LoaderManager which takes care of registering and getting schema loaders. You should replace any calls to `Dereferencer::getLoader`, `Dereferencer::getLoaders`, or `Dereferencer::registerLoader` with `Dereferencer::getLoaderManager` and then call the method on the loader manager. The order of arguments for `LoaderManager::registerLoader` was also changed;
* All reference resolving is now handled by a separate package, `league/json-reference`. Please review the documentation as `league/json-reference` is almost a complete rewrite.
* Dropped support for PHP 5.5 and HHVM.

## Removed

Expand Down
19 changes: 8 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,18 @@
}
],
"require": {
"php": ">=5.5.0",
"sabre/uri": "^1.1"
},
"suggest": {
"ext-bcmath": "Required to properly check constraints for numbers larger than PHP_INT_MAX."
"php": ">=5.6.0",
"sabre/uri": "^1.1",
"psr/container": "^1.0",
"ext-bcmath": "*"
},
"require-dev": {
"phpunit/phpunit" : "4.*",
"scrutinizer/ocular": "~1.1",
"squizlabs/php_codesniffer": "~2.3",
"json-schema/JSON-Schema-Test-Suite": "1.2.0",
"ext-curl": "*",
"ext-bcmath": "*"
"league/json-reference": "*@dev",
"ext-curl": "*"
},
"autoload": {
"psr-4": {
Expand All @@ -60,13 +59,11 @@
"psr-4": {
"League\\JsonGuard\\Test\\": "tests",
"League\\JsonGuard\\Bench\\": "tests/benchmarks"
},
"files": [
"tests/helpers.php"
]
}
},
"scripts": {
"test": "phpunit",
"test-server": "php -S localhost:1234 -t ./vendor/json-schema/JSON-Schema-Test-Suite/remotes/",
"cs": "phpcs --standard=psr2 src/",
"bench": "phpbench run ./tests/benchmarks --report=default"
},
Expand Down
14 changes: 10 additions & 4 deletions docs/_data/menu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ Getting Started:
Introduction: '/'
Simple Example: '/simple-example/'
Installation: '/installation/'
Dereferencing:
Overview: '/dereferencing/overview/'
Circular References: '/dereferencing/circular-references/'
Validation:
JSON References:
Overview: '/json-reference/overview/'
Installation: '/json-reference/installation/'
Dereferencing: '/json-reference/dereferencing/'
Loaders: '/json-reference/loaders/'
Scope Resolution: '/json-reference/scope-resolution/'
Circular References: '/json-reference/circular-references/'
JSON Schema Validation:
Overview: '/validation/overview/'
Errors: '/validation/errors/'
Extending: '/validation/extending/'
FAQ: '/faq'
Upgrade Guide:
0.x to 1.0: '/upgrade-guide/1-0'
40 changes: 0 additions & 40 deletions docs/dereferencing/circular-references.md

This file was deleted.

87 changes: 0 additions & 87 deletions docs/dereferencing/overview.md

This file was deleted.

12 changes: 8 additions & 4 deletions docs/faq.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
layout: default
permalink: faq/
permalink: faq
title: FAQ
---

Expand Down Expand Up @@ -41,12 +41,16 @@ If your schema contains numbers larger than PHP_INT_MAX (usually 2147483647), yo
$data = json_decode($data, false, 512, JSON_BIGINT_AS_STRING);
```

Comparison will only work correctly with large numbers if you have the [bcmatch extension](http://php.net/manual/en/book.bc.php), so make sure it is enabled on your platform. It's usually enabled by default.
Comparison with large numbers uses the [bcmatch extension](http://php.net/manual/en/book.bc.php), so make sure it is enabled on your platform. It's usually enabled by default.

If you need to compare floats with more than 10 places after the decimal place, you can change the scale used for comparisons:
If you need to compare floats with more than 10 places after the decimal place, you can set the scale of the Max or Min constraint when instantiating it, then add it to the ruleset.

```php
<?php

League\JsonGuard\Comparator::setScale(20);
$ruleset = new \League\JsonGuard\RuleSets\DraftFour();
$ruleset->set('minimum', function () {
return new \League\JsonGuard\Constraints\Min(20);
});
$validator = new \League\JsonGuard\Validator($data, $schema, $ruleset);
```
4 changes: 2 additions & 2 deletions docs/installation.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
layout: default
permalink: installation/
permalink: installation
title: Installation
---

# Installation

## System Requirements

You need PHP >= 5.5.0 to use this package but the latest stable version of PHP is recommended.
You need PHP >= 5.6.0 to use this package but the latest stable version of PHP is recommended.

## Composer

Expand Down
38 changes: 38 additions & 0 deletions docs/json-reference/circular-references.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
layout: default
permalink: /json-reference/circular-references
title: Circular References
---

# Circular References

This package fully supports recursive references. Consider the following example:

```json
{
"author": {
"properties": {
"name": {
"type": "string"
},
"co-author": {
"$ref": "#/author" // circular reference
}
}
}
}
}
```

## Resolving

If the dereferencer attempted to fully resolve this reference, the dereferencer would continue looping infintely. Instead of resolving references immediately, the $ref is replaced with a [reference object](https://github.com/league/json-reference/blob/master/src/Reference.php).

The reference object is resolved lazily as it is accessed. Because circular object references are possible, make sure code accessing the dereferenced object does not get stuck in an infinite loop.

## Serializing

Because a $ref may be circular, attempting to inline the $ref would be impossible.

When serialized as JSON, all references are transformed into the original `{ "$ref": "#/some/reference" }` format instead of attempting to inline them.

78 changes: 78 additions & 0 deletions docs/json-reference/dereferencing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
layout: default
permalink: /json-reference/dereferencing
title: Dereferencing
---

# Dereferencing

Let's say you have a JSON document like this:

```json
{
"$schema": "http://json-schema.org/draft-04/schema#",
"definitions": {
"pet": {
"type": "object",
"properties": {
"name": { "type": "string" },
"breed": { "type": "string" },
"age": { "type": "string" }
},
"required": ["name", "breed", "age"]
}
},
"type": "object",
"properties": {
"cat": { "$ref": "#/definitions/pet" },
"dog": { "$ref": "#/definitions/pet" }
}
}
```

This document only has _internal_ references. Internal references use a [JSON Pointer](https://tools.ietf.org/html/rfc6901) and start with an anchor (`#`) character. We want to resolve the references `#/definitions/pet` and replace them with the JSON value at that location in the schema.

## Usage

To dereference your schema, create a new `Dereferencer` instance.

```php
<?php

$dereferencer = new League\JsonReference\CoreDereferencer();
```

Now call the `dereference` method with your schema. The schema should be the result from a json_decode call.

<div class="message-warning">
The dereferencer only works with JSON decoded as an object, not an array.
</div>

```php
<?php

$schema = json_decode('{"properties": { "username": {"type": "string"}, "login": {"$ref": "#/properties/username"} } }');
$schema = $dereferencer->dereference($schema);
```

The resulting object is identical, but references have been replaced with Reference objects.

## Paths

Alternatively, you can provide the dereferencer with a path to load the schema from.

```php
<?php

$schema = $dereferencer->dereference('http://json-schema.org/draft-04/schema#');
```

By default `http://`, `https://`, and `file://` paths are supported.

Even if you are using a decoded object, you can still specify the path the schema was loaded from. This allows the dereferencer to resolve relative external references (i.e. `{"$ref": "some-other-schema.json"}`). To specify a path, just pass it as the second argument:

```php
<?php

$schema = $dereferencer->dereference($schema, 'http://json-schema.org/draft-04/schema#');
```

0 comments on commit eef9e4d

Please sign in to comment.