gendoria / param-converter-bundle
Adds several additional parameter converters
Installs: 36
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=5.3.0
- sensio/framework-extra-bundle: ~3.0
- symfony/framework-bundle: ~2.3|~3.0
Requires (Dev)
- symfony/expression-language: ~2.6|~3.0
- symfony/security-bundle: ~2.4|~3.0
Suggests
- symfony/expression-language
- symfony/psr-http-message-bridge: To use the PSR-7 converters
- symfony/security-bundle
README
Gendoria parameter converter bundle adds some more converters to Framework Extra Bundle converters.
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:
- Simple argument. This is the default option. No additional parsing is added.
- Request parameter. You have to enclose parameter name with % signs
and converter will extract it from the request. For example,
when you define argument as
%myParam%
, the service will try to fetch parametermyParam
from the request. - Service parameter. When you preceede argument with
@
character, it will be treated as a service ID. Parser will try to fetch the service from service container and inject it to the method call. If the service is not registered in the container, an\InvalidArgumentException
will be thrown.
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
.