Download the PHP package maksi/laravel-request-mapper without Composer

On this page you can find all versions of the php package maksi/laravel-request-mapper. 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 laravel-request-mapper

Request Mapper for Laravel

Build Status Code Coverage Latest Stable Version License

This component allow you to inject DTO object mapped from the Request to the action.

  1. Install
  2. Requirements
  3. Basic usage
  4. Nested object
  5. Mapped strategies
  6. Create custom mapped strategy
  7. How to create an custom exception?
  8. Project example
  9. Contributing
  10. Licence
  11. TODO

1. Install

You can install this package via composer using this command:

The package will automatically register itself.

2. Requirements

PHP 7.1 or newer and Laravel 5.5 or newer

3. Basic usage

3.1 Create an DTO object

Your DTO object should extend one of RequestData classes:

RequestData classes responsible for mapped strategies.

$data array in the init it is an array which return from the mapped strategies classes. Basically $data it is some data from the Request.

3.2 Inject to the action

DTO object can be injected to any type of action.

3.3 Validate DTO object

You can apply validation to the DTO object:

3.3.1 Apply laravel validation

Laravel validation applied for the RequestData object before object filling.

  1. You should create a class with validation rules. This class should implement Maksi\LaravelRequestMapper\Validation\BeforeType\Laravel\ValidationRuleInterface interface (in case, if you do no need change the validation messages and customAttributes, than you can extend Maksi\LaravelRequestMapper\Validation\BeforeType\Laravel\AbstractValidationRule class)

  2. In the next you should apply this rules to the DTO object. This should be done via annotation.

string

indicates that before filling current DTO should be appied \Maksi\LaravelRequestMapper\Tests\Integration\LaravelNestedValidation\Stub\ValidatorRule rules for the data which will be injected to the dto.

3.3.2 Apply symfony annotation validation

Annotation symfony validation applied to the properties in the RequestData object (So this validation appied after the creating and DTO object).

At the first you should add the @Type(type="annotation") annotation to the RequestData object. After this you can apply the validation to the DTO object (for more information please see symfony validation documentation)

4. Nested object validation

4.1. Symfony annotation validation

In the same way you can create an nested DTO object, for example:

Root class

Nested class

4.2. Laravel validation for nested

So, as a laravel validation applied before filling the RequestData object, than you should just create the same validation class as an for no nested validation.

5. Mapped strategies

By default package has 3 strategies:

AllStrategy - responsible for filling data from the $request->all() array. If you want to use this strategy, than your RequestData object should extend AllRequestData class.

HeaderStrategy - responsible for filling data from the $request->header->all() array. If you want to use this strategy, than your RequestData object should extend HeaderRequestData class.

JsonStrategy - responsible for filling data from the $request->json()->all() array. If you want to use this strategy, than your RequestData object should extend JsonRequestData class.

6. Create custom mapped strategy

You can create a custom mapped strategies for our application.

6.1 Create custom strategy

You strategy should implement StrategyInterface;

Method support define is strategy available for resolve object. This method has 2 parameters $request and $object:

Method resolve will return the array which will be injected to the DTO instance. This method accept $request object.

6.2 Create RequestData class for Strategy

You should extend RequestData in case if you want to create your own strategy

6.3 Register your strategy in the ServiceProvider

You should add instance of your strategy to the Maksi\LaravelRequestMapper\StrategiesHandler via addStrategy method.

7. Change validation exception

  1. Create Exception which will extend \Maksi\LaravelRequestMapper\Validation\ResponseException\AbstractException and implement toResponse method

For example:

  1. Define in config/laravel-request-mapper.php exception-class key

8. Project example

You can see example of usage part of this package in https://github.com/E-ZSTU/rozklad-rest-api project.

Contributing

Please see CONTRIBUTING for details.

License

The MIT License (MIT). Please see License File for more information.

TODO


All versions of laravel-request-mapper with dependencies

PHP Build Version
Package Version
Requires doctrine/annotations Version ^1.6
doctrine/cache Version ^1.8
illuminate/contracts Version ^5.5
illuminate/http Version ^5.5
illuminate/support Version ^5.5
illuminate/validation Version ^5.5
symfony/validator Version ^4.1
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 maksi/laravel-request-mapper contains the following files

Loading the files please wait ....