Permalink
Browse files

Added feature to ignore include errors for CakePlugin

  • Loading branch information...
ADmad committed Jan 8, 2013
1 parent 0b43a5c commit 970fdca89d81da84cfb0aade5566c34a0a584640
Showing with 41 additions and 4 deletions.
  1. +27 −4 lib/Cake/Core/CakePlugin.php
  2. +14 −0 lib/Cake/Test/Case/Core/CakePluginTest.php
@@ -74,7 +74,7 @@ public static function load($plugin, $config = array()) {
}
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 @@ public static function bootstrap($plugin) {
$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 @@ public static function routes($plugin = null) {
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 @@ public static function unload($plugin = null) {
}
}
/**
* 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;
}
}
@@ -179,6 +179,20 @@ public function testLoadMultipleWithDefaultsMissingFile() {
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
*

0 comments on commit 970fdca

Please sign in to comment.