Skip to content

Fix various details in README.md #335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 26, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@ See [json-schema](http://json-schema.org/) for more details.

### Library

$ git clone https://github.com/justinrainbow/json-schema.git
```bash
git clone https://github.com/justinrainbow/json-schema.git
```

### Dependencies
### Composer

#### [`Composer`](https://github.com/composer/composer) (*will use the Composer ClassLoader*)
[Install PHP Composer](https://getcomposer.org/doc/00-intro.md)

$ wget http://getcomposer.org/composer.phar
$ php composer.phar require justinrainbow/json-schema:~2.0
```bash
composer require justinrainbow/json-schema
```

## Usage

### Basic usage

```php
<?php

Expand All @@ -43,17 +44,23 @@ if ($validator->isValid()) {
}
}
```
###Type Coercion
If you're validating data passed to your application via HTTP, you can cast strings and booleans to the expected types defined by your schema:

### Type coercion

If you're validating data passed to your application via HTTP, you can cast strings and booleans to
the expected types defined by your schema:

```php
<?php

use JsonSchema\SchemaStorage;
use JsonSchema\Validator;
use JsonSchema\Constraints\Factory;
use JsonSchema\Constraints\Constraint;

$request = (object)[
'processRefund'=>"true",
'refundAmount'=>"17"
'processRefund'=>"true",
'refundAmount'=>"17"
];

$factory = new Factory( null, null, Constraint::CHECK_MODE_TYPE_CAST | Constraint::CHECK_MODE_COERCE );
Expand All @@ -75,7 +82,7 @@ is_bool($request->processRefund); // true
is_int($request->refundAmount); // true
```

Note that the ```CHECK_MODE_COERCE``` flag will only take effect when an object is passed into the ```check``` method.
Note that the `CHECK_MODE_COERCE` flag will only take effect when an object is passed into the `check()` method.

### With inline references

Expand Down Expand Up @@ -133,4 +140,6 @@ $jsonValidator->check($jsonToValidateObject, $jsonSchemaObject);

## Running the tests

$ vendor/bin/phpunit
```bash
vendor/bin/phpunit
```