10000 [Routing] simplified code · ShinichiU/symfony@45e34c2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 45e34c2

Browse files
committed
[Routing] simplified code
1 parent 794634d commit 45e34c2

File tree

1 file changed

+5
-20
lines changed

1 file changed

+5
-20
lines changed

src/Symfony/Component/Routing/Generator/Dumper/PhpGeneratorDumper.php

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ protected function addGenerator()
5151
{
5252
$methods = array();
5353
$routes = array();
54-
5554
foreach ($this->routes->all() as $name => $route) {
5655
$compiledRoute = $route->compile();
5756

@@ -69,17 +68,19 @@ protected function get{$name}RouteInfo()
6968
EOF
7069
;
7170

72-
$routes[$name] = true;
71+
$routes[] = " '$name' => true,";
7372
}
7473

7574
$methods = implode("\n", $methods);
76-
$routes = $this->exportParameters($routes);
75+
$routes = implode("\n", $routes);
7776

7877
return <<<EOF
7978
8079
public function generate(\$name, array \$parameters, \$absolute = false)
8180
{
82-
static \$routes = $routes;
81+
static \$routes = array(
82+
$routes
83+
);
8384
8485
if (!isset(\$routes[\$name])) {
8586
throw new \InvalidArgumentException(sprintf('Route "%s" does not exist.', \$name));
@@ -133,20 +134,4 @@ protected function endClass()
133134
134135
EOF;
135136
}
136-
137-
protected function exportParameters($parameters, $indent = 12)
138-
{
139-
$php = array();
140-
foreach ($parameters as $key => $value) {
141-
if (is_array($value)) {
142-
$value = $this->exportParameters($value, $indent + 4);
143-
} else {
144-
$value = var_export($value, true);
145-
}
146-
147-
$php[] = sprintf('%s%s => %s,', str_repeat(' ', $indent), var_export($key, true), $value);
148-
}
149-
150-
return sprintf("array(\n%s\n%s)", implode("\n", $php), str_repeat(' ', $indent - 4));
151-
}
152137
}

0 commit comments

Comments
 (0)
0