Commit bb2274ea by Carsten Brandt

re-added Exception about wrong class name to autoloader

helps reducing weird error messages.
parent 5e759790
......@@ -9,6 +9,7 @@ namespace yii;
use yii\base\Exception;
use yii\base\InvalidConfigException;
use yii\base\InvalidParamException;
use yii\base\UnknownClassException;
use yii\log\Logger;
/**
......@@ -333,7 +334,11 @@ class YiiBase
* it will attempt to include the file associated with the corresponding path alias
* (e.g. `@PHPUnit/Framework/TestCase.php`);
*
* This autoloader allows loading classes that follow the [PSR-0 standard](http://www.php-fig.org/psr/0/).
* Therefor a path alias has to be defined for each top-level namespace.
*
* @param string $className the fully qualified class name without a leading backslash "\"
* @throws UnknownClassException if the class does not exist in the class file
*/
public static function autoload($className)
{
......@@ -342,7 +347,6 @@ class YiiBase
if ($classFile[0] === '@') {
$classFile = static::getAlias($classFile);
}
include($classFile);
} else {
// follow PSR-0 to determine the class file
if (($pos = strrpos($className, '\\')) !== false) {
......@@ -354,13 +358,22 @@ class YiiBase
}
// try loading via path alias
if (strpos($path, '/') !== false) {
if (strpos($path, '/') === false) {
return;
} else {
$classFile = static::getAlias('@' . $path, false);
if ($classFile !== false && is_file($classFile)) {
include($classFile);
if ($classFile === false || !is_file($classFile)) {
return;
}
}
}
include($classFile);
if (!class_exists($className, false) && !interface_exists($className, false) &&
(!function_exists('trait_exists') || !trait_exists($className, false))) {
throw new UnknownClassException("Unable to find '$className' in file: $classFile");
}
}
/**
......
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\base;
/**
* UnknownClassException represents an exception caused by using an unknown class.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class UnknownClassException extends Exception
{
/**
* @return string the user-friendly name of this exception
*/
public function getName()
{
return \Yii::t('yii', 'Unknown Class');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment