CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Team
    • Issues (Github)
    • YouTube Channel
    • Get Involved
    • Bakery
    • Featured Resources
    • Newsletter
    • Certification
    • My CakePHP
    • CakeFest
    • Facebook
    • Twitter
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.7 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.7
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Cake
    • Auth
      • Storage
    • Cache
      • Engine
    • Collection
      • Iterator
    • Command
    • Console
      • Exception
    • Controller
      • Component
      • Exception
    • Core
      • Configure
        • Engine
      • Exception
      • Retry
    • Database
      • Driver
      • Exception
      • Expression
      • Schema
      • Statement
      • Type
    • Datasource
      • Exception
    • Error
      • Middleware
    • Event
      • Decorator
    • Filesystem
    • Form
    • Http
      • Client
        • Adapter
        • Auth
      • Cookie
      • Exception
      • Middleware
      • Session
    • I18n
      • Formatter
      • Middleware
      • Parser
    • Log
      • Engine
    • Mailer
      • Exception
      • Transport
    • Network
      • Exception
    • ORM
      • Association
      • Behavior
        • Translate
      • Exception
      • Locator
      • Rule
    • Routing
      • Exception
      • Filter
      • Middleware
      • Route
    • Shell
      • Helper
      • Task
    • TestSuite
      • Fixture
      • Stub
    • Utility
      • Exception
    • Validation
    • View
      • Exception
      • Form
      • Helper
      • Widget
  • None

Classes

  • AssetsTask
  • CommandTask
  • ExtractTask
  • LoadTask
  • UnloadTask
  1: <?php
  2: /**
  3:  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4:  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  5:  *
  6:  * Licensed under The MIT License
  7:  * For full copyright and license information, please see the LICENSE.txt
  8:  * Redistributions of files must retain the above copyright notice.
  9:  *
 10:  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
 11:  * @link          https://cakephp.org CakePHP(tm) Project
 12:  * @since         3.0.0
 13:  * @license       https://opensource.org/licenses/mit-license.php MIT License
 14:  */
 15: namespace Cake\Shell\Task;
 16: 
 17: use Cake\Console\Shell;
 18: use Cake\Filesystem\File;
 19: 
 20: /**
 21:  * Task for unloading plugins.
 22:  */
 23: class UnloadTask extends Shell
 24: {
 25: 
 26:     /**
 27:      * Path to the bootstrap file.
 28:      *
 29:      * @var string
 30:      */
 31:     public $bootstrap;
 32: 
 33:     /**
 34:      * Execution method always used for tasks.
 35:      *
 36:      * @param string|null $plugin The plugin name.
 37:      * @return bool if action passed.
 38:      */
 39:     public function main($plugin = null)
 40:     {
 41:         $filename = 'bootstrap';
 42:         if ($this->params['cli']) {
 43:             $filename .= '_cli';
 44:         }
 45: 
 46:         $this->bootstrap = ROOT . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . $filename . '.php';
 47: 
 48:         if (!$plugin) {
 49:             $this->err('You must provide a plugin name in CamelCase format.');
 50:             $this->err('To unload an "Example" plugin, run `cake plugin unload Example`.');
 51: 
 52:             return false;
 53:         }
 54: 
 55:         $app = APP . 'Application.php';
 56:         if (file_exists($app) && !$this->param('no_app')) {
 57:             $this->modifyApplication($app, $plugin);
 58: 
 59:             return true;
 60:         }
 61: 
 62:         return (bool)$this->_modifyBootstrap($plugin);
 63:     }
 64: 
 65:     /**
 66:      * Update the applications bootstrap.php file.
 67:      *
 68:      * @param string $app Path to the application to update.
 69:      * @param string $plugin Name of plugin.
 70:      * @return bool If modify passed.
 71:      */
 72:     protected function modifyApplication($app, $plugin)
 73:     {
 74:         $finder = "@\\\$this\-\>addPlugin\(\s*'$plugin'(.|.\n|)+\);+@";
 75: 
 76:         $content = file_get_contents($app);
 77:         $newContent = preg_replace($finder, '', $content);
 78: 
 79:         if ($newContent === $content) {
 80:             return false;
 81:         }
 82: 
 83:         file_put_contents($app, $newContent);
 84: 
 85:         $this->out('');
 86:         $this->out(sprintf('%s modified', $app));
 87: 
 88:         return true;
 89:     }
 90: 
 91:     /**
 92:      * Update the applications bootstrap.php file.
 93:      *
 94:      * @param string $plugin Name of plugin.
 95:      * @return bool If modify passed.
 96:      */
 97:     protected function _modifyBootstrap($plugin)
 98:     {
 99:         $finder = "@\nPlugin::load\((.|.\n|\n\s\s|\n\t|)+'$plugin'(.|.\n|)+\);\n@";
100: 
101:         $bootstrap = new File($this->bootstrap, false);
102:         $content = $bootstrap->read();
103: 
104:         if (!preg_match("@\n\s*Plugin::loadAll@", $content)) {
105:             $newContent = preg_replace($finder, '', $content);
106: 
107:             if ($newContent === $content) {
108:                 return false;
109:             }
110: 
111:             $bootstrap->write($newContent);
112: 
113:             $this->out('');
114:             $this->out(sprintf('%s modified', $this->bootstrap));
115: 
116:             return true;
117:         }
118: 
119:         return false;
120:     }
121: 
122:     /**
123:      * GetOptionParser method.
124:      *
125:      * @return \Cake\Console\ConsoleOptionParser
126:      */
127:     public function getOptionParser()
128:     {
129:         $parser = parent::getOptionParser();
130: 
131:         $parser->addOption('cli', [
132:                 'help' => 'Use the bootstrap_cli file.',
133:                 'boolean' => true,
134:                 'default' => false,
135:             ])
136:             ->addOption('no_app', [
137:                 'help' => 'Do not update the Application if it exist. Forces config/bootstrap.php to be updated.',
138:                 'boolean' => true,
139:                 'default' => false,
140:             ])
141:             ->addArgument('plugin', [
142:                 'help' => 'Name of the plugin to load.',
143:             ]);
144: 
145:         return $parser;
146:     }
147: }
148: 
Follow @CakePHP
#IRC
OpenHub
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Logos & Trademarks
  • Community
  • Team
  • Issues (Github)
  • YouTube Channel
  • Get Involved
  • Bakery
  • Featured Resources
  • Newsletter
  • Certification
  • My CakePHP
  • CakeFest
  • Facebook
  • Twitter
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs