diff --git a/lib/Cake/Core/App.php b/lib/Cake/Core/App.php index c76008ab4..c2234deba 100644 --- a/lib/Cake/Core/App.php +++ b/lib/Cake/Core/App.php @@ -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) { diff --git a/lib/Cake/Test/Case/Core/AppTest.php b/lib/Cake/Test/Case/Core/AppTest.php index 3520fd461..6ef7bcd20 100644 --- a/lib/Cake/Test/Case/Core/AppTest.php +++ b/lib/Cake/Test/Case/Core/AppTest.php @@ -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. *