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 loading plugins.
 22:  */
 23: class LoadTask 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
 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 load an "Example" plugin, run `cake plugin load Example`.');
 50: 
 51:             return false;
 52:         }
 53: 
 54:         $options = $this->makeOptions();
 55: 
 56:         $app = APP . 'Application.php';
 57:         if (file_exists($app) && !$this->param('no_app')) {
 58:             $this->modifyApplication($app, $plugin, $options);
 59: 
 60:             return true;
 61:         }
 62: 
 63:         return $this->_modifyBootstrap($plugin, $options);
 64:     }
 65: 
 66:     /**
 67:      * Create options string for the load call.
 68:      *
 69:      * @return string
 70:      */
 71:     protected function makeOptions()
 72:     {
 73:         $autoloadString = $this->param('autoload') ? "'autoload' => true" : '';
 74:         $bootstrapString = $this->param('bootstrap') ? "'bootstrap' => true" : '';
 75:         $routesString = $this->param('routes') ? "'routes' => true" : '';
 76: 
 77:         return implode(', ', array_filter([$autoloadString, $bootstrapString, $routesString]));
 78:     }
 79: 
 80:     /**
 81:      * Modify the application class
 82:      *
 83:      * @param string $app The Application file to modify.
 84:      * @param string $plugin The plugin name to add.
 85:      * @param string $options The plugin options to add
 86:      * @return void
 87:      */
 88:     protected function modifyApplication($app, $plugin, $options)
 89:     {
 90:         $file = new File($app, false);
 91:         $contents = $file->read();
 92: 
 93:         $append = "\n        \$this->addPlugin('%s', [%s]);\n";
 94:         $insert = str_replace(', []', '', sprintf($append, $plugin, $options));
 95: 
 96:         if (!preg_match('/function bootstrap\(\)/m', $contents)) {
 97:             $this->abort('Your Application class does not have a bootstrap() method. Please add one.');
 98:         } else {
 99:             $contents = preg_replace('/(function bootstrap\(\)(?:\s+)\{)/m', '$1' . $insert, $contents);
100:         }
101:         $file->write($contents);
102: 
103:         $this->out('');
104:         $this->out(sprintf('%s modified', $app));
105:     }
106: 
107:     /**
108:      * Update the applications bootstrap.php file.
109:      *
110:      * @param string $plugin Name of plugin.
111:      * @param string $options The options string
112:      * @return bool If modify passed.
113:      */
114:     protected function _modifyBootstrap($plugin, $options)
115:     {
116:         $bootstrap = new File($this->bootstrap, false);
117:         $contents = $bootstrap->read();
118:         if (!preg_match("@\n\s*Plugin::loadAll@", $contents)) {
119:             $append = "\nPlugin::load('%s', [%s]);\n";
120: 
121:             $bootstrap->append(str_replace(', []', '', sprintf($append, $plugin, $options)));
122:             $this->out('');
123:             $this->out(sprintf('%s modified', $this->bootstrap));
124: 
125:             return true;
126:         }
127: 
128:         return false;
129:     }
130: 
131:     /**
132:      * GetOptionParser method.
133:      *
134:      * @return \Cake\Console\ConsoleOptionParser
135:      */
136:     public function getOptionParser()
137:     {
138:         $parser = parent::getOptionParser();
139: 
140:         $parser->addOption('bootstrap', [
141:                     'short' => 'b',
142:                     'help' => 'Will load bootstrap.php from plugin.',
143:                     'boolean' => true,
144:                     'default' => false,
145:                 ])
146:                 ->addOption('routes', [
147:                     'short' => 'r',
148:                     'help' => 'Will load routes.php from plugin.',
149:                     'boolean' => true,
150:                     'default' => false,
151:                 ])
152:                 ->addOption('autoload', [
153:                     'help' => 'Will autoload the plugin using CakePHP.' .
154:                         'Set to true if you are not using composer to autoload your plugin.',
155:                     'boolean' => true,
156:                     'default' => false,
157:                 ])
158:                 ->addOption('cli', [
159:                     'help' => 'Use the bootstrap_cli file.',
160:                     'boolean' => true,
161:                     'default' => false,
162:                 ])
163:                 ->addOption('no_app', [
164:                     'help' => 'Do not update the Application if it exist. Forces config/bootstrap.php to be updated.',
165:                     'boolean' => true,
166:                     'default' => false,
167:                 ])
168:                 ->addArgument('plugin', [
169:                     'help' => 'Name of the plugin to load.',
170:                 ]);
171: 
172:         return $parser;
173:     }
174: }
175: 
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