bu/extra-param-converter-bundle
BuExtraParamConverterBundle extends Sensio ParamConverter functionality, allowing to convert simple GET and complex POST data to entities, decode json data and strip tags from data.
Requires SensioFrameworkExtraBundle.
Add bundle with composer:
composer require bu/extra-param-converter-bundle dev-master
Register bundle in AppKernel.php:
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Bu\ExtraParamConverterBundle\BuExtraParamConverterBundle(),
);
}
Sensio ParamConverter should be enabled, ie parameter sensio_framework_extra.request.converters in your app config should be set to true (set by default).
GetConverter
You don't need to write any annotations, following code will work with any GET request with user parameter, like "/getUserDetails?user=123"
public function detailsAction(User $user)
{
...
}
where 123 is user id. It will throw NotFoundHttpException if can't find User by this id.
PostConverter
use Bu\ExtraParamConverterBundle\Configuration\ExtraParamConverter;
/**
* @ExtraParamConverter("data", jsonData=true, stripTags=true, namespace="App", entities={"groups"="Group", "role"="Role"})
*/
public function saveUserAction(array $data)
{
// $data['groups'] ...
}
In this example:
Recommented to set doctrine mapping alias for your bundle:
# Doctrine Configuration
doctrine:
orm:
mappings:
ApplicationMySuperBundle:
alias: My
This will allow you to use short namespace "My" instead of long autogenerated "ApplicationMySuperBundle".
This bundle is under the MIT license.
How can I help you explore Laravel packages today?