Proposal. Adding new package using App::build().

For instance, adding new 'Service' package to app search paths.
This commit is contained in:
Yosuke Basuke Suzuki 2011-10-20 17:19:08 +09:00 committed by mark_story
parent fcd96bcc60
commit f861cc6e09
2 changed files with 50 additions and 0 deletions

View file

@ -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) {

View file

@ -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.
*