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.8 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.8
      • 3.8
      • 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:      * Path to the bootstrap file.
 27:      *
 28:      * @var string
 29:      */
 30:     public $bootstrap;
 31: 
 32:     /**
 33:      * Execution method always used for tasks.
 34:      *
 35:      * @param string|null $plugin The plugin name.
 36:      * @return bool if action passed.
 37:      */
 38:     public function main($plugin = null)
 39:     {
 40:         $filename = 'bootstrap';
 41:         if ($this->params['cli']) {
 42:             $filename .= '_cli';
 43:         }
 44: 
 45:         $this->bootstrap = ROOT . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . $filename . '.php';
 46: 
 47:         if (!$plugin) {
 48:             $this->err('You must provide a plugin name in CamelCase format.');
 49:             $this->err('To unload an "Example" plugin, run `cake plugin unload Example`.');
 50: 
 51:             return false;
 52:         }
 53: 
 54:         $app = APP . 'Application.php';
 55:         if (file_exists($app) && !$this->param('no_app')) {
 56:             $this->modifyApplication($app, $plugin);
 57: 
 58:             return true;
 59:         }
 60: 
 61:         return (bool)$this->_modifyBootstrap($plugin);
 62:     }
 63: 
 64:     /**
 65:      * Update the applications bootstrap.php file.
 66:      *
 67:      * @param string $app Path to the application to update.
 68:      * @param string $plugin Name of plugin.
 69:      * @return bool If modify passed.
 70:      */
 71:     protected function modifyApplication($app, $plugin)
 72:     {
 73:         $finder = "@\\\$this\-\>addPlugin\(\s*'$plugin'(.|.\n|)+\);+@";
 74: 
 75:         $content = file_get_contents($app);
 76:         $newContent = preg_replace($finder, '', $content);
 77: 
 78:         if ($newContent === $content) {
 79:             return false;
 80:         }
 81: 
 82:         file_put_contents($app, $newContent);
 83: 
 84:         $this->out('');
 85:         $this->out(sprintf('%s modified', $app));
 86: 
 87:         return true;
 88:     }
 89: 
 90:     /**
 91:      * Update the applications bootstrap.php file.
 92:      *
 93:      * @param string $plugin Name of plugin.
 94:      * @return bool If modify passed.
 95:      */
 96:     protected function _modifyBootstrap($plugin)
 97:     {
 98:         $finder = "@\nPlugin::load\((.|.\n|\n\s\s|\n\t|)+'$plugin'(.|.\n|)+\);\n@";
 99: 
100:         $bootstrap = new File($this->bootstrap, false);
101:         $content = $bootstrap->read();
102: 
103:         if (!preg_match("@\n\s*Plugin::loadAll@", $content)) {
104:             $newContent = preg_replace($finder, '', $content);
105: 
106:             if ($newContent === $content) {
107:                 return false;
108:             }
109: 
110:             $bootstrap->write($newContent);
111: 
112:             $this->out('');
113:             $this->out(sprintf('%s modified', $this->bootstrap));
114: 
115:             return true;
116:         }
117: 
118:         return false;
119:     }
120: 
121:     /**
122:      * GetOptionParser method.
123:      *
124:      * @return \Cake\Console\ConsoleOptionParser
125:      */
126:     public function getOptionParser()
127:     {
128:         $parser = parent::getOptionParser();
129: 
130:         $parser->addOption('cli', [
131:                 'help' => 'Use the bootstrap_cli file.',
132:                 'boolean' => true,
133:                 'default' => false,
134:             ])
135:             ->addOption('no_app', [
136:                 'help' => 'Do not update the Application if it exist. Forces config/bootstrap.php to be updated.',
137:                 'boolean' => true,
138:                 'default' => false,
139:             ])
140:             ->addArgument('plugin', [
141:                 'help' => 'Name of the plugin to load.',
142:             ]);
143: 
144:         return $parser;
145:     }
146: }
147: 
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