mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fix loading ShellHelpers from plugins
Previously the Shell::helper() function would call a `class_exists` on a variable that contained the `Plugin.ClassName` notation which will always result be false, e.g. `class_exists('YourPlugin.TestShellHelper')` will always be false. Loading ShellHelpers from a plugin will never work because of this. (This notation is described in the ShellHelper 2.x documentation). After the pluginSplit and the loading of the actual ShellHelper class file (through `App::uses`), the `class_exists` should be called on the real class name, not on `Plugin.ClassName`. Through this fix, plugins with an ExampleShellHelper in placed in MyPlugin/Console/Helper/ExampleShellHelper.php can be called in Shells by `$this->helper('MyPlugin.ExampleShellHelper')` and plugins within your app can still be loaded through the regular `$this->helper('MyShellHelper')`.
This commit is contained in:
parent
ec8022baf5
commit
64700e9a08
1 changed files with 4 additions and 4 deletions
|
@ -806,12 +806,12 @@ class Shell extends CakeObject {
|
||||||
return $this->_helpers[$name];
|
return $this->_helpers[$name];
|
||||||
}
|
}
|
||||||
list($plugin, $helperClassName) = pluginSplit($name, true);
|
list($plugin, $helperClassName) = pluginSplit($name, true);
|
||||||
$helperClassName = Inflector::camelize($name) . "ShellHelper";
|
$helperClassNameShellHelper = Inflector::camelize($helperClassName) . "ShellHelper";
|
||||||
App::uses($helperClassName, $plugin . "Console/Helper");
|
App::uses($helperClassNameShellHelper, $plugin . "Console/Helper");
|
||||||
if (!class_exists($helperClassName)) {
|
if (!class_exists($helperClassNameShellHelper)) {
|
||||||
throw new RuntimeException("Class " . $helperClassName . " not found");
|
throw new RuntimeException("Class " . $helperClassName . " not found");
|
||||||
}
|
}
|
||||||
$helper = new $helperClassName($this->stdout);
|
$helper = new $helperClassNameShellHelper($this->stdout);
|
||||||
$this->_helpers[$name] = $helper;
|
$this->_helpers[$name] = $helper;
|
||||||
return $helper;
|
return $helper;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue