Skip to content
Permalink
Browse files

Refactoring App::build() so it looks more readable

  • Loading branch information...
Yosuke Basuke Suzuki authored and lorenzo committed Oct 6, 2011
1 parent 0a70963 commit 0b6c93cf82d5aa32624095c4c2fa7e77b47ad1f1
Showing with 93 additions and 87 deletions.
  1. +91 −85 lib/Cake/Core/App.php
  2. +2 −2 lib/Cake/Test/Case/Core/AppTest.php
@@ -214,8 +214,9 @@ public static function path($type, $plugin = null) {
if (!empty($plugin)) {
$path = array();
$pluginPath = self::pluginPath($plugin);
if (!empty(self::$_packageFormat[$type])) {
foreach (self::$_packageFormat[$type] as $f) {
$packageFormat= self::_packageFormat();
if (!empty($packageFormat[$type])) {
foreach ($packageFormat[$type] as $f) {
$path[] = sprintf($f, $pluginPath);
}
}
@@ -260,100 +261,28 @@ public static function paths() {
* @return void
*/
public static function build($paths = array(), $mode = App::PREPEND) {
if (empty(self::$_packageFormat)) {
self::$_packageFormat = array(
'Model' => array(
'%s' . 'Model' . DS,
'%s' . 'models' . DS
),
'Model/Behavior' => array(
'%s' . 'Model' . DS . 'Behavior' . DS,
'%s' . 'models' . DS . 'behaviors' . DS
),
'Model/Datasource' => array(
'%s' . 'Model' . DS . 'Datasource' . DS,
'%s' . 'models' . DS . 'datasources' . DS
),
'Model/Datasource/Database' => array(
'%s' . 'Model' . DS . 'Datasource' . DS . 'Database' . DS,
'%s' . 'models' . DS . 'datasources' . DS . 'database' . DS
),
'Model/Datasource/Session' => array(
'%s' . 'Model' . DS . 'Datasource' . DS . 'Session' . DS,
'%s' . 'models' . DS . 'datasources' . DS . 'session' . DS
),
'Controller' => array(
'%s' . 'Controller' . DS,
'%s' . 'controllers' . DS
),
'Controller/Component' => array(
'%s' . 'Controller' . DS . 'Component' . DS,
'%s' . 'controllers' . DS . 'components' . DS
),
'Controller/Component/Auth' => array(
'%s' . 'Controller' . DS . 'Component' . DS . 'Auth' . DS,
'%s' . 'controllers' . DS . 'components' . DS . 'auth' . DS
),
'View' => array(
'%s' . 'View' . DS,
'%s' . 'views' . DS
),
'View/Helper' => array(
'%s' . 'View' . DS . 'Helper' . DS,
'%s' . 'views' . DS . 'helpers' . DS
),
'Console' => array(
'%s' . 'Console' . DS,
'%s' . 'console' . DS
),
'Console/Command' => array(
'%s' . 'Console' . DS . 'Command' . DS,
'%s' . 'console' . DS . 'shells' . DS,
),
'Console/Command/Task' => array(
'%s' . 'Console' . DS . 'Command' . DS . 'Task' . DS,
'%s' . 'console' . DS . 'shells' . DS . 'tasks' . DS
),
'Lib' => array(
'%s' . 'Lib' . DS,
'%s' . 'libs' . DS
),
'locales' => array(
'%s' . 'Locale' . DS,
'%s' . 'locale' . DS
),
'Vendor' => array('%s' . 'Vendor' . DS, VENDORS),
'Plugin' => array(
APP . 'Plugin' . DS,
APP . 'plugins' . DS,
dirname(dirname(CAKE)) . DS . 'plugins' . DS,
)
);
//Provides Backwards compatibility for old-style package names
$legacyPaths = array();
foreach ($paths as $type => $path) {
if (!empty(self::$legacy[$type])) {
$type = self::$legacy[$type];
}
$legacyPaths[$type] = $path;
}
$paths = $legacyPaths;
if ($mode === App::RESET) {
foreach ($paths as $type => $new) {
if (!empty(self::$legacy[$type])) {
$type = self::$legacy[$type];
}
self::$_packages[$type] = (array)$new;
self::objects($type, null, false);
}
return $paths;
return;
}
//Provides Backwards compatibility for old-style package names
$legacyPaths = array();
foreach ($paths as $type => $path) {
if (!empty(self::$legacy[$type])) {
$type = self::$legacy[$type];
}
$legacyPaths[$type] = $path;
}
$packageFormat = self::_packageFormat();
$paths = $legacyPaths;
$defaults = array();
foreach (self::$_packageFormat as $package => $format) {
foreach ($packageFormat as $package => $format) {
foreach ($format as $f) {
$defaults[$package][] = sprintf($f, APP);
}
@@ -853,6 +782,83 @@ protected static function _mapped($name, $plugin = null) {
return false;
}
protected static function _packageFormat() {
if (empty(self::$_packageFormat)) {
self::$_packageFormat = array(
'Model' => array(
'%s' . 'Model' . DS,
'%s' . 'models' . DS
),
'Model/Behavior' => array(
'%s' . 'Model' . DS . 'Behavior' . DS,
'%s' . 'models' . DS . 'behaviors' . DS
),
'Model/Datasource' => array(
'%s' . 'Model' . DS . 'Datasource' . DS,
'%s' . 'models' . DS . 'datasources' . DS
),
'Model/Datasource/Database' => array(
'%s' . 'Model' . DS . 'Datasource' . DS . 'Database' . DS,
'%s' . 'models' . DS . 'datasources' . DS . 'database' . DS
),
'Model/Datasource/Session' => array(
'%s' . 'Model' . DS . 'Datasource' . DS . 'Session' . DS,
'%s' . 'models' . DS . 'datasources' . DS . 'session' . DS
),
'Controller' => array(
'%s' . 'Controller' . DS,
'%s' . 'controllers' . DS
),
'Controller/Component' => array(
'%s' . 'Controller' . DS . 'Component' . DS,
'%s' . 'controllers' . DS . 'components' . DS
),
'Controller/Component/Auth' => array(
'%s' . 'Controller' . DS . 'Component' . DS . 'Auth' . DS,
'%s' . 'controllers' . DS . 'components' . DS . 'auth' . DS
),
'View' => array(
'%s' . 'View' . DS,
'%s' . 'views' . DS
),
'View/Helper' => array(
'%s' . 'View' . DS . 'Helper' . DS,
'%s' . 'views' . DS . 'helpers' . DS
),
'Console' => array(
'%s' . 'Console' . DS,
'%s' . 'console' . DS
),
'Console/Command' => array(
'%s' . 'Console' . DS . 'Command' . DS,
'%s' . 'console' . DS . 'shells' . DS,
),
'Console/Command/Task' => array(
'%s' . 'Console' . DS . 'Command' . DS . 'Task' . DS,
'%s' . 'console' . DS . 'shells' . DS . 'tasks' . DS
),
'Lib' => array(
'%s' . 'Lib' . DS,
'%s' . 'libs' . DS
),
'locales' => array(
'%s' . 'Locale' . DS,
'%s' . 'locale' . DS
),
'Vendor' => array(
'%s' . 'Vendor' . DS, VENDORS
),
'Plugin' => array(
APP . 'Plugin' . DS,
APP . 'plugins' . DS,
dirname(dirname(CAKE)) . DS . 'plugins' . DS
)
);
}
return self::$_packageFormat;
}
/**
* Object destructor.
*
@@ -345,7 +345,7 @@ public function testListObjectsIgnoreDotDirectories() {
$path = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS;
App::build(array(
'plugins' => array($path)
), true);
), App::RESET);
mkdir($path . '.svn');
$result = App::objects('plugin', null, false);
rmdir($path . '.svn');
@@ -362,7 +362,7 @@ public function testListObjectsInPlugin() {
App::build(array(
'Model' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Model' . DS),
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
), true);
), App::RESET);
CakePlugin::loadAll();
$result = App::objects('TestPlugin.model');

0 comments on commit 0b6c93c

Please sign in to comment.
You can’t perform that action at this time.