Skip to content

Commit

Permalink
composer.json and little clean
Browse files Browse the repository at this point in the history
  • Loading branch information
Yavin committed Dec 20, 2013
1 parent 92ac1e6 commit 1b92360
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/vendor/
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Symfony Init Controller extension
Add ability to call `init` method in controller before every action. This is similar functionality that are in Zend Frameowrk.
Add ability to call `init` method in controller before every action.
Based on [this answer](http://stackoverflow.com/a/11179521/1051297)


You must implement `Yavin\Symfony\Controller\InitControllerInterface` in controller that you wont to have init method.
You must implement `Yavin\Symfony\Controller\InitControllerInterface` in controller that you want to have init method.
Then you can have your init method like this:
```php
namespace Acme\DemoBundle\Controller;

Expand All @@ -18,23 +20,23 @@ class SampleController extends Controller implements InitControllerInterface
$request = $this->getRequest();
$this->page = $request->get('page');
}

public function indexAction()
{
//...
}

public function otherAction()
{
//...
}
}
```

To add this functionality you must add service in symfony config:
To add this functionality you must add service in symfony `app/config/config.yml`:
```
services:
yavin.symfony.controller.init.subscriber:
symfony.controller.init.subscriber:
class: "Yavin\\Symfony\\Controller\\InitControllerSubscriber"
tags:
- { name: kernel.event_subscriber }
Expand Down
16 changes: 16 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "yavin/symfony-init-controller",
"description": "Runs init controller method before every action",
"require": {
"symfony/http-kernel": "~2.0",
"symfony/event-dispatcher": "~2.0"
},
"license": "mit",
"authors": [
{
"name": "Yavin",
"email": "[email protected]"
}
],
"minimum-stability": "stable"
}
2 changes: 0 additions & 2 deletions src/Yavin/Symfony/Controller/InitControllerSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Yavin\Symfony\Controller;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;

Expand Down Expand Up @@ -38,4 +37,3 @@ public function onKernelController(FilterControllerEvent $event)
}
}
}

0 comments on commit 1b92360

Please sign in to comment.