PHPackages                             dr-benton/before-after-controllers-hooks-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. dr-benton/before-after-controllers-hooks-bundle

AbandonedArchivedLibrary[Framework](/categories/framework)

dr-benton/before-after-controllers-hooks-bundle
===============================================

Provides "@BeforeHook" and "@AfterHook" Annotations support for Symfony Controllers

v1.0.0(11y ago)027.5kMITPHP

Since Nov 13Pushed 11y ago1 watchersCompare

[ Source](https://github.com/DrBenton/BeforeAfterControllersHooksBundle)[ Packagist](https://packagist.org/packages/dr-benton/before-after-controllers-hooks-bundle)[ RSS](/packages/dr-benton-before-after-controllers-hooks-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (2)Used By (0)

BeforeAfterControllersHooksBundle
=================================

[](#beforeaftercontrollershooksbundle)

[![build status](https://camo.githubusercontent.com/d75812d0018d694b2312ead9187f899c4889a0b8d3a892d90d8276edc9a58aa9/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f447242656e746f6e2f4265666f72654166746572436f6e74726f6c6c657273486f6f6b7342756e646c652e706e67)](http://travis-ci.org/DrBenton/BeforeAfterControllersHooksBundle)

If you like [Silex routes middlewares](http://silex.sensiolabs.org/doc/middlewares.html#route-middlewares)or [Ruby on Rails actions filters](http://guides.rubyonrails.org/action_controller_overview.html#filters), you may appreciate this Bundle, as it mimics this behaviour in Symfony2, thanks to specific Annotations.

This type of "before" and "after" callbacks around Controllers Actions may not be very "design patterns compliant", but it's pragmatic and allows easy DRY principle application :-)

With the "@BeforeHook" and "@AfterHook" Annotations, you can trigger methods of the Controller itself, or Symfony Services methods.

If a "@BeforeHook" callback returns a Response object, the Request handling is short-circuited (the next hooks won't be run, neither the Controller action), and the Response is passed to the "@AfterHook" callback(s) right away - or returned to the client if no @AfterHook is linked to this Controller Action.

Synopsis
--------

[](#synopsis)

As always, a code sample may be worth a thousand words:

```
