diff --git a/lib/Cake/Core/CakePlugin.php b/lib/Cake/Core/CakePlugin.php index 814f36b32..f82472bf2 100644 --- a/lib/Cake/Core/CakePlugin.php +++ b/lib/Cake/Core/CakePlugin.php @@ -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; + } + } diff --git a/lib/Cake/Test/Case/Core/CakePluginTest.php b/lib/Cake/Test/Case/Core/CakePluginTest.php index 893e6715a..417a20a0a 100644 --- a/lib/Cake/Test/Case/Core/CakePluginTest.php +++ b/lib/Cake/Test/Case/Core/CakePluginTest.php @@ -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 *