diff --git a/lib/Cake/Core/App.php b/lib/Cake/Core/App.php index 69adf14e9b7..882af42a3ec 100644 --- a/lib/Cake/Core/App.php +++ b/lib/Cake/Core/App.php @@ -21,25 +21,16 @@ use Cake\Utility\Inflector; /** - * App is responsible for path management, class location and class loading. + * App is responsible for resource location, and path management. * - * ### Adding paths - * - * You can add paths to the search indexes App uses to find classes using `App::build()`. Adding - * additional controller paths for example would alter where CakePHP looks for controllers. - * This allows you to split your application up across the filesystem. * - * ### Packages - * - * CakePHP is organized around the idea of packages, each class belongs to a package or folder where other - * classes reside. You can configure each package location in your application using `App::build('APackage/SubPackage', $paths)` - * to inform the framework where should each class be loaded. Almost every class in the CakePHP framework can be swapped - * by your own compatible implementation. If you wish to use you own class instead of the classes the framework provides, - * just add the class to your libs folder mocking the directory location of where CakePHP expects to find it. + * ### Adding paths * - * For instance if you'd like to use your own HttpSocket class, put it under + * You can add paths to the search indexes App uses to find resources using `App::build()`. Adding + * additional view paths for example would alter where CakePHP looks for view files. * - * App/Network/Http/HttpSocket.php + * You can only add paths for Views and Locale files. All class based resources should be mapped + * using your application's autoloader. * * ### Inspecting loaded paths * @@ -365,6 +356,8 @@ public static function objects($type, $path = null, $cache = true) { if (empty($path)) { $path = static::path($type, $plugin); } + // TODO write tests and fix objects(Plugin) with plugins + // on unique paths. Perhaps use Plugin::loaded()? foreach ((array)$path as $dir) { if ($dir != APP && is_dir($dir)) { @@ -421,7 +414,7 @@ protected static function _packageFormat() { if (empty(static::$_packageFormat)) { static::$_packageFormat = array( 'View' => array( - '%s' . 'View' . DS + '%s' . 'View' . DS, ), 'Locale' => array( '%s' . 'Locale' . DS diff --git a/lib/Cake/Test/TestCase/Core/AppTest.php b/lib/Cake/Test/TestCase/Core/AppTest.php index b17da14646e..6c3a96b6890 100644 --- a/lib/Cake/Test/TestCase/Core/AppTest.php +++ b/lib/Cake/Test/TestCase/Core/AppTest.php @@ -58,9 +58,6 @@ public function testClassname() { $this->assertFalse(App::classname('Unknown', 'Controller', 'Controller')); // Test plugin - App::build(array( - 'Plugin' => array(CAKE . 'Test' . DS . 'TestApp' . DS . 'Plugin' . DS) - ), App::RESET); Plugin::load('TestPlugin'); $this->assertEquals('TestPlugin\Utility\TestPluginEngine', App::classname('TestPlugin.TestPlugin', 'Utility', 'Engine')); $this->assertFalse(App::classname('TestPlugin.Unknown', 'Utility')); @@ -87,7 +84,7 @@ public function testClassnameUnknownPlugin() { public function testBuild() { $old = App::path('View'); $expected = array( - APP . 'View' . DS + APP . 'View' . DS, ); $this->assertEquals($expected, $old); @@ -96,7 +93,7 @@ public function testBuild() { $new = App::path('View'); $expected = array( '/path/to/views/', - APP . 'View' . DS + APP . 'View' . DS, ); $this->assertEquals($expected, $new); @@ -139,9 +136,6 @@ public function testBuild() { */ public function testPathWithPlugins() { $basepath = CAKE . 'Test' . DS . 'TestApp' . DS . 'Plugin' . DS; - App::build(array( - 'Plugin' => array($basepath), - )); Plugin::load('TestPlugin'); $result = App::path('Controller', 'TestPlugin'); @@ -154,23 +148,23 @@ public function testPathWithPlugins() { * @return void */ public function testBuildWithReset() { - $old = App::path('Model'); + $old = App::path('View'); $expected = array( - APP . 'Model' . DS + APP . 'View' . DS, ); $this->assertEquals($expected, $old); - App::build(array('Model' => array('/path/to/models/')), App::RESET); + App::build(array('View' => array('/path/to/views/')), App::RESET); - $new = App::path('Model'); + $new = App::path('View'); $expected = array( - '/path/to/models/' + '/path/to/views/' ); $this->assertEquals($expected, $new); App::build(); //reset defaults - $defaults = App::path('Model'); + $defaults = App::path('View'); $this->assertEquals($old, $defaults); } @@ -209,28 +203,20 @@ public function testListObjects() { $this->assertTrue(in_array('Dispatcher', $result)); $this->assertTrue(in_array('Router', $result)); - App::build(array( - 'Model/Behavior' => App::core('Model/Behavior'), - 'Controller' => App::core('Controller'), - 'Controller/Component' => App::core('Controller/Component'), - 'View' => App::core('View'), - 'Model' => App::core('Model'), - 'View/Helper' => App::core('View/Helper'), - ), App::RESET); $result = App::objects('Model/Behavior', null, false); - $this->assertTrue(in_array('TreeBehavior', $result)); + $this->assertContains('PersisterOneBehaviorBehavior', $result); $result = App::objects('Controller/Component', null, false); - $this->assertTrue(in_array('AuthComponent', $result)); + $this->assertContains('AppleComponent', $result); $result = App::objects('View', null, false); - $this->assertTrue(in_array('JsonView', $result)); + $this->assertContains('CustomJsonView', $result); $result = App::objects('View/Helper', null, false); - $this->assertTrue(in_array('HtmlHelper', $result)); + $this->assertContains('BananaHelper', $result); $result = App::objects('Model', null, false); - $this->assertTrue(in_array('AcoAction', $result)); + $this->assertContains('Article', $result); $result = App::objects('file'); $this->assertFalse($result); @@ -241,14 +227,7 @@ public function testListObjects() { $result = App::objects('NonExistingType'); $this->assertSame(array(), $result); - } - function testMe() { - App::build(array( - 'Plugin' => array( - CAKE . 'Test/TestApp/Plugin/' - ) - )); $result = App::objects('Plugin', null, false); $this->assertContains('TestPlugin', $result); $this->assertContains('TestPluginTwo', $result); @@ -355,9 +334,8 @@ public function testThemePath() { */ public function testPaths() { $result = App::paths(); - $this->assertArrayHasKey('Plugin', $result); - $this->assertArrayHasKey('Controller', $result); - $this->assertArrayHasKey('Controller/Component', $result); + $this->assertArrayHasKey('View', $result); + $this->assertArrayHasKey('Locale', $result); } }