Browse Source

Allow loading and unloading plugins for bootstrap_cli

dereuromark 9 years ago
parent
commit
35d6df54bd
2 changed files with 29 additions and 9 deletions
  1. 13 3
      src/Shell/Task/LoadTask.php
  2. 16 6
      src/Shell/Task/UnloadTask.php

+ 13 - 3
src/Shell/Task/LoadTask.php

@@ -38,9 +38,14 @@ class LoadTask extends Shell
      */
     public function main($plugin = null)
     {
-        $this->bootstrap = ROOT . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'bootstrap.php';
+        $filename = 'bootstrap';
+        if ($this->params['cli']) {
+            $filename .= '_cli';
+        }
+
+        $this->bootstrap = ROOT . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . $filename . '.php';
 
-        if (empty($plugin)) {
+        if (!$plugin) {
             $this->err('You must provide a plugin name in CamelCase format.');
             $this->err('To load an "Example" plugin, run `cake plugin load Example`.');
 
@@ -109,11 +114,16 @@ class LoadTask extends Shell
                     'default' => false,
                 ])
                 ->addOption('autoload', [
-                    'help' => 'Will autoload the plugin using CakePHP. ' .
+                    'help' => 'Will autoload the plugin using CakePHP.' .
                         'Set to true if you are not using composer to autoload your plugin.',
                     'boolean' => true,
                     'default' => false,
                 ])
+                ->addOption('cli', [
+                    'help' => 'Use the bootstrap_cli file.',
+                    'boolean' => true,
+                    'default' => false,
+                ])
                 ->addArgument('plugin', [
                     'help' => 'Name of the plugin to load.',
                 ]);

+ 16 - 6
src/Shell/Task/UnloadTask.php

@@ -38,9 +38,14 @@ class UnloadTask extends Shell
      */
     public function main($plugin = null)
     {
-        $this->bootstrap = ROOT . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'bootstrap.php';
+        $filename = 'bootstrap';
+        if ($this->params['cli']) {
+            $filename .= '_cli';
+        }
+
+        $this->bootstrap = ROOT . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . $filename . '.php';
 
-        if (empty($plugin)) {
+        if (!$plugin) {
             $this->err('You must provide a plugin name in CamelCase format.');
             $this->err('To unload an "Example" plugin, run `cake plugin unload Example`.');
 
@@ -58,7 +63,7 @@ class UnloadTask extends Shell
      */
     protected function _modifyBootstrap($plugin)
     {
-        $finder = "/\nPlugin::load\((.|.\n|\n\s\s|\n\t|)+'$plugin'(.|.\n|)+\);\n/";
+        $finder = "@\nPlugin::load\((.|.\n|\n\s\s|\n\t|)+'$plugin'(.|.\n|)+\);\n@";
 
         $bootstrap = new File($this->bootstrap, false);
         $contents = $bootstrap->read();
@@ -86,9 +91,14 @@ class UnloadTask extends Shell
     {
         $parser = parent::getOptionParser();
 
-        $parser->addArgument('plugin', [
-            'help' => 'Name of the plugin to load.',
-        ]);
+        $parser->addOption('cli', [
+                'help' => 'Use the bootstrap_cli file.',
+                'boolean' => true,
+                'default' => false,
+            ])
+            ->addArgument('plugin', [
+                'help' => 'Name of the plugin to load.',
+            ]);
 
         return $parser;
     }