mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Merge pull request #1063 from ADmad/2.3-cakeplugin
Added feature to ignore include errors for CakePlugin
This commit is contained in:
commit
d571b056f4
2 changed files with 41 additions and 4 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue