Small refactoring, and adding some App::uses() to avoid problems

This commit is contained in:
Jose Lorenzo Rodriguez 2011-04-21 17:56:03 -04:30
parent a8c2dbfd72
commit 8dc675335a
3 changed files with 36 additions and 30 deletions

View file

@ -531,45 +531,47 @@ class App {
* @param string $className the name of the class to load * @param string $className the name of the class to load
*/ */
public static function load($className) { public static function load($className) {
if (isset(self::$__classMap[$className])) { if (!isset(self::$__classMap[$className])) {
if ($file = self::__mapped($className)) { return false;
}
if ($file = self::__mapped($className)) {
return include $file;
}
$parts = explode('.', self::$__classMap[$className], 2);
list($plugin, $package) = count($parts) > 1 ? $parts : array(null, current($parts));
$paths = self::path($package, $plugin);
if (empty($plugin)) {
$appLibs = empty(self::$__packages['Lib']) ? APPLIBS : current(self::$__packages['Lib']);
$paths[] = $appLibs . $package . DS;
$paths[] = LIBS . $package . DS;
}
foreach ($paths as $path) {
$file = $path . $className . '.php';
if (file_exists($file)) {
self::__map($file, $className);
return include $file; return include $file;
} }
}
$parts = explode('.', self::$__classMap[$className], 2); //To help apps migrate to 2.0 old style file names are allowed
list($plugin, $package) = count($parts) > 1 ? $parts : array(null, current($parts)); foreach ($paths as $path) {
$paths = self::path($package, $plugin); $underscored = Inflector::underscore($className);
$tries = array($path . $underscored . '.php');
if (empty($plugin)) { $parts = explode('_', $underscored);
$appLibs = empty(self::$__packages['Lib']) ? APPLIBS : current(self::$__packages['Lib']); if (count($parts) > 1) {
$paths[] = $appLibs . $package . DS; array_pop($parts);
$paths[] = LIBS . $package . DS; $tries[] = $path . implode('_', $parts) . '.php';
} }
foreach ($tries as $file) {
foreach ($paths as $path) {
$file = $path . $className . '.php';
if (file_exists($file)) { if (file_exists($file)) {
self::__map($file, $className); self::__map($file, $className);
return include $file; return include $file;
} }
} }
//To help apps migrate to 2.0 old style file names are allowed
foreach ($paths as $path) {
$underscored = Inflector::underscore($className);
$tries = array($path . $underscored . '.php');
$parts = explode('_', $underscored);
if (count($parts) > 1) {
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;

View file

@ -16,6 +16,9 @@
* @since CakePHP(tm) v 2.0 * @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/ */
App::uses('Cache', 'Cache');
/** /**
* CacheSession provides method for saving sessions into a Cache engine. Used with CakeSession * CacheSession provides method for saving sessions into a Cache engine. Used with CakeSession
* *

View file

@ -72,6 +72,7 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
*/ */
protected $_configure = array(); protected $_configure = array();
/** /**
* Runs the test case and collects the results in a TestResult object. * Runs the test case and collects the results in a TestResult object.
* If no TestResult object is passed a new one will be created. * If no TestResult object is passed a new one will be created.