changed the routing to accept a single _controller argument instead of _bundle, _controller, and _action (the _controller is the : separated representation of a controller - this is more coherent with other part of the framework)

This commit is contained in:
Fabien Potencier 2010-05-12 20:49:45 +02:00
parent 9005efaa17
commit fd331bac18
6 changed files with 11 additions and 18 deletions

View File

@ -43,7 +43,7 @@ class ControllerLoader
{
$request = $this->container->getRequestService();
list($path['_bundle'], $path['_controller'], $path['_action']) = explode(':', $controller);
$path['_controller'] = $controller;
$subRequest = $request->duplicate($query, null, $path);
@ -58,15 +58,15 @@ class ControllerLoader
{
$request = $event->getParameter('request');
if (!($bundle = $request->path->get('_bundle')) || !($controller = $request->path->get('_controller')) || !($action = $request->path->get('_action'))) {
if (!$controller = $request->path->get('_controller')) {
if (null !== $this->logger) {
$this->logger->err(sprintf('Unable to look for the controller as some mandatory parameters are missing (_bundle: %s, _controller: %s, _action: %s)', isset($bundle) ? var_export($bundle, true) : 'NULL', isset($controller) ? var_export($controller, true) : 'NULL', isset($action) ? var_export($action, true) : 'NULL'));
$this->logger->err('Unable to look for the controller as the _controller parameter is missing');
}
return false;
}
$controller = $this->findController($bundle, $controller, $action);
$controller = $this->findController($controller);
$controller[0]->setRequest($request);
$r = new \ReflectionObject($controller[0]);
@ -80,8 +80,9 @@ class ControllerLoader
/**
* @throws \InvalidArgumentException|\LogicException If controller can't be found
*/
public function findController($bundle, $controller, $action)
public function findController($controller)
{
list($bundle, $controller, $action) = explode(':', $controller);
$class = null;
$logs = array();
foreach (array_keys($this->container->getParameter('kernel.bundle_dirs')) as $namespace) {

View File

@ -25,19 +25,15 @@ use Symfony\Foundation\LoggerInterface;
class ExceptionHandler
{
protected $container;
protected $bundle;
protected $controller;
protected $action;
protected $logger;
public function __construct(ContainerInterface $container, LoggerInterface $logger = null, $bundle, $controller, $action)
public function __construct(ContainerInterface $container, LoggerInterface $logger = null, $controller)
{
$this->container = $container;
$this->logger = $logger;
$this->bundle = $bundle;
$this->controller = $controller;
$this->action = $action;
}
public function register()
@ -58,9 +54,7 @@ class ExceptionHandler
}
$parameters = array(
'_bundle' => $this->bundle,
'_controller' => $this->controller,
'_action' => $this->action,
'exception' => $exception,
'originalRequest' => $event->getParameter('request'),
'logs' => $this->container->hasService('zend.logger.writer.debug') ? $this->container->getService('zend.logger.writer.debug')->getLogs() : array(),

View File

@ -59,7 +59,7 @@ class RequestParser
));
$this->container->setParameter('request.base_path', $request->getBasePath());
if ($request->path->has('_bundle')) {
if ($request->path->has('_controller')) {
return;
}

View File

@ -4,5 +4,5 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.symfony-project.org/schema/routing http://www.symfony-project.org/schema/routing/routing-1.0.xsd">
<route id="_internal" pattern="/:_bundle/:_controller/:_action.:_format" />
<route id="_internal" pattern="/:_controller.:_format" />
</routes>

View File

@ -5,8 +5,6 @@
xsi:schemaLocation="http://www.symfony-project.org/schema/routing http://www.symfony-project.org/schema/routing/routing-1.0.xsd">
<route id="homepage" pattern="/">
<default key="_bundle">WebBundle</default>
<default key="_controller">Default</default>
<default key="_action">index</default>
<default key="_controller">WebBundle:Default:index</default>
</route>
</routes>

View File

@ -1,3 +1,3 @@
homepage:
pattern: /
defaults: { _bundle: WebBundle, _controller: Default, _action: index }
defaults: { _controller: WebBundle:Default:index }