|
35 | 35 | */ |
36 | 36 | class Zend_Controller_Dispatcher_Standard extends Zend_Controller_Dispatcher_Abstract |
37 | 37 | { |
| 38 | + /** |
| 39 | + * @var Closure|null |
| 40 | + */ |
| 41 | + private static $_instanceCreatorCallback; |
| 42 | + |
38 | 43 | /** |
39 | 44 | * Current dispatchable directory |
40 | 45 | * @var string |
@@ -65,6 +70,11 @@ public function __construct(array $params = []) |
65 | 70 | $this->_curModule = $this->getDefaultModule(); |
66 | 71 | } |
67 | 72 |
|
| 73 | + public static function setInstanceCreatorCallback(?Closure $instanceCreatorCallback): void |
| 74 | + { |
| 75 | + self::$_instanceCreatorCallback = $instanceCreatorCallback; |
| 76 | + } |
| 77 | + |
68 | 78 | /** |
69 | 79 | * Add a single path to the controller directory stack |
70 | 80 | * |
@@ -278,7 +288,7 @@ public function dispatch(Zend_Controller_Request_Abstract $request, Zend_Control |
278 | 288 | * Instantiate controller with request, response, and invocation |
279 | 289 | * arguments; throw exception if it's not an action controller |
280 | 290 | */ |
281 | | - $controller = new $moduleClassName($request, $this->getResponse(), $this->getParams()); |
| 291 | + $controller = $this->_createControllerInstance($moduleClassName, $request); |
282 | 292 | if (!($controller instanceof Zend_Controller_Action_Interface) && |
283 | 293 | !($controller instanceof Zend_Controller_Action)) { |
284 | 294 | require_once 'Zend/Controller/Dispatcher/Exception.php'; |
@@ -509,4 +519,24 @@ public function getActionMethod(Zend_Controller_Request_Abstract $request) |
509 | 519 |
|
510 | 520 | return $this->formatActionName($action); |
511 | 521 | } |
| 522 | + |
| 523 | + /** |
| 524 | + * @param string $moduleClassName |
| 525 | + * @param Zend_Controller_Request_Abstract $request |
| 526 | + * @return mixed |
| 527 | + */ |
| 528 | + private function _createControllerInstance($moduleClassName, Zend_Controller_Request_Abstract $request) |
| 529 | + { |
| 530 | + if (self::$_instanceCreatorCallback) { |
| 531 | + return call_user_func( |
| 532 | + self::$_instanceCreatorCallback, |
| 533 | + $moduleClassName, |
| 534 | + $request, |
| 535 | + $this->getResponse(), |
| 536 | + $this->getParams() |
| 537 | + ); |
| 538 | + } |
| 539 | + |
| 540 | + return new $moduleClassName($request, $this->getResponse(), $this->getParams()); |
| 541 | + } |
512 | 542 | } |
0 commit comments