polidog / controller-filter-bundle
1.0.6
2018-06-16 14:57 UTC
Requires
- php: ~7.0
- doctrine/common: ~2.2
- symfony/config: ~2.8|~3.0|~4.0
- symfony/dependency-injection: ~2.8|~3.0|~4.0
- symfony/event-dispatcher: ~2.8|~3.0|~4.0
- symfony/http-kernel: ~2.8|~3.0|~4.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.3
- phpunit/phpunit: ^6.5
- symfony/framework-bundle: ~2.8|~3.0|~4.0
README
This bundle to allow you to describe filtering with annotations in the Controller class.
Install
install polidog/controller-filter-bundle with composer.
$ composer require polidog/controller-filter-bundle
Configuration
// AppKernel.php public function registerBundles() { $bundles = array( // ... new Polidog\ControllerFilterBundle\PolidogControllerFilterBundle(), // ... ); }
Using
// controller class /** * @Route("/card") * @Filter(Filter::TYPE_BEFORE, method="checkSession", service="app.service.check_service") */ class CardController extends Controller { use DonationSessionTrait; /** * @Route("/") * @Method("GET") * @Template() * @Filter(Filter::TYPE_AFTER, method="changeResult", service="app.service.check_service") */ public function indexAction(Request $request) { return ['hoge' =>'fuga']; } }
// service class class CheckService { /** * @Session */ private $session; public function changeResult() { if ($this->session->has('hoge') { throw new \Exception(); } } public function changeResult(GetResponseForControllerResultEvent $event) { $event->setControllerResult(['hoge' => 'hogehoge']); } }
// services.yml services: app.service.check_service: class: AppBundle\Service\CheckService public: true arguments: ["@session"]