mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Proposal. Adding new package using App::build().
For instance, adding new 'Service' package to app search paths.
This commit is contained in:
parent
fcd96bcc60
commit
f861cc6e09
2 changed files with 50 additions and 0 deletions
|
@ -76,6 +76,13 @@ class App {
|
|||
*/
|
||||
const PREPEND = 'prepend';
|
||||
|
||||
/**
|
||||
* Register package
|
||||
*
|
||||
* @constant REGISTER
|
||||
*/
|
||||
const REGISTER = 'register';
|
||||
|
||||
/**
|
||||
* Reset paths instead of merging
|
||||
*
|
||||
|
@ -281,6 +288,24 @@ class App {
|
|||
|
||||
$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])) {
|
||||
$formats = array_merge($packageFormat[$package], $formats);
|
||||
}
|
||||
|
||||
$packageFormat[$package] = array_values(array_unique($formats));
|
||||
}
|
||||
|
||||
self::$_packageFormat = $packageFormat;
|
||||
$paths = array();
|
||||
}
|
||||
}
|
||||
|
||||
$defaults = array();
|
||||
foreach ($packageFormat as $package => $format) {
|
||||
foreach ($format as $f) {
|
||||
|
|
|
@ -200,6 +200,31 @@ class AppTest extends CakeTestCase {
|
|||
$this->assertEqual($old, $defaults);
|
||||
}
|
||||
|
||||
/**
|
||||
* test package build() with App::REGISTER.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testBuildPackage() {
|
||||
$paths = App::path('Service');
|
||||
$this->assertEqual(array(), $paths);
|
||||
|
||||
App::build(array(
|
||||
'Service' => array(
|
||||
'%s' . 'Service' . DS,
|
||||
),
|
||||
), App::REGISTER);
|
||||
|
||||
$expected = array(
|
||||
APP . 'Service' . DS,
|
||||
);
|
||||
|
||||
$result = App::path('Service');
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
App::build(array(), App::REGISTER);
|
||||
}
|
||||
|
||||
/**
|
||||
* test path() with a plugin.
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue