zalas / param-converter-bundle
Bundle that provides additional param converters for Symfony
Installs: 177
Dependents: 0
Suggesters: 0
Security: 0
Stars: 16
Watchers: 4
Forks: 2
Open Issues: 0
Type:bundle
Requires
- php: ^7.0
- sensio/framework-extra-bundle: ^3.0.3
Requires (Dev)
- phpspec/phpspec: ^3.4
- phpunit/phpunit: ^6.1.4
- symfony/browser-kit: ^3.2||^4.0
- symfony/config: ^3.2||^4.0
- symfony/dom-crawler: ^3.2||^4.0
- symfony/framework-bundle: ^3.2.8||^4.0
This package is auto-updated.
Last update: 2021-08-05 11:49:59 UTC
README
This bundle provides additional param converters for Symfony.
Since argument resolvers and service arguments were introduced in Symfony 3.3, the param converter provided by this bundle is redundant. We can achieve pretty much the same by injecting services directly to controller actions.
Installation
This bundle requires:
- PHP ^7.0
- sensio/framework-extra-bundle ~3.0
The easiest way to install it is to use Composer:
$ composer require zalas/param-converter-bundle:^1.0
Service Param Converter
The service param converter calls a configured service to convert a request attribute to an object.
Options:
- service - a service id
- method - a method name to be called on the service
- arguments - list of request attributes to be passed as method call arguments
Example:
<?php namespace AppBundle\Controller; use AppBundle\Site\Visitor; use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Symfony\Component\HttpFoundation\Response; class DemoController { /** * @Route("/hello/{name}") * @ParamConverter( * "visitor", * converter="service", * options={ * "service": "visitor_repository", * "method": "findByName", * "arguments": {"name"} * } * ) */ public function indexAction(Visitor $visitor) { return new Response('Hello '.$visitor->getName()); } }