PHPackages                             pln0w/rest-api-validator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. pln0w/rest-api-validator

AbandonedArchivedLibrary[HTTP &amp; Networking](/categories/http)

pln0w/rest-api-validator
========================

A package for creating request objects for pre-controller validation

1.0.0(6y ago)114MITPHPPHP ^7.4

Since Dec 18Pushed 6y ago1 watchersCompare

[ Source](https://github.com/pln0w/rest-api-validator)[ Packagist](https://packagist.org/packages/pln0w/rest-api-validator)[ Docs](https://github.com/pln0w/rest-api-validator)[ RSS](/packages/pln0w-rest-api-validator/feed)WikiDiscussions master Synced 5d ago

READMEChangelogDependencies (4)Versions (2)Used By (0)

Request Object validator
========================

[](#request-object-validator)

A simple library to force and make consistent development REST API controllers. It allows to define structure of the payload and it validator constraints. It also provides much easier way to access validated data from within the controller body.

Installation
------------

[](#installation)

`composer require pln0w/rest-api-validator`

Add following section to your *services.yml*

```
Pawly\RestApiValidator\Resolver\CustomRequestResolver:
    arguments:
      - '@validator'
    tags:
      - { name: controller.request_value_resolver }
```

Each request object must have *request\_stack* service injected, i.e:

```
User\Infrastructure\Request\RegisterUserRequest:
        arguments:
            - '@request_stack'
```

Usage
-----

[](#usage)

- Steps to provide validation to your controllers:

    - Create custom request overriding *Pawly\\RestApiValidator\\Request\\AbstractCustomRequest*
    - Define request class properties that you want to map request values with
    - Add validation constraints to *$metadata* (no yaml, no addnotations - pure PHP config)
    - *(optional)* Override getters for properties in needed or add constraint explicit against getter
        *See validation docs:*

    #### Example 1.

    [](#example-1)

    ```
