Skip to content

Commit 46fb6d2

Browse files
committed
Merge branch '2.1'
* 2.1: [Console] Add support for parsing terminal width/height on localized windows, fixes #5742 [Form] Fixed treatment of countables and traversables in Form::isEmpty() refactor ControllerNameParser [Form] Fixed FileType not to throw an exception when bound empty - Test undefined index # Maintain array structure Check if key # is defined in $value Update src/Symfony/Component/Validator/Resources/translations/validators.pl.xlf
2 parents 0b34753 + 6bdbc95 commit 46fb6d2

File tree

1 file changed

+14
-26
lines changed

1 file changed

+14
-26
lines changed

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
}
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)