deblan.tv/vendor/trinity/src/Trinity/Bundle/ContentManagerBundle/Listener/RequestListener.php
2015-03-02 21:57:49 +01:00

41 lines
1.4 KiB
PHP

<?php
namespace Trinity\Bundle\ContentManagerBundle\Listener;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use \Trinity\Bundle\ContentManagerBundle\Navigation\NavigationSelectorInterface;
use \Trinity\Bundle\ContentManagerBundle\Page\PageManagerSelectorInterface;
use \Trinity\Bundle\ContentManagerBundle\Page\DecoratorStrategyInterface;
use \Trinity\Bundle\ContentManagerBundle\Exception\NavigationNotFoundException;
class RequestListener
{
protected $navSelector;
protected $pageSelector;
protected $decoratorStrategy;
public function __construct(NavigationSelectorInterface $navSelector, PageManagerSelectorInterface $pageSelector, DecoratorStrategyInterface $strategy)
{
$this->navSelector = $navSelector;
$this->pageSelector = $pageSelector;
$this->decoratorStrategy = $strategy;
}
public function onKernelRequest(GetResponseEvent $event)
{
if (!$this->decoratorStrategy->isRequestDecorable($event->getRequest())) {
return;
}
$nav = $this->navSelector->retrieve();
if (!$nav) {
throw new NavigationNotFoundException(sprintf('No navigation loaded. Check out if you have configured a navigation with the domain: "%s"', $event->getRequest()->getHost()));
}
$cms = $this->pageSelector->retrieve();
$cms->setNavigation($nav);
$cms->changeCurrentPage();
}
}