PHP Classes

How to Use a PHP Request Data Mapping to Get Application Parameters Using the Package Request Data Adapter: Convert request parameters to internal parameters

Recommend this page to a friend!
  Info   View files Documentation   View files View files (4)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-05-17 (1 month ago) RSS 2.0 feedNot yet rated by the usersTotal: 17 This week: 2All time: 11,275 This week: 54Up
Version License PHP version Categories
request-data-adapter 1.0MIT/X Consortium ...5Libraries, Data types, Design Patterns, P...
Description 

Author

This package can convert request parameters to internal parameters.

It provides a trait that can be used with Laravel request processing classes and the trait code can do the mapping operation.

Developers should use the mappingData function to specify how request parameters should be converted to the respective application parameters.

Innovation Award
PHP Programming Innovation award nominee
May 2024
Nominee
Vote
Web applications usually process requests sent by browsers on behalf of the Web users for instance after processing forms or clicking links.

Often these forms or links contain parameter values that configure actions to be performed on the server side.

Usually, the names of the parameters passed via forms or links have names that are the same names used in the code of the Web application for instance as database table field names.

Sometimes it is convenient for the Web application to use other names that are more friendly to the users but are different from the parameter names used by the application on the server side.

This may be the case when the request parameters have names in the language of the user and the application parameter names are in English or some other specific language.

When there is this difference of names, there needs to exist a parameter conversion process on the server side. This package provides this kind of parameter conversion.

Manuel Lemos
Picture of Andrey Iatsenko
  Performance   Level  
Name: Andrey Iatsenko <contact>
Classes: 11 packages by
Country: Russian Federation Russian Federation
Age: 29
All time rank: 4246117 in Russian Federation Russian Federation
Week rank: 53 Up5 in Russian Federation Russian Federation Up
Innovation award
Innovation award
Nominee: 7x

Documentation

RequestDataAdapter - Adapter for converting input data from Illuminate\Http\Request

<img alt="Packagist Downloads" src="https://img.shields.io/packagist/dm/yzen.dev/request-data-adapter"> <img alt="Packagist Downloads" src="https://img.shields.io/packagist/dt/yzen.dev/request-data-adapter">

This package provides easy conversion of input keys to your internal keys.

This adapter is perfect for you if for example you do not want to give your internal keys containing typos (but we know that you can?t have this?), or vice versa, translate incorrect keys into the correct form.

:scroll: Installation

The package can be installed via composer:

composer require yzen.dev/request-data-adapter

:scroll: Usage

To use the adapter, you must connect this trait:

class CommentStoreRequest extends FormRequest
{
    use RequestDataAdapter;
    ...
}

Then you need to implement the mappingData method (PHPStorm itself will offer you add method stubs)

    /
     * {@inheritDoc}
     */
    public function mappingData(): array
    {
        return [
            'tatle' => 'title',
            'autor' => 'author',
            'files' => [
                'file' => [
                    'document_name' => 'name'
                ],
            ],
            'additions' => [
                'date' => 'date_time',
            ],
        ];
    }

Thus, you can already work in the controller with the data set you need:

{
  "title": "Test packages",
  "author": "Taylor",
  "files": [
    {
      "file": {
        "document_name": "my_photo"
      }
    }
  ],
  "additions": {
    "date": "date_time"
  }
}

  Files folder image Files  
File Role Description
Files folder imagesrc (1 file)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
  Plain text file RequestDataAdapter.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:17
This week:2
All time:11,275
This week:54Up