Download the PHP package realshadow/request-deserializer without Composer

On this page you can find all versions of the php package realshadow/request-deserializer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package request-deserializer

Scrutinizer Code Quality Build Status

Request deserializer

Package for providing JSON schema validation and request deserialization for API's built on top of Dingo API.

Installation

Since this package is built on top Dingo API it has to be installed first, see its installation instructions for details.

Now you can run

Add package provider to list of providers in app.php configuration file

and add the request deserialization middleware to Kernel

And for the last step publish configuration files with

I should note that this package relies on Purifier package and if you are using it, you will have to update its configuration accordingly or use the --force option for publishing.

Usage

After you complete the installation steps you can add the DeserializesRequests trait to your controller. Now you can create a new schema and request object pair (see how it works section for more details).

How it works

This package is built on top of Dingo API and combines two great packages - JMS serializer and JSON schema validator to create a powerful validation and deserialization layer for all incoming requests.

Note: I will assume you are familiar with at least one of the required packages.

Now for the actual magic

Middleware will catch every request and looks if the called method in controller expects any request object in its arguments. If its found the request will run trough 3 steps:

Basic request object looks like this

Request object must implement RequestInterface. This interface contains three helper methods that will describe the request for us (see phpdoc in code above) and list of properties and their respective getter methods.

When the validation of a request fails, it will throw HTTP 422 Validation Exception with list of violated constraints.

GET requests

PHP will handle every parameter in query string as a string. In this case the validation process will use type coercion. Furthermore all passed data is deserialized to the correct type defined in request object.

Caveats

Since all properties are always present in request objects (or any object for that matter) it is impossible to distinguish between properties that should have null values and properties that are not present in request body as they will always be null. You can get around it by using Laravels Input facade or any other viable method that works with the original request directly.

Configuration

Package contains two configuration files:

Package configuration

Package configuration is merged so if you want to extend it just copy the required options from package configuration.

Cache directory for serializer can be configured in .env by setting SERIALIZER_STORAGE_PATH key.

Helper command

Since creation of bigger request objects can become tedious this package includes a helper command that will generate a new request object from provided JSON schema. Usage is very simple

JSON schema and created request are always relative to directories set in configuration including the namespace the request object will belong to.

Examples

In the example folder you can find two directories with request objects and their respecitive schemas - a simple request and a more complicated request with nested schema. These should work out of the box so it should be enough just to copy them to their respective folders (dont forget to add methods in routes!)

Furthermore you can import a Postman collection with two example requests that will for with example schemas.


All versions of request-deserializer with dependencies

PHP Build Version
Package Version
Requires php Version ^5.6.0 || ^7.0
dingo/api Version v1.0.0-beta8
justinrainbow/json-schema Version ^5.0
jms/serializer Version ^1.7
mews/purifier Version ^2.0
doctrine/cache Version ^1.6
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package realshadow/request-deserializer contains the following files

Loading the files please wait ....