mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fixed bug where registering new packages would reset extra paths set for other packages. Closes #2666
This commit is contained in:
parent
150c9fc6a3
commit
13b748ad86
2 changed files with 40 additions and 15 deletions
|
@ -263,10 +263,13 @@ class App {
|
|||
*
|
||||
* `App::build(array('View/Helper' => array('/path/to/helpers/', '/another/path/'))); will setup multiple search paths for helpers`
|
||||
*
|
||||
* `App::build(array('Service' => array('%s' . 'Service' . DS)), App::REGISTER); will register new package 'Service'`
|
||||
*
|
||||
* If reset is set to true, all loaded plugins will be forgotten and they will be needed to be loaded again.
|
||||
*
|
||||
* @param array $paths associative array with package names as keys and a list of directories for new search paths
|
||||
* @param mixed $mode App::RESET will set paths, App::APPEND with append paths, App::PREPEND will prepend paths, [default] App::PREPEND
|
||||
* @param mixed $mode App::RESET will set paths, App::APPEND with append paths, App::PREPEND will prepend paths (default)
|
||||
* App::REGISTER will register new packages and their paths, %s in path will be replaced by APP path
|
||||
* @return void
|
||||
* @link http://book.cakephp.org/2.0/en/core-utility-libraries/app.html#App::build
|
||||
*/
|
||||
|
@ -289,24 +292,22 @@ class App {
|
|||
return;
|
||||
}
|
||||
|
||||
if (empty($paths)) {
|
||||
self::$_packageFormat = null;
|
||||
}
|
||||
|
||||
$packageFormat = self::_packageFormat();
|
||||
|
||||
if ($mode === App::REGISTER) {
|
||||
if (empty($paths)) {
|
||||
self::$_packageFormat = null;
|
||||
$packageFormat = self::_packageFormat();
|
||||
} else {
|
||||
foreach ($paths as $package => $formats) {
|
||||
if (!empty($packageFormat[$package])) {
|
||||
if (empty($packageFormat[$package])) {
|
||||
$packageFormat[$package] = $formats;
|
||||
} else {
|
||||
$formats = array_merge($packageFormat[$package], $formats);
|
||||
}
|
||||
|
||||
$packageFormat[$package] = array_values(array_unique($formats));
|
||||
}
|
||||
|
||||
self::$_packageFormat = $packageFormat;
|
||||
$paths = array();
|
||||
}
|
||||
self::$_packageFormat = $packageFormat;
|
||||
}
|
||||
|
||||
$defaults = array();
|
||||
|
@ -321,9 +322,15 @@ class App {
|
|||
return;
|
||||
}
|
||||
|
||||
if ($mode === App::REGISTER) {
|
||||
$paths = array();
|
||||
}
|
||||
|
||||
foreach ($defaults as $type => $default) {
|
||||
if (!empty(self::$_packages[$type])) {
|
||||
$path = self::$_packages[$type];
|
||||
} else {
|
||||
$path = $default;
|
||||
}
|
||||
|
||||
if (!empty($paths[$type])) {
|
||||
|
|
|
@ -191,6 +191,19 @@ class AppTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testBuildPackage() {
|
||||
$pluginPaths = array(
|
||||
'/foo/bar',
|
||||
APP . 'Plugin' . DS,
|
||||
dirname(dirname(CAKE)) . DS . 'plugins' . DS
|
||||
);
|
||||
App::build(array(
|
||||
'Plugin' => array(
|
||||
'/foo/bar'
|
||||
)
|
||||
));
|
||||
$result = App::path('Plugin');
|
||||
$this->assertEquals($pluginPaths, $result);
|
||||
|
||||
$paths = App::path('Service');
|
||||
$this->assertEquals(array(), $paths);
|
||||
|
||||
|
@ -203,11 +216,16 @@ class AppTest extends CakeTestCase {
|
|||
$expected = array(
|
||||
APP . 'Service' . DS,
|
||||
);
|
||||
|
||||
$result = App::path('Service');
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
App::build(array(), App::REGISTER);
|
||||
//Ensure new paths registered for other packages are not affected
|
||||
$result = App::path('Plugin');
|
||||
$this->assertEquals($pluginPaths, $result);
|
||||
|
||||
App::build();
|
||||
$paths = App::path('Service');
|
||||
$this->assertEquals(array(), $paths);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue