Skip to content

Instantly share code, notes, and snippets.

@JJK801
Last active December 24, 2015 09:09
Show Gist options
  • Save JJK801/6775056 to your computer and use it in GitHub Desktop.
Save JJK801/6775056 to your computer and use it in GitHub Desktop.
Code illustration for M6Web article
<?php
namespace M6\Bundle\MyBundle\Listener;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use M6\Bundle\MyBundle\Helper\MyHelper;
class MyEventSubscriber implements EventSubscriberInterface
{
protected $helper = null;
public function __construct(MyHelper $myHelper)
{
$this->helper = $myHelper;
}
static public function getSubscribedEvents()
{
$subscriber = array(
KernelEvents::REQUEST => array(
array('onKernelRequest', 0),
)
);
return $subscriber;
}
public function onKernelRequest(GetResponseEvent $event)
{
$this->helper->doSomething($event->getRequest()->getPathInfo());
return $this;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment