From 90a74f54dbf00e1fd1f3e4cd1dc3c8ad4488ad73 Mon Sep 17 00:00:00 2001 From: ondra Date: Mon, 25 Mar 2019 16:08:44 +0000 Subject: [PATCH 1/5] Use cakephp to load plugin --- src/Shell/Task/PluginTask.php | 36 +++++++++-------------------------- 1 file changed, 9 insertions(+), 27 deletions(-) diff --git a/src/Shell/Task/PluginTask.php b/src/Shell/Task/PluginTask.php index 8cde50354..05916d2b9 100644 --- a/src/Shell/Task/PluginTask.php +++ b/src/Shell/Task/PluginTask.php @@ -14,6 +14,7 @@ */ namespace Bake\Shell\Task; +use Cake\Console\ShellDispatcher; use Cake\Core\App; use Cake\Core\Configure; use Cake\Core\Plugin; @@ -28,13 +29,6 @@ */ class PluginTask extends BakeTask { - /** - * Path to the bootstrap file. Changed in tests. - * - * @var string - */ - public $bootstrap = null; - /** * Tasks this task uses. * @@ -59,7 +53,6 @@ class PluginTask extends BakeTask public function initialize() { $this->path = current(App::path('Plugin')); - $this->bootstrap = ROOT . DS . 'config' . DS . 'bootstrap.php'; } /** @@ -118,7 +111,7 @@ public function bake($plugin) $this->_generateFiles($plugin, $this->path); $hasAutoloader = $this->_modifyAutoloader($plugin, $this->path); - $this->_modifyBootstrap($plugin, $hasAutoloader); + $this->_modifyApplication($plugin, $hasAutoloader); $this->hr(); $this->out(sprintf('Created: %s in %s', $plugin, $this->path . $plugin), 2); @@ -130,32 +123,21 @@ public function bake($plugin) } /** - * Update the app's bootstrap.php file. + * Modify the application class * * @param string $plugin Name of plugin * @param bool $hasAutoloader Whether or not there is an autoloader configured for * the plugin * @return void */ - protected function _modifyBootstrap($plugin, $hasAutoloader) + protected function _modifyApplication($plugin, $hasAutoloader) { - $bootstrap = new File($this->bootstrap, false); - if (!$bootstrap->exists()) { - $this->err('Could not update application bootstrap.php file, as it could not be found.'); - - return; - } - $contents = $bootstrap->read(); - if (!preg_match("@\n\s*Plugin::loadAll@", $contents)) { - $autoload = $hasAutoloader ? null : "'autoload' => true, "; - $bootstrap->append(sprintf( - "\nPlugin::load('%s', [%s'bootstrap' => false, 'routes' => true]);\n", - $plugin, - $autoload - )); - $this->out(''); - $this->out(sprintf('%s modified', $this->bootstrap)); + $shell = new ShellDispatcher(); + $cmd = ['cake', 'plugin', 'load', $plugin]; + if ($hasAutoloader) { + $cmd[] = '--autoload'; } + $shell->run($cmd); } /** From c9fa9b763cf557d95f3ae9e0e9a6de93516b0ae6 Mon Sep 17 00:00:00 2001 From: ondra Date: Tue, 26 Mar 2019 07:55:49 +0000 Subject: [PATCH 2/5] Use cakephp to load plugin - test updated by original logic --- src/Shell/Task/PluginTask.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Shell/Task/PluginTask.php b/src/Shell/Task/PluginTask.php index 05916d2b9..710df6904 100644 --- a/src/Shell/Task/PluginTask.php +++ b/src/Shell/Task/PluginTask.php @@ -132,12 +132,18 @@ public function bake($plugin) */ protected function _modifyApplication($plugin, $hasAutoloader) { - $shell = new ShellDispatcher(); + $application = new File(ROOT . DS . 'src' . DS . 'Application.php', false); + if (!$application->exists()) { + $this->err('Could not update application Application.php file, as it could not be found.'); + + return; + } + $cmd = ['cake', 'plugin', 'load', $plugin]; if ($hasAutoloader) { $cmd[] = '--autoload'; } - $shell->run($cmd); + ShellDispatcher::run($cmd); } /** From 132a8d41fc1b74bccd6e713d50b6ef5e0f4f8838 Mon Sep 17 00:00:00 2001 From: ondra Date: Tue, 26 Mar 2019 09:46:28 +0000 Subject: [PATCH 3/5] Use cakephp to load plugin - autoload param deprecated fix --- src/Shell/Task/PluginTask.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Shell/Task/PluginTask.php b/src/Shell/Task/PluginTask.php index 710df6904..472180751 100644 --- a/src/Shell/Task/PluginTask.php +++ b/src/Shell/Task/PluginTask.php @@ -110,8 +110,8 @@ public function bake($plugin) $this->_generateFiles($plugin, $this->path); - $hasAutoloader = $this->_modifyAutoloader($plugin, $this->path); - $this->_modifyApplication($plugin, $hasAutoloader); + $this->_modifyAutoloader($plugin, $this->path); + $this->_modifyApplication($plugin); $this->hr(); $this->out(sprintf('Created: %s in %s', $plugin, $this->path . $plugin), 2); @@ -126,11 +126,10 @@ public function bake($plugin) * Modify the application class * * @param string $plugin Name of plugin - * @param bool $hasAutoloader Whether or not there is an autoloader configured for * the plugin * @return void */ - protected function _modifyApplication($plugin, $hasAutoloader) + protected function _modifyApplication($plugin) { $application = new File(ROOT . DS . 'src' . DS . 'Application.php', false); if (!$application->exists()) { @@ -140,9 +139,6 @@ protected function _modifyApplication($plugin, $hasAutoloader) } $cmd = ['cake', 'plugin', 'load', $plugin]; - if ($hasAutoloader) { - $cmd[] = '--autoload'; - } ShellDispatcher::run($cmd); } From 0c35b6dddcae0d1cf5df90499072fccd2e4a6fed Mon Sep 17 00:00:00 2001 From: ondra Date: Thu, 11 Apr 2019 14:19:02 +0100 Subject: [PATCH 4/5] Use cakephp to load plugin - shellDispatch() method --- src/Shell/Task/PluginTask.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Shell/Task/PluginTask.php b/src/Shell/Task/PluginTask.php index 472180751..51c4e6148 100644 --- a/src/Shell/Task/PluginTask.php +++ b/src/Shell/Task/PluginTask.php @@ -138,8 +138,7 @@ protected function _modifyApplication($plugin) return; } - $cmd = ['cake', 'plugin', 'load', $plugin]; - ShellDispatcher::run($cmd); + $this->dispatchShell('plugin', 'load', $plugin); } /** From b19fad657a19db3be8ecd41b0fa1e00b25fcdb51 Mon Sep 17 00:00:00 2001 From: ondra Date: Fri, 12 Apr 2019 08:50:31 +0100 Subject: [PATCH 5/5] Use cakephp to load plugin - remove use ShellDispatcher --- src/Shell/Task/PluginTask.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Shell/Task/PluginTask.php b/src/Shell/Task/PluginTask.php index 51c4e6148..b58a25e14 100644 --- a/src/Shell/Task/PluginTask.php +++ b/src/Shell/Task/PluginTask.php @@ -14,7 +14,6 @@ */ namespace Bake\Shell\Task; -use Cake\Console\ShellDispatcher; use Cake\Core\App; use Cake\Core\Configure; use Cake\Core\Plugin;