softius/cakephp-param-converter

Param converter for CakePHP Routing

v0.4.0 2019-05-16 11:26 UTC

This package is auto-updated.

Last update: 2024-11-07 05:46:49 UTC


README

CakePHP v3.x plugin for converting request parameters to objects. These objects replace the original parameters before dispatching the controller action and hence they can be injected as controller method arguments.

Heavily inspired by Symfony ParamConverter

Install

Using Composer:

composer require softius/cakephp-param-converter

You then need to load the plugin. You can use the shell command:

bin/cake plugin load ParamConverter

Usage

Adjustments on application level are only necessary if you need to remove or / add new param converters.

Configuration

By default, the plugin provides and registers converters that can be used to convert request parameters to Entity and DateTime instances as well as various scalar types. Converters can be removed / added by adjusting the following configuration:

<?php
// config/param_converter.php
return [
    'ParamConverter' => [
        'converters' => [
            \ParamConverter\EntityParamConverter::class,
            \ParamConverter\DateTimeParamConverter::class,
            \ParamConverter\BooleanParamConverter::class,
            \ParamConverter\IntegerParamConverter::class,
            \ParamConverter\FloatParamConverter::class
        ]
    ]
];

Creating a converter

All converters must implement the ParamConverterInterface.

Security

If you discover any security related issues, please email softius@gmail.com instead of using the issue tracker.

Credits

License

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