Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
odan committed May 30, 2020
1 parent a6f6494 commit 7fac1dc
Showing 1 changed file with 22 additions and 29 deletions.
51 changes: 22 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,35 +118,7 @@ it into a nice JSON response.

#### Slim 4 integration

```php
<?php

use Selective\Validation\Encoder\JsonEncoder;
use Selective\Validation\Middleware\ValidationExceptionMiddleware;
use Selective\Validation\Transformer\ErrorDetailsResultTransformer;
use Slim\Factory\AppFactory;

require_once __DIR__ . '/../vendor/autoload.php';

$app = AppFactory::create();

$app->add(new ValidationExceptionMiddleware(
$app->getResponseFactory(),
new ErrorDetailsResultTransformer(),
new JsonEncoder()
));

// If you are using a container, you can also use this option:
// $app->add(ValidationExceptionMiddleware::class);

// ...

$app->run();
```

### Container definition

This example uses PHI-DI:
Insert a container definition for `ValidationExceptionMiddleware::class`:

```php
<?php
Expand Down Expand Up @@ -188,6 +160,27 @@ return [
];
```

Add the `ValidationExceptionMiddleware` into your middlware stack:

```php
<?php

use Selective\Validation\Middleware\ValidationExceptionMiddleware;
use Slim\Factory\AppFactory;

require_once __DIR__ . '/../vendor/autoload.php';

$app = AppFactory::create();

// ...

$app->add(ValidationExceptionMiddleware::class);

// ...

$app->run();
```

#### Usage

```php
Expand Down

0 comments on commit 7fac1dc

Please sign in to comment.