Removing 1.3 Backwards compatible code to load underscored files. Now you can App::build('Locale') instead of 'locales'

This commit is contained in:
Jose Lorenzo Rodriguez 2012-01-05 19:56:01 -04:30
parent a47c8160dd
commit 00a0c60733
19 changed files with 47 additions and 98 deletions

View file

@ -176,6 +176,7 @@ class App {
'libs' => 'Lib', 'libs' => 'Lib',
'vendors' => 'Vendor', 'vendors' => 'Vendor',
'plugins' => 'Plugin', 'plugins' => 'Plugin',
'locales' => 'Locale'
); );
/** /**
@ -548,25 +549,6 @@ class App {
} }
} }
// 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; return false;
} }
@ -826,71 +808,55 @@ class App {
if (empty(self::$_packageFormat)) { if (empty(self::$_packageFormat)) {
self::$_packageFormat = array( self::$_packageFormat = array(
'Model' => array( 'Model' => array(
'%s' . 'Model' . DS, '%s' . 'Model' . DS
'%s' . 'models' . DS
), ),
'Model/Behavior' => array( 'Model/Behavior' => array(
'%s' . 'Model' . DS . 'Behavior' . DS, '%s' . 'Model' . DS . 'Behavior' . DS
'%s' . 'models' . DS . 'behaviors' . DS
), ),
'Model/Datasource' => array( 'Model/Datasource' => array(
'%s' . 'Model' . DS . 'Datasource' . DS, '%s' . 'Model' . DS . 'Datasource' . DS
'%s' . 'models' . DS . 'datasources' . DS
), ),
'Model/Datasource/Database' => array( 'Model/Datasource/Database' => array(
'%s' . 'Model' . DS . 'Datasource' . DS . 'Database' . DS, '%s' . 'Model' . DS . 'Datasource' . DS . 'Database' . DS
'%s' . 'models' . DS . 'datasources' . DS . 'database' . DS
), ),
'Model/Datasource/Session' => array( 'Model/Datasource/Session' => array(
'%s' . 'Model' . DS . 'Datasource' . DS . 'Session' . DS, '%s' . 'Model' . DS . 'Datasource' . DS . 'Session' . DS
'%s' . 'models' . DS . 'datasources' . DS . 'session' . DS
), ),
'Controller' => array( 'Controller' => array(
'%s' . 'Controller' . DS, '%s' . 'Controller' . DS
'%s' . 'controllers' . DS
), ),
'Controller/Component' => array( 'Controller/Component' => array(
'%s' . 'Controller' . DS . 'Component' . DS, '%s' . 'Controller' . DS . 'Component' . DS
'%s' . 'controllers' . DS . 'components' . DS
), ),
'Controller/Component/Auth' => array( 'Controller/Component/Auth' => array(
'%s' . 'Controller' . DS . 'Component' . DS . 'Auth' . DS, '%s' . 'Controller' . DS . 'Component' . DS . 'Auth' . DS
'%s' . 'controllers' . DS . 'components' . DS . 'auth' . DS
), ),
'View' => array( 'View' => array(
'%s' . 'View' . DS, '%s' . 'View' . DS
'%s' . 'views' . DS
), ),
'View/Helper' => array( 'View/Helper' => array(
'%s' . 'View' . DS . 'Helper' . DS, '%s' . 'View' . DS . 'Helper' . DS
'%s' . 'views' . DS . 'helpers' . DS
), ),
'Console' => array( 'Console' => array(
'%s' . 'Console' . DS, '%s' . 'Console' . DS
'%s' . 'console' . DS
), ),
'Console/Command' => array( 'Console/Command' => array(
'%s' . 'Console' . DS . 'Command' . DS, '%s' . 'Console' . DS . 'Command' . DS
'%s' . 'console' . DS . 'shells' . DS,
), ),
'Console/Command/Task' => array( 'Console/Command/Task' => array(
'%s' . 'Console' . DS . 'Command' . DS . 'Task' . DS, '%s' . 'Console' . DS . 'Command' . DS . 'Task' . DS
'%s' . 'console' . DS . 'shells' . DS . 'tasks' . DS
), ),
'Lib' => array( 'Lib' => array(
'%s' . 'Lib' . DS, '%s' . 'Lib' . DS
'%s' . 'libs' . DS
), ),
'locales' => array( 'Locale' => array(
'%s' . 'Locale' . DS, '%s' . 'Locale' . DS
'%s' . 'locale' . DS
), ),
'Vendor' => array( 'Vendor' => array(
'%s' . 'Vendor' . DS, VENDORS '%s' . 'Vendor' . DS, VENDORS
), ),
'Plugin' => array( 'Plugin' => array(
APP . 'Plugin' . DS, APP . 'Plugin' . DS,
APP . 'plugins' . DS,
dirname(dirname(CAKE)) . DS . 'plugins' . DS dirname(dirname(CAKE)) . DS . 'plugins' . DS
) )
); );

View file

@ -88,9 +88,9 @@ class ComponentCollectionTest extends CakeTestCase {
App::build(array('plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS))); App::build(array('plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)));
CakePlugin::load('TestPlugin'); CakePlugin::load('TestPlugin');
$result = $this->Components->load('SomeOther', array('className' => 'TestPlugin.OtherComponent')); $result = $this->Components->load('SomeOther', array('className' => 'TestPlugin.Other'));
$this->assertInstanceOf('OtherComponentComponent', $result); $this->assertInstanceOf('OtherComponent', $result);
$this->assertInstanceOf('OtherComponentComponent', $this->Components->SomeOther); $this->assertInstanceOf('OtherComponent', $this->Components->SomeOther);
$result = $this->Components->attached(); $result = $this->Components->attached();
$this->assertEquals(array('Cookie', 'SomeOther'), $result, 'attached() results are wrong.'); $this->assertEquals(array('Cookie', 'SomeOther'), $result, 'attached() results are wrong.');
@ -131,9 +131,9 @@ class ComponentCollectionTest extends CakeTestCase {
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS), 'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS),
)); ));
CakePlugin::load('TestPlugin'); CakePlugin::load('TestPlugin');
$result = $this->Components->load('TestPlugin.OtherComponent'); $result = $this->Components->load('TestPlugin.Other');
$this->assertInstanceOf('OtherComponentComponent', $result, 'Component class is wrong.'); $this->assertInstanceOf('OtherComponent', $result, 'Component class is wrong.');
$this->assertInstanceOf('OtherComponentComponent', $this->Components->OtherComponent, 'Class is wrong'); $this->assertInstanceOf('OtherComponent', $this->Components->Other, 'Class is wrong');
App::build(); App::build();
CakePlugin::unload(); CakePlugin::unload();
} }

View file

@ -41,8 +41,7 @@ class AppTest extends CakeTestCase {
public function testBuild() { public function testBuild() {
$old = App::path('Model'); $old = App::path('Model');
$expected = array( $expected = array(
APP . 'Model' . DS, APP . 'Model' . DS
APP . 'models' . DS
); );
$this->assertEquals($expected, $old); $this->assertEquals($expected, $old);
@ -50,8 +49,7 @@ class AppTest extends CakeTestCase {
$new = App::path('Model'); $new = App::path('Model');
$expected = array( $expected = array(
'/path/to/models/', '/path/to/models/',
APP . 'Model' . DS, APP . 'Model' . DS
APP . 'models' . DS
); );
$this->assertEquals($expected, $new); $this->assertEquals($expected, $new);
@ -60,8 +58,7 @@ class AppTest extends CakeTestCase {
$new = App::path('Model'); $new = App::path('Model');
$expected = array( $expected = array(
'/path/to/models/', '/path/to/models/',
APP . 'Model' . DS, APP . 'Model' . DS
APP . 'models' . DS
); );
$this->assertEquals($expected, $new); $this->assertEquals($expected, $new);
@ -70,7 +67,6 @@ class AppTest extends CakeTestCase {
$new = App::path('Model'); $new = App::path('Model');
$expected = array( $expected = array(
APP . 'Model' . DS, APP . 'Model' . DS,
APP . 'models' . DS,
'/path/to/models/' '/path/to/models/'
); );
$this->assertEquals($expected, $new); $this->assertEquals($expected, $new);
@ -83,14 +79,12 @@ class AppTest extends CakeTestCase {
$new = App::path('Model'); $new = App::path('Model');
$expected = array( $expected = array(
APP . 'Model' . DS, APP . 'Model' . DS,
APP . 'models' . DS,
'/path/to/models/' '/path/to/models/'
); );
$this->assertEquals($expected, $new); $this->assertEquals($expected, $new);
$new = App::path('Controller'); $new = App::path('Controller');
$expected = array( $expected = array(
APP . 'Controller' . DS, APP . 'Controller' . DS,
APP . 'controllers' . DS,
'/path/to/controllers/' '/path/to/controllers/'
); );
$this->assertEquals($expected, $new); $this->assertEquals($expected, $new);
@ -108,8 +102,7 @@ class AppTest extends CakeTestCase {
public function testCompatibleBuild() { public function testCompatibleBuild() {
$old = App::path('models'); $old = App::path('models');
$expected = array( $expected = array(
APP . 'Model' . DS, APP . 'Model' . DS
APP . 'models' . DS
); );
$this->assertEquals($expected, $old); $this->assertEquals($expected, $old);
@ -119,8 +112,7 @@ class AppTest extends CakeTestCase {
$expected = array( $expected = array(
'/path/to/models/', '/path/to/models/',
APP . 'Model' . DS, APP . 'Model' . DS
APP . 'models' . DS
); );
$this->assertEquals($expected, $new); $this->assertEquals($expected, $new);
$this->assertEquals($expected, App::path('Model')); $this->assertEquals($expected, App::path('Model'));
@ -128,8 +120,7 @@ class AppTest extends CakeTestCase {
App::build(array('datasources' => array('/path/to/datasources/'))); App::build(array('datasources' => array('/path/to/datasources/')));
$expected = array( $expected = array(
'/path/to/datasources/', '/path/to/datasources/',
APP . 'Model' . DS . 'Datasource' . DS, APP . 'Model' . DS . 'Datasource' . DS
APP . 'models' . DS . 'datasources' . DS
); );
$result = App::path('datasources'); $result = App::path('datasources');
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
@ -138,8 +129,7 @@ class AppTest extends CakeTestCase {
App::build(array('behaviors' => array('/path/to/behaviors/'))); App::build(array('behaviors' => array('/path/to/behaviors/')));
$expected = array( $expected = array(
'/path/to/behaviors/', '/path/to/behaviors/',
APP . 'Model' . DS . 'Behavior' . DS, APP . 'Model' . DS . 'Behavior' . DS
APP . 'models' . DS . 'behaviors' . DS
); );
$result = App::path('behaviors'); $result = App::path('behaviors');
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
@ -148,8 +138,7 @@ class AppTest extends CakeTestCase {
App::build(array('controllers' => array('/path/to/controllers/'))); App::build(array('controllers' => array('/path/to/controllers/')));
$expected = array( $expected = array(
'/path/to/controllers/', '/path/to/controllers/',
APP . 'Controller' . DS, APP . 'Controller' . DS
APP . 'controllers' . DS
); );
$result = App::path('controllers'); $result = App::path('controllers');
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
@ -158,8 +147,7 @@ class AppTest extends CakeTestCase {
App::build(array('components' => array('/path/to/components/'))); App::build(array('components' => array('/path/to/components/')));
$expected = array( $expected = array(
'/path/to/components/', '/path/to/components/',
APP . 'Controller' . DS . 'Component' . DS, APP . 'Controller' . DS . 'Component' . DS
APP . 'controllers' . DS . 'components' . DS
); );
$result = App::path('components'); $result = App::path('components');
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
@ -168,8 +156,7 @@ class AppTest extends CakeTestCase {
App::build(array('views' => array('/path/to/views/'))); App::build(array('views' => array('/path/to/views/')));
$expected = array( $expected = array(
'/path/to/views/', '/path/to/views/',
APP . 'View' . DS, APP . 'View' . DS
APP . 'views' . DS
); );
$result = App::path('views'); $result = App::path('views');
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
@ -178,8 +165,7 @@ class AppTest extends CakeTestCase {
App::build(array('helpers' => array('/path/to/helpers/'))); App::build(array('helpers' => array('/path/to/helpers/')));
$expected = array( $expected = array(
'/path/to/helpers/', '/path/to/helpers/',
APP . 'View' . DS . 'Helper' .DS, APP . 'View' . DS . 'Helper' .DS
APP . 'views' . DS . 'helpers' . DS
); );
$result = App::path('helpers'); $result = App::path('helpers');
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
@ -188,8 +174,7 @@ class AppTest extends CakeTestCase {
App::build(array('shells' => array('/path/to/shells/'))); App::build(array('shells' => array('/path/to/shells/')));
$expected = array( $expected = array(
'/path/to/shells/', '/path/to/shells/',
APP . 'Console' . DS . 'Command' . DS, APP . 'Console' . DS . 'Command' . DS
APP . 'console' . DS . 'shells' . DS,
); );
$result = App::path('shells'); $result = App::path('shells');
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
@ -249,8 +234,7 @@ class AppTest extends CakeTestCase {
public function testBuildWithReset() { public function testBuildWithReset() {
$old = App::path('Model'); $old = App::path('Model');
$expected = array( $expected = array(
APP . 'Model' . DS, APP . 'Model' . DS
APP . 'models' . DS
); );
$this->assertEquals($expected, $old); $this->assertEquals($expected, $old);
@ -394,9 +378,9 @@ class AppTest extends CakeTestCase {
$this->assertTrue(in_array('TestPluginPost', $result)); $this->assertTrue(in_array('TestPluginPost', $result));
$result = App::objects('TestPlugin.behavior'); $result = App::objects('TestPlugin.behavior');
$this->assertTrue(in_array('TestPluginPersisterOne', $result)); $this->assertTrue(in_array('TestPluginPersisterOneBehavior', $result));
$result = App::objects('TestPlugin.Model/Behavior'); $result = App::objects('TestPlugin.Model/Behavior');
$this->assertTrue(in_array('TestPluginPersisterOne', $result)); $this->assertTrue(in_array('TestPluginPersisterOneBehavior', $result));
$result = App::objects('TestPlugin.helper'); $result = App::objects('TestPlugin.helper');
$expected = array('OtherHelperHelper', 'PluggedHelperHelper', 'TestPluginAppHelper'); $expected = array('OtherHelperHelper', 'PluggedHelperHelper', 'TestPluginAppHelper');
@ -553,8 +537,8 @@ class AppTest extends CakeTestCase {
*/ */
public function testPluginImporting() { public function testPluginImporting() {
App::build(array( App::build(array(
'libs' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Lib' . DS), 'Lib' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Lib' . DS),
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS) 'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
)); ));
CakePlugin::loadAll(); CakePlugin::loadAll();

View file

@ -1124,7 +1124,7 @@ class DispatcherTest extends CakeTestCase {
$result = $Dispatcher->dispatch($url, $response, array('return' => 1)); $result = $Dispatcher->dispatch($url, $response, array('return' => 1));
$this->assertTrue(class_exists('TestsController')); $this->assertTrue(class_exists('TestsController'));
$this->assertTrue(class_exists('TestPluginAppController')); $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['controller'], 'tests');
$this->assertEquals($result->params['plugin'], 'test_plugin'); $this->assertEquals($result->params['plugin'], 'test_plugin');

View file

@ -215,11 +215,11 @@ class ControllerTestCaseTest extends CakeTestCase {
'TestPlugin.TestPluginComment' 'TestPlugin.TestPluginComment'
), ),
'components' => array( 'components' => array(
'TestPlugin.PluginsComponent' 'TestPlugin.Plugins'
) )
)); ));
$this->assertEquals($Tests->name, 'Tests'); $this->assertEquals($Tests->name, 'Tests');
$this->assertInstanceOf('PluginsComponentComponent', $Tests->PluginsComponent); $this->assertInstanceOf('PluginsComponent', $Tests->Plugins);
$result = ClassRegistry::init('TestPlugin.TestPluginComment'); $result = ClassRegistry::init('TestPlugin.TestPluginComment');
$this->assertInstanceOf('TestPluginComment', $result); $this->assertInstanceOf('TestPluginComment', $result);

View file

@ -257,7 +257,6 @@ class ViewTest extends CakeTestCase {
$expected = array( $expected = array(
CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Plugin' . DS . 'TestPlugin' . DS, CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Plugin' . DS . 'TestPlugin' . DS,
$pluginPath . 'View' . DS, $pluginPath . 'View' . DS,
$pluginPath . 'views' . DS,
$pluginPath . 'Lib' . DS . 'View' . DS, $pluginPath . 'Lib' . DS . 'View' . DS,
CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS, CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS,
CAKE . 'View' . DS CAKE . 'View' . DS

View file

@ -16,5 +16,5 @@
* @since CakePHP(tm) v 1.2.0.4206 * @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/ */
class OtherComponentComponent extends Object { class OtherComponent extends Object {
} }

View file

@ -16,6 +16,6 @@
* @since CakePHP(tm) v 1.2.0.4206 * @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/ */
class PluginsComponentComponent extends Component { class PluginsComponent extends Component {
public $components = array('TestPlugin.OtherComponent'); public $components = array('TestPlugin.Other');
} }

View file

@ -20,7 +20,7 @@ class TestsController extends TestPluginAppController {
public $name = 'Tests'; public $name = 'Tests';
public $uses = array(); public $uses = array();
public $helpers = array('TestPlugin.OtherHelper', 'Html'); public $helpers = array('TestPlugin.OtherHelper', 'Html');
public $components = array('TestPlugin.PluginsComponent'); public $components = array('TestPlugin.Plugins');
public function index() { public function index() {
$this->set('test_value', 'It is a variable'); $this->set('test_value', 'It is a variable');