66 lines
1.6 KiB
PHP
66 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace Trinity\Bundle\ContentManagerBundle\Navigation;
|
|
|
|
use \Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
|
use \Symfony\Component\HttpFoundation\Request;
|
|
use \Trinity\Bundle\ContentManagerBundle\Model\NavPeer;
|
|
use \Trinity\Bundle\ContentManagerBundle\Page\DecoratorStrategyInterface;
|
|
|
|
class NavigationSelector implements NavigationSelectorInterface
|
|
{
|
|
protected $nav;
|
|
protected $request;
|
|
protected $decoratorStrategy;
|
|
|
|
public function __construct(DecoratorStrategyInterface $strategy)
|
|
{
|
|
$this->decoratorStrategy = $strategy;
|
|
}
|
|
|
|
public function retrieve()
|
|
{
|
|
return $this->nav;
|
|
}
|
|
|
|
protected function setRequest(Request $request)
|
|
{
|
|
$this->request = $request;
|
|
}
|
|
|
|
public function set(NavigationInterface $nav)
|
|
{
|
|
$this->nav = $nav;
|
|
}
|
|
|
|
protected function getNavigation()
|
|
{
|
|
if (!$this->request) {
|
|
throw new \RuntimeException('No Request attached.');
|
|
}
|
|
|
|
if ($this->nav) {
|
|
return $this->nav;
|
|
}
|
|
|
|
return NavPeer::retrieveByDomainAndCulture($this->request->getHost(), $this->request->getLocale());
|
|
}
|
|
|
|
public function onKernelRequest(GetResponseEvent $event)
|
|
{
|
|
// URI or request?
|
|
if (!$this->decoratorStrategy->isRouteUriDecorable($event->getRequest()->getPathInfo())) {
|
|
return;
|
|
}
|
|
|
|
$this->setRequest($event->getRequest());
|
|
|
|
$this->handleKernelRequest($event);
|
|
}
|
|
|
|
public function handleKernelRequest(GetResponseEvent $event)
|
|
{
|
|
$this->nav = $this->getNavigation();
|
|
}
|
|
}
|