8000 feature #12022 [HttpKernel] Extract method to instantiate controller … · symfony/symfony@1104112 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1104112

Browse files
committed
feature #12022 [HttpKernel] Extract method to instantiate controller in ControllerResolver (danharper)
This PR was merged into the 2.6-dev branch. Discussion ---------- [HttpKernel] Extract method to instantiate controller in ControllerResolver Replaces #10814 to merge into `master` instead of `2.3`. --- | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Currently it's required to duplicate the entirety of the `getController()` and `createController()` methods just to replace the call to `new` (e.g. with container resolution, instead). Now it's possible to just override the `instantiateController()` method. Commits ------- 88274df [HttpKernel] Extract method to make callable controller in ControllerResolver
2 parents 11f0cb1 + 88274df commit 1104112

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/Symfony/Component/HttpKernel/Controller/ControllerResolver.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function getController(Request $request)
7171

7272
if (false === strpos($controller, ':')) {
7373
if (method_exists($controller, '__invoke')) {
74-
return new $controller();
74+
return $this->instantiateController($controller);
7575
} elseif (function_exists($controller)) {
7676
return $controller;
7777
}
@@ -153,6 +153,18 @@ protected function createController($controller)
153153
throw new \InvalidArgumentException(sprintf('Class "%s" does not exist.', $class));
154154
}
155155

156-
return array(new $class(), $method);
156+
return array($this->instantiateController($class), $method);
157+
}
158+
159+
/**
160+
* Returns an instantiated controller
161+
*
162+
* @param string $class A class name
163+
*
164+
* @return object
165+
*/
166+
protected function instantiateController($class)
167+
{
168+
return new $class();
157169
}
158170
}

0 commit comments

Comments
 (0)
0