Skip to the content.

Summary

Gendoria parameter converter bundle adds some more converters to Framework Extra Bundle converters.

Build Status Scrutinizer Code Quality Code Coverage Downloads Latest Stable Version

Bundle should be compatible with all versions of PHP higher, than 5.4 (check the build status).

Installation

Step 1: Download the bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

$ composer require gendoria/param-converter "~1"

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Step 2: Enable the Framework Extra bundle

This bundle requires Framework Extra bundle enabled. You can to that by adding it to the list of registered bundles in the app/AppKernel.php file of your project (if not already done):

<?php
// app/AppKernel.php
// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
        );
        // ...
    }
    // ...
}

Step 3: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the app/AppKernel.php file of your project:

<?php
// app/AppKernel.php
// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new Gendoria\ParamConverterBundle\GendoriaParamConverterBundle(),
        );
        // ...
    }
    // ...
}

Usage

You can use parameter converters from this bundle as any other parameter converters.

Service param converter

You can use it by adding following call:

@ParamConverter("parameter_name", converter="service_param_converter", options={"service" = "service_id", "method" = "service_method", "arguments" = {"%requestParamName%", "@otherServiceId", "someParameter"})

Where the first argument is a parameter name, converter specifies the converter to use, and options - configure the converter.

Required options are service (service ID) and method (service method). Additionally, you can pass arguments to method by using “arguments” option.

Arguments is a list of service arguments. There are three types of them:

Converter parameter is only needed, when conversion may collide with other param converters (especially default DoctrineParamConverter).

ArrayObject param converter

This parameter converter can be used to explode parameter into array of objects. Parameter has to be a string with delimited values. Default delimiter is comma, but you can use your own, custom delimiter.

To invoke param converter, you should use following annotation:

@ParamConverter("parameter_name")

Or with custom delimiter:

@ParamConverter("parameter_name", options={"delimiter" = "|"})

Where parameter type in function type hints is ArrayObject.