Created
September 10, 2012 19:10
-
-
Save rande/3693051 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* This file is part of the Sonata project. | |
* | |
* (c) Thomas Rabaix <[email protected]> | |
* | |
* For the full copyright and license information, please view the LICENSE | |
* file that was distributed with this source code. | |
*/ | |
namespace Sonata\PageBundle\Route; | |
use Symfony\Component\Routing\RouterInterface; | |
use Sonata\PageBundle\Exception\PageNotFoundException; | |
use Symfony\Component\Routing\Exception\ResourceNotFoundException; | |
use Symfony\Component\Routing\RequestContext; | |
use Symfony\Component\Routing\RouteCollection; | |
use Sonata\PageBundle\CmsManager\CmsManagerSelector; | |
use Sonata\PageBundle\Site\SiteSelectorInterface; | |
class CmsRouter implements RouterInterface | |
{ | |
protected $context; | |
protected $cmsSelector; | |
protected $siteSelector; | |
protected $router; | |
/** | |
* @param CmsManagerSelector $selector | |
*/ | |
public function __construct(CmsManagerSelector $cmsSelector, SiteSelectorInterface $siteSelector) | |
{ | |
$this->cmsSelector = $cmsSelector; | |
$this->siteSelector = $siteSelector; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function setContext(RequestContext $context) | |
{ | |
$this->context = $context; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function getContext() | |
{ | |
return $this->context; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function getRouteCollection() | |
{ | |
return new RouteCollection(); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function generate($name, $parameters = array(), $absolute = false) | |
{ | |
return false; | |
throw new \RuntimeException('Invalid priority in the router chain'); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function match($pathinfo) | |
{ | |
$cms = $this->cmsSelector->retrieve(); | |
$site = $this->siteSelector->retrieve(); | |
try { | |
$page = $cms->getPageByUrl($site, $pathinfo); | |
} catch(PageNotFoundException $e) { | |
throw new ResourceNotFoundException($pathinfo, 0, $e); | |
} | |
if (!$page || !$page->isCms()) { | |
throw new ResourceNotFoundException($pathinfo); | |
} | |
$cms->setCurrentPage($page); | |
return array ( | |
'_controller' => 'sonata.page.renderer:render', | |
'_route' => 'page_slug', | |
'page' => $page, | |
'params' => array() | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment