Skip to content

Commit

Permalink
Removing 1.3 Backwards compatible code to load underscored files. Now…
Browse files Browse the repository at this point in the history
… you can App::build('Locale') instead of 'locales'
  • Loading branch information
lorenzo committed Jan 6, 2012
1 parent a47c816 commit 00a0c60
Show file tree
Hide file tree
Showing 19 changed files with 47 additions and 98 deletions.
68 changes: 17 additions & 51 deletions lib/Cake/Core/App.php
Expand Up @@ -176,6 +176,7 @@ class App {
'libs' => 'Lib',
'vendors' => 'Vendor',
'plugins' => 'Plugin',
'locales' => 'Locale'
);

/**
Expand Down Expand Up @@ -548,25 +549,6 @@ public static function load($className) {
}
}

// To help apps migrate to 2.0 old style file names are allowed
// if the trailing segment is one of the types that changed, alternates will be tried.
foreach ($paths as $path) {
$underscored = Inflector::underscore($className);
$tries = array($path . $underscored . '.php');
$parts = explode('_', $underscored);
$numParts = count($parts);
if ($numParts > 1 && in_array($parts[$numParts - 1], array('behavior', 'helper', 'component'))) {
array_pop($parts);
$tries[] = $path . implode('_', $parts) . '.php';
}
foreach ($tries as $file) {
if (file_exists($file)) {
self::_map($file, $className);
return include $file;
}
}
}

return false;
}

Expand Down Expand Up @@ -826,71 +808,55 @@ protected static function _packageFormat() {
if (empty(self::$_packageFormat)) {
self::$_packageFormat = array(
'Model' => array(
'%s' . 'Model' . DS,
'%s' . 'models' . DS
'%s' . 'Model' . DS
),
'Model/Behavior' => array(
'%s' . 'Model' . DS . 'Behavior' . DS,
'%s' . 'models' . DS . 'behaviors' . DS
'%s' . 'Model' . DS . 'Behavior' . DS
),
'Model/Datasource' => array(
'%s' . 'Model' . DS . 'Datasource' . DS,
'%s' . 'models' . DS . 'datasources' . DS
'%s' . 'Model' . DS . 'Datasource' . DS
),
'Model/Datasource/Database' => array(
'%s' . 'Model' . DS . 'Datasource' . DS . 'Database' . DS,
'%s' . 'models' . DS . 'datasources' . DS . 'database' . DS
'%s' . 'Model' . DS . 'Datasource' . DS . 'Database' . DS
),
'Model/Datasource/Session' => array(
'%s' . 'Model' . DS . 'Datasource' . DS . 'Session' . DS,
'%s' . 'models' . DS . 'datasources' . DS . 'session' . DS
'%s' . 'Model' . DS . 'Datasource' . DS . 'Session' . DS
),
'Controller' => array(
'%s' . 'Controller' . DS,
'%s' . 'controllers' . DS
'%s' . 'Controller' . DS
),
'Controller/Component' => array(
'%s' . 'Controller' . DS . 'Component' . DS,
'%s' . 'controllers' . DS . 'components' . DS
'%s' . 'Controller' . DS . 'Component' . DS
),
'Controller/Component/Auth' => array(
'%s' . 'Controller' . DS . 'Component' . DS . 'Auth' . DS,
'%s' . 'controllers' . DS . 'components' . DS . 'auth' . DS
'%s' . 'Controller' . DS . 'Component' . DS . 'Auth' . DS
),
'View' => array(
'%s' . 'View' . DS,
'%s' . 'views' . DS
'%s' . 'View' . DS
),
'View/Helper' => array(
'%s' . 'View' . DS . 'Helper' . DS,
'%s' . 'views' . DS . 'helpers' . DS
'%s' . 'View' . DS . 'Helper' . DS
),
'Console' => array(
'%s' . 'Console' . DS,
'%s' . 'console' . DS
'%s' . 'Console' . DS
),
'Console/Command' => array(
'%s' . 'Console' . DS . 'Command' . DS,
'%s' . 'console' . DS . 'shells' . DS,
'%s' . 'Console' . DS . 'Command' . DS
),
'Console/Command/Task' => array(
'%s' . 'Console' . DS . 'Command' . DS . 'Task' . DS,
'%s' . 'console' . DS . 'shells' . DS . 'tasks' . DS
'%s' . 'Console' . DS . 'Command' . DS . 'Task' . DS
),
'Lib' => array(
'%s' . 'Lib' . DS,
'%s' . 'libs' . DS
'%s' . 'Lib' . DS
),
'locales' => array(
'%s' . 'Locale' . DS,
'%s' . 'locale' . DS
'Locale' => array(
'%s' . 'Locale' . DS
),
'Vendor' => array(
'%s' . 'Vendor' . DS, VENDORS
),
'Plugin' => array(
APP . 'Plugin' . DS,
APP . 'plugins' . DS,
dirname(dirname(CAKE)) . DS . 'plugins' . DS
)
);
Expand Down
12 changes: 6 additions & 6 deletions lib/Cake/Test/Case/Controller/ComponentCollectionTest.php
Expand Up @@ -88,9 +88,9 @@ public function testLoadWithAlias() {

App::build(array('plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)));
CakePlugin::load('TestPlugin');
$result = $this->Components->load('SomeOther', array('className' => 'TestPlugin.OtherComponent'));
$this->assertInstanceOf('OtherComponentComponent', $result);
$this->assertInstanceOf('OtherComponentComponent', $this->Components->SomeOther);
$result = $this->Components->load('SomeOther', array('className' => 'TestPlugin.Other'));
$this->assertInstanceOf('OtherComponent', $result);
$this->assertInstanceOf('OtherComponent', $this->Components->SomeOther);

$result = $this->Components->attached();
$this->assertEquals(array('Cookie', 'SomeOther'), $result, 'attached() results are wrong.');
Expand Down Expand Up @@ -131,9 +131,9 @@ public function testLoadPluginComponent() {
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS),
));
CakePlugin::load('TestPlugin');
$result = $this->Components->load('TestPlugin.OtherComponent');
$this->assertInstanceOf('OtherComponentComponent', $result, 'Component class is wrong.');
$this->assertInstanceOf('OtherComponentComponent', $this->Components->OtherComponent, 'Class is wrong');
$result = $this->Components->load('TestPlugin.Other');
$this->assertInstanceOf('OtherComponent', $result, 'Component class is wrong.');
$this->assertInstanceOf('OtherComponent', $this->Components->Other, 'Class is wrong');
App::build();
CakePlugin::unload();
}
Expand Down
50 changes: 17 additions & 33 deletions lib/Cake/Test/Case/Core/AppTest.php
Expand Up @@ -41,17 +41,15 @@ public function tearDown() {
public function testBuild() {
$old = App::path('Model');
$expected = array(
APP . 'Model' . DS,
APP . 'models' . DS
APP . 'Model' . DS
);
$this->assertEquals($expected, $old);

App::build(array('Model' => array('/path/to/models/')));
$new = App::path('Model');
$expected = array(
'/path/to/models/',
APP . 'Model' . DS,
APP . 'models' . DS
APP . 'Model' . DS
);
$this->assertEquals($expected, $new);

Expand All @@ -60,8 +58,7 @@ public function testBuild() {
$new = App::path('Model');
$expected = array(
'/path/to/models/',
APP . 'Model' . DS,
APP . 'models' . DS
APP . 'Model' . DS
);
$this->assertEquals($expected, $new);

Expand All @@ -70,7 +67,6 @@ public function testBuild() {
$new = App::path('Model');
$expected = array(
APP . 'Model' . DS,
APP . 'models' . DS,
'/path/to/models/'
);
$this->assertEquals($expected, $new);
Expand All @@ -83,14 +79,12 @@ public function testBuild() {
$new = App::path('Model');
$expected = array(
APP . 'Model' . DS,
APP . 'models' . DS,
'/path/to/models/'
);
$this->assertEquals($expected, $new);
$new = App::path('Controller');
$expected = array(
APP . 'Controller' . DS,
APP . 'controllers' . DS,
'/path/to/controllers/'
);
$this->assertEquals($expected, $new);
Expand All @@ -108,8 +102,7 @@ public function testBuild() {
public function testCompatibleBuild() {
$old = App::path('models');
$expected = array(
APP . 'Model' . DS,
APP . 'models' . DS
APP . 'Model' . DS
);
$this->assertEquals($expected, $old);

Expand All @@ -119,17 +112,15 @@ public function testCompatibleBuild() {

$expected = array(
'/path/to/models/',
APP . 'Model' . DS,
APP . 'models' . DS
APP . 'Model' . DS
);
$this->assertEquals($expected, $new);
$this->assertEquals($expected, App::path('Model'));

App::build(array('datasources' => array('/path/to/datasources/')));
$expected = array(
'/path/to/datasources/',
APP . 'Model' . DS . 'Datasource' . DS,
APP . 'models' . DS . 'datasources' . DS
APP . 'Model' . DS . 'Datasource' . DS
);
$result = App::path('datasources');
$this->assertEquals($expected, $result);
Expand All @@ -138,8 +129,7 @@ public function testCompatibleBuild() {
App::build(array('behaviors' => array('/path/to/behaviors/')));
$expected = array(
'/path/to/behaviors/',
APP . 'Model' . DS . 'Behavior' . DS,
APP . 'models' . DS . 'behaviors' . DS
APP . 'Model' . DS . 'Behavior' . DS
);
$result = App::path('behaviors');
$this->assertEquals($expected, $result);
Expand All @@ -148,8 +138,7 @@ public function testCompatibleBuild() {
App::build(array('controllers' => array('/path/to/controllers/')));
$expected = array(
'/path/to/controllers/',
APP . 'Controller' . DS,
APP . 'controllers' . DS
APP . 'Controller' . DS
);
$result = App::path('controllers');
$this->assertEquals($expected, $result);
Expand All @@ -158,8 +147,7 @@ public function testCompatibleBuild() {
App::build(array('components' => array('/path/to/components/')));
$expected = array(
'/path/to/components/',
APP . 'Controller' . DS . 'Component' . DS,
APP . 'controllers' . DS . 'components' . DS
APP . 'Controller' . DS . 'Component' . DS
);
$result = App::path('components');
$this->assertEquals($expected, $result);
Expand All @@ -168,8 +156,7 @@ public function testCompatibleBuild() {
App::build(array('views' => array('/path/to/views/')));
$expected = array(
'/path/to/views/',
APP . 'View' . DS,
APP . 'views' . DS
APP . 'View' . DS
);
$result = App::path('views');
$this->assertEquals($expected, $result);
Expand All @@ -178,8 +165,7 @@ public function testCompatibleBuild() {
App::build(array('helpers' => array('/path/to/helpers/')));
$expected = array(
'/path/to/helpers/',
APP . 'View' . DS . 'Helper' .DS,
APP . 'views' . DS . 'helpers' . DS
APP . 'View' . DS . 'Helper' .DS
);
$result = App::path('helpers');
$this->assertEquals($expected, $result);
Expand All @@ -188,8 +174,7 @@ public function testCompatibleBuild() {
App::build(array('shells' => array('/path/to/shells/')));
$expected = array(
'/path/to/shells/',
APP . 'Console' . DS . 'Command' . DS,
APP . 'console' . DS . 'shells' . DS,
APP . 'Console' . DS . 'Command' . DS
);
$result = App::path('shells');
$this->assertEquals($expected, $result);
Expand Down Expand Up @@ -249,8 +234,7 @@ public function testPathWithPlugins() {
public function testBuildWithReset() {
$old = App::path('Model');
$expected = array(
APP . 'Model' . DS,
APP . 'models' . DS
APP . 'Model' . DS
);
$this->assertEquals($expected, $old);

Expand Down Expand Up @@ -394,9 +378,9 @@ public function testListObjectsInPlugin() {
$this->assertTrue(in_array('TestPluginPost', $result));

$result = App::objects('TestPlugin.behavior');
$this->assertTrue(in_array('TestPluginPersisterOne', $result));
$this->assertTrue(in_array('TestPluginPersisterOneBehavior', $result));
$result = App::objects('TestPlugin.Model/Behavior');
$this->assertTrue(in_array('TestPluginPersisterOne', $result));
$this->assertTrue(in_array('TestPluginPersisterOneBehavior', $result));

$result = App::objects('TestPlugin.helper');
$expected = array('OtherHelperHelper', 'PluggedHelperHelper', 'TestPluginAppHelper');
Expand Down Expand Up @@ -553,8 +537,8 @@ public function testClassLoading() {
*/
public function testPluginImporting() {
App::build(array(
'libs' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Lib' . DS),
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
'Lib' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Lib' . DS),
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
));
CakePlugin::loadAll();

Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Test/Case/Routing/DispatcherTest.php
Expand Up @@ -1124,7 +1124,7 @@ public function testTestPluginDispatch() {
$result = $Dispatcher->dispatch($url, $response, array('return' => 1));
$this->assertTrue(class_exists('TestsController'));
$this->assertTrue(class_exists('TestPluginAppController'));
$this->assertTrue(class_exists('PluginsComponentComponent'));
$this->assertTrue(class_exists('PluginsComponent'));

$this->assertEquals($result->params['controller'], 'tests');
$this->assertEquals($result->params['plugin'], 'test_plugin');
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Test/Case/TestSuite/ControllerTestCaseTest.php
Expand Up @@ -215,11 +215,11 @@ public function testGenerateWithPlugin() {
'TestPlugin.TestPluginComment'
),
'components' => array(
'TestPlugin.PluginsComponent'
'TestPlugin.Plugins'
)
));
$this->assertEquals($Tests->name, 'Tests');
$this->assertInstanceOf('PluginsComponentComponent', $Tests->PluginsComponent);
$this->assertInstanceOf('PluginsComponent', $Tests->Plugins);

$result = ClassRegistry::init('TestPlugin.TestPluginComment');
$this->assertInstanceOf('TestPluginComment', $result);
Expand Down
1 change: 0 additions & 1 deletion lib/Cake/Test/Case/View/ViewTest.php
Expand Up @@ -257,7 +257,6 @@ public function testPluginPathGeneration() {
$expected = array(
CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Plugin' . DS . 'TestPlugin' . DS,
$pluginPath . 'View' . DS,
$pluginPath . 'views' . DS,
$pluginPath . 'Lib' . DS . 'View' . DS,
CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS,
CAKE . 'View' . DS
Expand Down
Expand Up @@ -16,5 +16,5 @@
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
class OtherComponentComponent extends Object {
class OtherComponent extends Object {
}
Expand Up @@ -16,6 +16,6 @@
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
class PluginsComponentComponent extends Component {
public $components = array('TestPlugin.OtherComponent');
class PluginsComponent extends Component {
public $components = array('TestPlugin.Other');
}
Expand Up @@ -20,7 +20,7 @@ class TestsController extends TestPluginAppController {
public $name = 'Tests';
public $uses = array();
public $helpers = array('TestPlugin.OtherHelper', 'Html');
public $components = array('TestPlugin.PluginsComponent');
public $components = array('TestPlugin.Plugins');

public function index() {
$this->set('test_value', 'It is a variable');
Expand Down

0 comments on commit 00a0c60

Please sign in to comment.