8000 merged branch Tobion/controllernameparser (PR #6297) · symfony/symfony@6e499a3 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 6e499a3

Browse files
committed
merged branch Tobion/controllernameparser (PR #6297)
This PR was submitted for the master branch but it was merged into the 2.1 branch instead (closes #6297). Commits ------- 444fea4 [FrameworkBundle] refactor ControllerNameParser Discussion ---------- [FrameworkBundle] refactor ControllerNameParser bc break: no --------------------------------------------------------------------------- by Tobion at 2012-12-12T16:38:12Z Maybe merge into 2.1 instead? So master and 2.1 do not drift apart by pure refactorings? It also includes a phpdoc fix.
2 parents a6930a3 + 35e19c7 commit 6e499a3

File tree

1 file changed

+14
-26
lines changed

1 file changed

+14
-26
lines changed

src/Symfony/Bundle/FrameworkBundle/Controller/ControllerNameParser.php

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ public function __construct(KernelInterface $kernel)
3838
* Converts a short notation a:b:c to a class::method.
3939
*
4040
* @param string $controller A short notation controller (a:b:c)
41+
*
42+
* @return string A string with class::method
43+
*
44+
* @throws \InvalidArgumentException when the specified bundle is not enabled
45+
* or the controller cannot be found
4146
*/
4247
public function parse($controller)
4348
{
@@ -47,39 +52,22 @@ public function parse($controller)
4752

4853
list($bundle, $controller, $action) = $parts;
4954
$controller = str_replace('/', '\\', $controller);
50-
$class = null;
51-
$logs = array();
55+
$bundles = array();
56+
57+
// this throws an exception if there is no such bundle
5258
foreach ($this->kernel->getBundle($bundle, false) as $b) {
5359
$try = $b->getNamespace().'\\Controller\\'.$controller.'Controller';
54-
if (!class_exists($try)) {
55-
$logs[] = sprintf('Unable to find controller "%s:%s" - class "%s" does not exist.', $bundle, $controller, $try);
56-
} else {
57-
$class = $try;
58-
59-
break;
60+
if (class_exists($try)) {
61+
return $try.'::'.$action.'Action';
6062
}
< E276 /code>
61-
}
6263

63-
if (null === $class) {
64-
$this->handleControllerNotFoundException($bundle, $controller, $logs);
64+
$bundles[] = $b->getName();
65+
$msg = sprintf('Unable to find controller "%s:%s" - class "%s" does not exist.', $bundle, $controller, $try);
6566
}
6667

67-
return $class.'::'.$action.'Action';
68-
}
69-
70-
private function handleControllerNotFoundException($bundle, $controller, array $logs)
71-
{
72-
// just one log, return it as the exception
73-
if (1 == count($logs)) {
74-
throw new \InvalidArgumentException($logs[0]);
75-
}
76-
77-
// many logs, use a message that mentions each searched bundle
78-
$names = array();
79-
foreach ($this->kernel->getBundle($bundle, false) as $b) {
80-
$names[] = $b->getName();
68+
if (count($bundles) > 1) {
69+
$msg = sprintf('Unable to find controller "%s:%s" in bundles %s.', $bundle, $controller, implode(', ', $bundles));
8170
}
82-
$msg = sprintf('Unable to find controller "%s:%s" in bundles %s.', $bundle, $controller, implode(', ', $names));
8371

8472
throw new \InvalidArgumentException($msg);
8573
}

0 commit comments

Comments
 (0)
0