mirror of
https://github.com/yiisoft/yii2.git
synced 2025-12-01 23:51:12 +08:00
refactoring autoloading (WIP)
This commit is contained in:
@@ -46,8 +46,8 @@ class YiiBase
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var array class map used by the Yii autoloading mechanism.
|
* @var array class map used by the Yii autoloading mechanism.
|
||||||
* The array keys are the class names, and the array values are the corresponding class file paths.
|
* The array keys are the class names (without leading backslashes), and the array values
|
||||||
* This property mainly affects how [[autoload]] works.
|
* are the corresponding class file paths. This property mainly affects how [[autoload()]] works.
|
||||||
* @see import
|
* @see import
|
||||||
* @see autoload
|
* @see autoload
|
||||||
*/
|
*/
|
||||||
@@ -113,7 +113,7 @@ class YiiBase
|
|||||||
* includes the class file when the class is referenced in the code the first time.
|
* includes the class file when the class is referenced in the code the first time.
|
||||||
*
|
*
|
||||||
* Importing a directory will add the directory to the front of the [[classPath]] array.
|
* Importing a directory will add the directory to the front of the [[classPath]] array.
|
||||||
* When [[autoload]] is loading an unknown class, it will search in the directories
|
* When [[autoload()]] is loading an unknown class, it will search in the directories
|
||||||
* specified in [[classPath]] to find the corresponding class file to include.
|
* specified in [[classPath]] to find the corresponding class file to include.
|
||||||
* For this reason, if multiple directories are imported, the directories imported later
|
* For this reason, if multiple directories are imported, the directories imported later
|
||||||
* will take precedence in class file searching.
|
* will take precedence in class file searching.
|
||||||
@@ -273,7 +273,7 @@ class YiiBase
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strpos($className, '\\') !== false) {
|
if (strrpos($className, '\\') > 0) {
|
||||||
// namespaced class, e.g. yii\base\Component
|
// namespaced class, e.g. yii\base\Component
|
||||||
// convert namespace to path alias, e.g. yii\base\Component to @yii/base/Component
|
// convert namespace to path alias, e.g. yii\base\Component to @yii/base/Component
|
||||||
$alias = '@' . str_replace('\\', '/', ltrim($className, '\\'));
|
$alias = '@' . str_replace('\\', '/', ltrim($className, '\\'));
|
||||||
@@ -296,17 +296,19 @@ class YiiBase
|
|||||||
if (is_file($path)) {
|
if (is_file($path)) {
|
||||||
$classFile = $path;
|
$classFile = $path;
|
||||||
$alias = $className;
|
$alias = $className;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($classFile, $alias) && is_file($classFile)) {
|
if (isset($classFile, $alias) && is_file($classFile)) {
|
||||||
if (!YII_DEBUG || basename(realpath($classFile)) === basename($alias) . '.php') {
|
if (basename(realpath($classFile)) === basename($alias) . '.php') {
|
||||||
include($classFile);
|
include($classFile);
|
||||||
return true;
|
if (class_exists($className, false)) {
|
||||||
} else {
|
return true;
|
||||||
throw new Exception("Class name '$className' does not match the class file '" . realpath($classFile) . "'. Have you checked their case sensitivity?");
|
}
|
||||||
}
|
}
|
||||||
|
throw new Exception("The class file name '" . realpath($classFile) . "' does not match the class name '$className'. Please check the case of the names and make sure the class file does not have syntax errors.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user