Browse Source

Changed Yii autoloader to support loading PSR-4 classes only (i.e. PEAR-styled classes not supported anymore)

tags/2.0.0-beta
Qiang Xue 11 years ago
parent
commit
e123428c94
  1. 1
      framework/CHANGELOG.md
  2. 27
      framework/yii/BaseYii.php

1
framework/CHANGELOG.md

@ -71,6 +71,7 @@ Yii Framework 2 Change Log
- Chg: Added `yii\widgets\InputWidget::options` (qiangxue)
- Chg: Changed the signature of `urlCreator` and button creators for `yii\gridview\ActionColumn` (qiangxue)
- Chg: Updated HTMLPurified dependency to `4.6.*`.
- Chg: Changed Yii autoloader to support loading PSR-4 classes only (i.e. PEAR-styled classes not supported anymore) (qiangxue)
- New #66: [Auth client library](https://github.com/yiisoft/yii2-authclient) OpenId, OAuth1, OAuth2 clients (klimov-paul)
- New #1393: [Codeception testing framework integration](https://github.com/yiisoft/yii2-codeception) (Ragazzo)
- New #1438: [MongoDB integration](https://github.com/yiisoft/yii2-mongodb) ActiveRecord and Query (klimov-paul)

27
framework/yii/BaseYii.php

@ -266,12 +266,9 @@ class BaseYii
* 2. If the class is namespaced (e.g. `yii\base\Component`), it will attempt
* to include the file associated with the corresponding path alias
* (e.g. `@yii/base/Component.php`);
* 3. If the class is named in PEAR style (e.g. `PHPUnit_Framework_TestCase`),
* 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.
* This autoloader allows loading classes that follow the [PSR-4 standard](http://www.php-fig.org/psr/psr-4/)
* and have its top-level namespace defined as path aliases.
*
* @param string $className the fully qualified class name without a leading backslash "\"
* @throws UnknownClassException if the class does not exist in the class file
@ -283,25 +280,13 @@ class BaseYii
if ($classFile[0] === '@') {
$classFile = static::getAlias($classFile);
}
} else {
// follow PSR-0 to determine the class file
if (($pos = strrpos($className, '\\')) !== false) {
// namespaced class, e.g. yii\base\Component
$path = str_replace('\\', '/', substr($className, 0, $pos + 1))
. str_replace('_', '/', substr($className, $pos + 1)) . '.php';
} else {
$path = str_replace('_', '/', $className) . '.php';
}
// try loading via path alias
if (strpos($path, '/') === false) {
return;
} else {
$classFile = static::getAlias('@' . $path, false);
} elseif (strpos($className, '\\') !== false) {
$classFile = static::getAlias('@' . str_replace('\\', '/', $className) . '.php', false);
if ($classFile === false || !is_file($classFile)) {
return;
}
}
} else {
return;
}
include($classFile);

Loading…
Cancel
Save