Skip to content

Commit

Permalink
Reduce options for bootstrapping.
Browse files Browse the repository at this point in the history
Loading a conventions based file allows you to do all the things other
options would. Therefore the other options are redundant.
  • Loading branch information
markstory committed Sep 10, 2013
1 parent 5ce87df commit caa6b8d
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 55 deletions.
26 changes: 1 addition & 25 deletions lib/Cake/Core/Plugin.php
Expand Up @@ -62,14 +62,6 @@ class Plugin {
*
* Will load routes.php file but not bootstrap.php
*
* `Plugin::load('DebugKit', ['bootstrap' => ['config1', 'config2']])
*
* Will load config1.php and config2.php files
*
* `Plugin::load('DebugKit', ['bootstrap' => '\DebugKit\SomeClass::bootstrap'])`
*
* Will run the \DebugKit\SomeClass::bootstrap() function to initialize it
*
* `Plugin::load('DebugKit', ['namespace' => 'Cake\DebugKit'])`
*
* Will load files on APP/Plugin/Cake/DebugKit/...
Expand Down Expand Up @@ -99,8 +91,7 @@ class Plugin {
*
* ## Configuration options
*
* - `bootstrap` - array|boolean - Whether or not you want the $plugin/Config/bootstrap.php file loaded.
* Can also be an array of files to load from $plugin/Config.
* - `bootstrap` - array - Whether or not you want the $plugin/Config/bootstrap.php file loaded.
* - `routes` - boolean - Whether or not you want to load the $plugin/Config/routes.php file.
* - `namespace` - string - A custom namespace for the plugin. It will default to the plugin name.
* - `ignoreMissing` - boolean - Set to true to ignore missing bootstrap/routes files.
Expand Down Expand Up @@ -215,28 +206,13 @@ public static function bootstrap($plugin) {
if ($config['bootstrap'] === false) {
return false;
}
if (is_callable($config['bootstrap'])) {
$cb = $config['bootstrap'];
return $cb($plugin, $config);
}

$path = static::path($plugin);
if ($config['bootstrap'] === true) {
return static::_includeFile(
$path . 'Config/bootstrap.php',
$config['ignoreMissing']
);
}

$bootstrap = (array)$config['bootstrap'];
foreach ($bootstrap as $file) {
static::_includeFile(
$path . 'Config' . DS . $file . '.php',
$config['ignoreMissing']
);
}

return true;
}

/**
Expand Down
30 changes: 0 additions & 30 deletions lib/Cake/Test/TestCase/Core/PluginTest.php
Expand Up @@ -161,28 +161,6 @@ public function testLoadMultipleWithDefaultsAndOverride() {
$this->assertEquals(null, Configure::read('PluginTest.test_plugin_two.bootstrap'));
}

/**
* Tests that it is possible to load multiple bootstrap files at once
*
* @return void
*/
public function testMultipleBootstrapFiles() {
Plugin::load('TestPlugin', array('bootstrap' => array('bootstrap', 'custom_config')));
$this->assertTrue(Plugin::loaded('TestPlugin'));
$this->assertEquals('loaded plugin bootstrap', Configure::read('PluginTest.test_plugin.bootstrap'));
}

/**
* Tests that it is possible to load plugin bootstrap by calling a callback function
*
* @return void
*/
public function testCallbackBootstrap() {
Plugin::load('TestPlugin', array('bootstrap' => array($this, 'pluginBootstrap')));
$this->assertTrue(Plugin::loaded('TestPlugin'));
$this->assertEquals('called plugin bootstrap callback', Configure::read('PluginTest.test_plugin.bootstrap'));
}

/**
* Tests that loading a missing routes file throws a warning
*
Expand Down Expand Up @@ -289,12 +267,4 @@ public function testLoadAllWithDefaultsAndOverride() {
$this->assertEquals('loaded plugin two bootstrap', Configure::read('PluginTest.test_plugin_two.bootstrap'));
}

/**
* Auxiliary function to test plugin bootstrap callbacks
*
* @return void
*/
public function pluginBootstrap() {
Configure::write('PluginTest.test_plugin.bootstrap', 'called plugin bootstrap callback');
}
}

0 comments on commit caa6b8d

Please sign in to comment.