Skip to content

Commit 243673c

Browse files
committed
[TASK] Put composer patches to vcs in this fork repository
1 parent 04d7d79 commit 243673c

3 files changed

Lines changed: 71 additions & 3 deletions

File tree

library/Zend/Controller/Action/HelperBroker.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ class Zend_Controller_Action_HelperBroker
4646
*/
4747
protected $_actionController;
4848

49+
/**
50+
* @var Closure|null
51+
*/
52+
protected static $_instanceCreatorCallback;
53+
4954
/**
5055
* @var Zend_Loader_PluginLoader_Interface
5156
*/
@@ -58,6 +63,11 @@ class Zend_Controller_Action_HelperBroker
5863
*/
5964
protected static $_stack = null;
6065

66+
public static function setInstanceCreatorCallback(?Closure $instanceCreatorCallback): void
67+
{
68+
self::$_instanceCreatorCallback = $instanceCreatorCallback;
69+
}
70+
6171
/**
6272
* Set PluginLoader for use with broker
6373
*
@@ -369,7 +379,7 @@ protected static function _loadHelper($name)
369379
throw new Zend_Controller_Action_Exception('Action Helper by name ' . $name . ' not found', 0, $e);
370380
}
371381

372-
$helper = new $class();
382+
$helper = self::_createHelperInstance($class);
373383

374384
if (!$helper instanceof Zend_Controller_Action_Helper_Abstract) {
375385
require_once 'Zend/Controller/Action/Exception.php';
@@ -378,4 +388,13 @@ protected static function _loadHelper($name)
378388

379389
self::getStack()->push($helper);
380390
}
391+
392+
protected static function _createHelperInstance($className)
393+
{
394+
if (self::$_instanceCreatorCallback) {
395+
return call_user_func(self::$_instanceCreatorCallback, $className);
396+
}
397+
398+
return new $className();
399+
}
381400
}

library/Zend/Controller/Dispatcher/Standard.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@
3535
*/
3636
class Zend_Controller_Dispatcher_Standard extends Zend_Controller_Dispatcher_Abstract
3737
{
38+
/**
39+
* @var Closure|null
40+
*/
41+
private static $_instanceCreatorCallback;
42+
3843
/**
3944
* Current dispatchable directory
4045
* @var string
@@ -65,6 +70,11 @@ public function __construct(array $params = [])
6570
$this->_curModule = $this->getDefaultModule();
6671
}
6772

73+
public static function setInstanceCreatorCallback(?Closure $instanceCreatorCallback): void
74+
{
75+
self::$_instanceCreatorCallback = $instanceCreatorCallback;
76+
}
77+
6878
/**
6979
* Add a single path to the controller directory stack
7080
*
@@ -278,7 +288,7 @@ public function dispatch(Zend_Controller_Request_Abstract $request, Zend_Control
278288
* Instantiate controller with request, response, and invocation
279289
* arguments; throw exception if it's not an action controller
280290
*/
281-
$controller = new $moduleClassName($request, $this->getResponse(), $this->getParams());
291+
$controller = $this->_createControllerInstance($moduleClassName, $request);
282292
if (!($controller instanceof Zend_Controller_Action_Interface) &&
283293
!($controller instanceof Zend_Controller_Action)) {
284294
require_once 'Zend/Controller/Dispatcher/Exception.php';
@@ -509,4 +519,24 @@ public function getActionMethod(Zend_Controller_Request_Abstract $request)
509519

510520
return $this->formatActionName($action);
511521
}
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+
}
512542
}

library/Zend/View/Abstract.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838
*/
3939
abstract class Zend_View_Abstract implements Zend_View_Interface
4040
{
41+
/**
42+
* @var Closure|null
43+
*/
44+
private static $_instanceCreatorCallback;
45+
4146
/**
4247
* Path stack for script, helper, and filter directories.
4348
*
@@ -239,6 +244,11 @@ public function __construct($config = [])
239244
$this->init();
240245
}
241246

247+
public static function setInstanceCreatorCallback(?Closure $param): void
248+
{
249+
self::$_instanceCreatorCallback = $param;
250+
}
251+
242252
/**
243253
* Return the template engine object
244254
*
@@ -1178,7 +1188,7 @@ private function _getPlugin($type, $name)
11781188

11791189
if (!isset($store[$name])) {
11801190
$class = $this->getPluginLoader($type)->load($name);
1181-
$store[$name] = new $class();
1191+
$store[$name] = $this->_getPluginInstance($class);
11821192
if (method_exists($store[$name], 'setView')) {
11831193
$store[$name]->setView($this);
11841194
}
@@ -1188,6 +1198,15 @@ private function _getPlugin($type, $name)
11881198
return $store[$name];
11891199
}
11901200

1201+
private function _getPluginInstance(string $class)
1202+
{
1203+
if (self::$_instanceCreatorCallback) {
1204+
return call_user_func(self::$_instanceCreatorCallback, $class);
1205+
}
1206+
1207+
return new $class();
1208+
}
1209+
11911210
/**
11921211
* Use to include the view script in a scope that only allows public
11931212
* members.

0 commit comments

Comments
 (0)