Skip to content
Snippets Groups Projects
Commit 45e34c29 authored by Fabien Potencier's avatar Fabien Potencier
Browse files

[Routing] simplified code

parent 794634db
Branches
Tags vPR4
No related merge requests found
......@@ -51,7 +51,6 @@ class PhpGeneratorDumper extends GeneratorDumper
{
$methods = array();
$routes = array();
foreach ($this->routes->all() as $name => $route) {
$compiledRoute = $route->compile();
......@@ -69,17 +68,19 @@ class PhpGeneratorDumper extends GeneratorDumper
EOF
;
$routes[$name] = true;
$routes[] = " '$name' => true,";
}
$methods = implode("\n", $methods);
$routes = $this->exportParameters($routes);
$routes = implode("\n", $routes);
return <<<EOF
public function generate(\$name, array \$parameters, \$absolute = false)
{
static \$routes = $routes;
static \$routes = array(
$routes
);
if (!isset(\$routes[\$name])) {
throw new \InvalidArgumentException(sprintf('Route "%s" does not exist.', \$name));
......@@ -133,20 +134,4 @@ EOF;
EOF;
}
protected function exportParameters($parameters, $indent = 12)
{
$php = array();
foreach ($parameters as $key => $value) {
if (is_array($value)) {
$value = $this->exportParameters($value, $indent + 4);
} else {
$value = var_export($value, true);
}
$php[] = sprintf('%s%s => %s,', str_repeat(' ', $indent), var_export($key, true), $value);
}
return sprintf("array(\n%s\n%s)", implode("\n", $php), str_repeat(' ', $indent - 4));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment