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
*/
public static function load($className) {
if (isset(self::$__classMap[$className])) {
if ($file = self::__mapped($className)) {
if (!isset(self::$__classMap[$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;
}
}
$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;
//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 ($paths as $path) {
$file = $path . $className . '.php';
foreach ($tries as $file) {
if (file_exists($file)) {
self::__map($file, $className);
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;

View file

@ -16,6 +16,9 @@
* @since CakePHP(tm) v 2.0
* @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
*

View file

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