Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
map _template default into request attributes
  • Loading branch information
dbu committed Jun 7, 2012
1 parent 54d2717 commit 0ace4c1
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions Routing/DynamicRouter.php
Expand Up @@ -6,6 +6,7 @@
use Symfony\Component\DependencyInjection\ContainerAwareInterface;

use Symfony\Cmf\Component\Routing\DynamicRouter as BaseDynamicRouter;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;

/**
* A router that reads route entries from an Object-Document Mapper store.
Expand Down Expand Up @@ -57,18 +58,31 @@ public function match($url)
{
$defaults = parent::match($url);

if (isset($defaults['_content'])) {
if (! $request = $this->container->get('request')) {
throw new \Exception('Request object not available from container');
}
if (isset($defaults[RouteObjectInterface::CONTENT_OBJECT])) {
$request = $this->getRequest();

$request->attributes->set(self::CONTENT_KEY, $defaults['_content']);
unset($defaults['_content']);
$request->attributes->set(self::CONTENT_KEY, $defaults[RouteObjectInterface::CONTENT_OBJECT]);
unset($defaults[RouteObjectInterface::CONTENT_OBJECT]);
}

if (isset($defaults[RouteObjectInterface::TEMPLATE_NAME])) {
$request = $this->getRequest();

$request->attributes->set(self::CONTENT_TEMPLATE, $defaults[RouteObjectInterface::TEMPLATE_NAME]);
unset($defaults[RouteObjectInterface::TEMPLATE_NAME]);
}

return $defaults;
}

public function getRequest()
{
if (!$request = $this->container->get('request')) {
throw new \Exception('Request object not available from container');
}
return $request;
}

protected function getLocale($parameters)
{
$locale = parent::getLocale($parameters);
Expand Down

0 comments on commit 0ace4c1

Please sign in to comment.