Merge pull request #1063 from ADmad/2.3-cakeplugin

Added feature to ignore include errors for CakePlugin
This commit is contained in:
José Lorenzo Rodríguez 2013-01-11 15:13:54 -08:00
commit d571b056f4
2 changed files with 41 additions and 4 deletions

View file

@ -74,7 +74,7 @@ class CakePlugin {
}
return;
}
$config += array('bootstrap' => false, 'routes' => false);
$config += array('bootstrap' => false, 'routes' => false, 'ignoreMissing' => false);
if (empty($config['path'])) {
foreach (App::path('plugins') as $path) {
if (is_dir($path . $plugin)) {
@ -162,12 +162,18 @@ class CakePlugin {
$path = self::path($plugin);
if ($config['bootstrap'] === true) {
return include $path . 'Config' . DS . 'bootstrap.php';
return self::_includeFile(
$path . 'Config' . DS . 'bootstrap.php',
$config['ignoreMissing']
);
}
$bootstrap = (array)$config['bootstrap'];
foreach ($bootstrap as $file) {
include $path . 'Config' . DS . $file . '.php';
self::_includeFile(
$path . 'Config' . DS . $file . '.php',
$config['ignoreMissing']
);
}
return true;
@ -191,7 +197,10 @@ class CakePlugin {
if ($config['routes'] === false) {
return false;
}
return (bool)include self::path($plugin) . 'Config' . DS . 'routes.php';
return (bool)self::_includeFile(
self::path($plugin) . 'Config' . DS . 'routes.php',
$config['ignoreMissing']
);
}
/**
@ -225,4 +234,18 @@ class CakePlugin {
}
}
/**
* Include file, ignoring include error if needed if file is missing
*
* @param string $file File to include
* @param boolean $ignoreMissing Whether to ignore include error for missing files
* @return mixed
*/
protected static function _includeFile($file, $ignoreMissing = false) {
if ($ignoreMissing && !is_file($file)) {
return false;
}
return include $file;
}
}

View file

@ -179,6 +179,20 @@ class CakePluginTest extends CakeTestCase {
CakePlugin::routes();
}
/**
* Test ignoring missing bootstrap/routes file
*
* @return void
*/
public function testIgnoreMissingFiles() {
CakePlugin::loadAll(array(array(
'bootstrap' => true,
'routes' => true,
'ignoreMissing' => true
)));
CakePlugin::routes();
}
/**
* Tests that CakePlugin::load() throws an exception on unknown plugin
*