Commit 8b2b7915 by Qiang Xue

Renamed application to app.

parent fcf3f2c8
...@@ -65,7 +65,7 @@ class YiiBase ...@@ -65,7 +65,7 @@ class YiiBase
/** /**
* @var yii\base\Application the application instance * @var yii\base\Application the application instance
*/ */
public static $application; public static $app;
/** /**
* @var array registered path aliases * @var array registered path aliases
* @see getAlias * @see getAlias
...@@ -125,8 +125,8 @@ class YiiBase ...@@ -125,8 +125,8 @@ class YiiBase
* *
* To import a class or a directory, one can use either path alias or class name (can be namespaced): * To import a class or a directory, one can use either path alias or class name (can be namespaced):
* *
* - `@application/components/GoogleMap`: importing the `GoogleMap` class with a path alias; * - `@app/components/GoogleMap`: importing the `GoogleMap` class with a path alias;
* - `@application/components/*`: importing the whole `components` directory with a path alias; * - `@app/components/*`: importing the whole `components` directory with a path alias;
* - `GoogleMap`: importing the `GoogleMap` class with a class name. [[autoload()]] will be used * - `GoogleMap`: importing the `GoogleMap` class with a class name. [[autoload()]] will be used
* when this class is used for the first time. * when this class is used for the first time.
* *
...@@ -262,6 +262,7 @@ class YiiBase ...@@ -262,6 +262,7 @@ class YiiBase
* *
* @param string $className class name * @param string $className class name
* @return boolean whether the class has been loaded successfully * @return boolean whether the class has been loaded successfully
* @throws Exception if the class file does not exist
*/ */
public static function autoload($className) public static function autoload($className)
{ {
...@@ -322,12 +323,12 @@ class YiiBase ...@@ -322,12 +323,12 @@ class YiiBase
* the class. For example, * the class. For example,
* *
* - `\app\components\GoogleMap`: fully-qualified namespaced class. * - `\app\components\GoogleMap`: fully-qualified namespaced class.
* - `@application/components/GoogleMap`: an alias * - `@app/components/GoogleMap`: an alias
* *
* Below are some usage examples: * Below are some usage examples:
* *
* ~~~ * ~~~
* $object = \Yii::createObject('@application/components/GoogleMap'); * $object = \Yii::createObject('@app/components/GoogleMap');
* $object = \Yii::createObject(array( * $object = \Yii::createObject(array(
* 'class' => '\app\components\GoogleMap', * 'class' => '\app\components\GoogleMap',
* 'apiKey' => 'xyz', * 'apiKey' => 'xyz',
...@@ -520,6 +521,6 @@ class YiiBase ...@@ -520,6 +521,6 @@ class YiiBase
*/ */
public static function t($message, $params = array(), $language = null) public static function t($message, $params = array(), $language = null)
{ {
Yii::$application->getI18N()->translate($message, $params, $language); Yii::$app->getI18N()->translate($message, $params, $language);
} }
} }
...@@ -105,7 +105,7 @@ class Application extends Module ...@@ -105,7 +105,7 @@ class Application extends Module
*/ */
public function __construct($id, $basePath, $config = array()) public function __construct($id, $basePath, $config = array())
{ {
Yii::$application = $this; Yii::$app = $this;
$this->id = $id; $this->id = $id;
$this->setBasePath($basePath); $this->setBasePath($basePath);
...@@ -342,7 +342,7 @@ class Application extends Module ...@@ -342,7 +342,7 @@ class Application extends Module
*/ */
public function registerDefaultAliases() public function registerDefaultAliases()
{ {
Yii::$aliases['@application'] = $this->getBasePath(); Yii::$aliases['@app'] = $this->getBasePath();
Yii::$aliases['@entry'] = dirname($_SERVER['SCRIPT_FILENAME']); Yii::$aliases['@entry'] = dirname($_SERVER['SCRIPT_FILENAME']);
Yii::$aliases['@www'] = ''; Yii::$aliases['@www'] = '';
} }
......
...@@ -72,9 +72,9 @@ class Controller extends Component ...@@ -72,9 +72,9 @@ class Controller extends Component
* *
* ~~~ * ~~~
* return array( * return array(
* 'action1' => '@application/components/Action1', * 'action1' => '@app/components/Action1',
* 'action2' => array( * 'action2' => array(
* 'class' => '@application/components/Action2', * 'class' => '@app/components/Action2',
* 'property1' => 'value1', * 'property1' => 'value1',
* 'property2' => 'value2', * 'property2' => 'value2',
* ), * ),
...@@ -139,7 +139,7 @@ class Controller extends Component ...@@ -139,7 +139,7 @@ class Controller extends Component
} elseif ($pos > 0) { } elseif ($pos > 0) {
return $this->module->runAction($route, $params); return $this->module->runAction($route, $params);
} else { } else {
return \Yii::$application->runAction(ltrim($route, '/'), $params); return \Yii::$app->runAction(ltrim($route, '/'), $params);
} }
} }
......
...@@ -36,7 +36,7 @@ class ErrorHandler extends Component ...@@ -36,7 +36,7 @@ class ErrorHandler extends Component
public $discardExistingOutput = true; public $discardExistingOutput = true;
/** /**
* @var string the route (eg 'site/error') to the controller action that will be used to display external errors. * @var string the route (eg 'site/error') to the controller action that will be used to display external errors.
* Inside the action, it can retrieve the error information by \Yii::$application->errorHandler->error. * Inside the action, it can retrieve the error information by \Yii::$app->errorHandler->error.
* This property defaults to null, meaning ErrorHandler will handle the error display. * This property defaults to null, meaning ErrorHandler will handle the error display.
*/ */
public $errorAction; public $errorAction;
...@@ -71,14 +71,14 @@ class ErrorHandler extends Component ...@@ -71,14 +71,14 @@ class ErrorHandler extends Component
protected function render($exception) protected function render($exception)
{ {
if ($this->errorAction !== null) { if ($this->errorAction !== null) {
\Yii::$application->runAction($this->errorAction); \Yii::$app->runAction($this->errorAction);
} elseif (\Yii::$application instanceof \yii\web\Application) { } elseif (\Yii::$app instanceof \yii\web\Application) {
if (!headers_sent()) { if (!headers_sent()) {
$errorCode = $exception instanceof HttpException ? $exception->statusCode : 500; $errorCode = $exception instanceof HttpException ? $exception->statusCode : 500;
header("HTTP/1.0 $errorCode " . get_class($exception)); header("HTTP/1.0 $errorCode " . get_class($exception));
} }
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest') { if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest') {
\Yii::$application->renderException($exception); \Yii::$app->renderException($exception);
} else { } else {
$view = new View($this); $view = new View($this);
if (!YII_DEBUG || $exception instanceof UserException) { if (!YII_DEBUG || $exception instanceof UserException) {
...@@ -91,7 +91,7 @@ class ErrorHandler extends Component ...@@ -91,7 +91,7 @@ class ErrorHandler extends Component
)); ));
} }
} else { } else {
\Yii::$application->renderException($exception); \Yii::$app->renderException($exception);
} }
} }
...@@ -239,7 +239,7 @@ class ErrorHandler extends Component ...@@ -239,7 +239,7 @@ class ErrorHandler extends Component
public function htmlEncode($text) public function htmlEncode($text)
{ {
return htmlspecialchars($text, ENT_QUOTES, \Yii::$application->charset); return htmlspecialchars($text, ENT_QUOTES, \Yii::$app->charset);
} }
public function clearOutput() public function clearOutput()
......
...@@ -73,9 +73,9 @@ abstract class Module extends Component ...@@ -73,9 +73,9 @@ abstract class Module extends Component
* *
* ~~~ * ~~~
* array( * array(
* 'account' => '@application/controllers/UserController', * 'account' => '@app/controllers/UserController',
* 'article' => array( * 'article' => array(
* 'class' => '@application/controllers/PostController', * 'class' => '@app/controllers/PostController',
* 'pageTitle' => 'something new', * 'pageTitle' => 'something new',
* ), * ),
* ) * )
...@@ -311,7 +311,7 @@ abstract class Module extends Component ...@@ -311,7 +311,7 @@ abstract class Module extends Component
* *
* ~~~ * ~~~
* array( * array(
* '@models' => '@application/models', // an existing alias * '@models' => '@app/models', // an existing alias
* '@backend' => __DIR__ . '/../backend', // a directory * '@backend' => __DIR__ . '/../backend', // a directory
* ) * )
* ~~~ * ~~~
...@@ -563,10 +563,10 @@ abstract class Module extends Component ...@@ -563,10 +563,10 @@ abstract class Module extends Component
if (is_array($result)) { if (is_array($result)) {
/** @var $controller Controller */ /** @var $controller Controller */
list($controller, $actionID) = $result; list($controller, $actionID) = $result;
$oldController = Yii::$application->controller; $oldController = Yii::$app->controller;
Yii::$application->controller = $controller; Yii::$app->controller = $controller;
$status = $controller->runAction($actionID, $params); $status = $controller->runAction($actionID, $params);
Yii::$application->controller = $oldController; Yii::$app->controller = $oldController;
return $status; return $status;
} else { } else {
throw new InvalidRouteException('Unable to resolve the request: ' . trim($this->getUniqueId() . '/' . $route, '/')); throw new InvalidRouteException('Unable to resolve the request: ' . trim($this->getUniqueId() . '/' . $route, '/'));
......
...@@ -59,12 +59,12 @@ class SecurityManager extends Component ...@@ -59,12 +59,12 @@ class SecurityManager extends Component
if ($this->_validationKey !== null) { if ($this->_validationKey !== null) {
return $this->_validationKey; return $this->_validationKey;
} else { } else {
if (($key = \Yii::$application->getGlobalState(self::STATE_VALIDATION_KEY)) !== null) { if (($key = \Yii::$app->getGlobalState(self::STATE_VALIDATION_KEY)) !== null) {
$this->setValidationKey($key); $this->setValidationKey($key);
} else { } else {
$key = $this->generateRandomKey(); $key = $this->generateRandomKey();
$this->setValidationKey($key); $this->setValidationKey($key);
\Yii::$application->setGlobalState(self::STATE_VALIDATION_KEY, $key); \Yii::$app->setGlobalState(self::STATE_VALIDATION_KEY, $key);
} }
return $this->_validationKey; return $this->_validationKey;
} }
...@@ -92,12 +92,12 @@ class SecurityManager extends Component ...@@ -92,12 +92,12 @@ class SecurityManager extends Component
if ($this->_encryptionKey !== null) { if ($this->_encryptionKey !== null) {
return $this->_encryptionKey; return $this->_encryptionKey;
} else { } else {
if (($key = \Yii::$application->getGlobalState(self::STATE_ENCRYPTION_KEY)) !== null) { if (($key = \Yii::$app->getGlobalState(self::STATE_ENCRYPTION_KEY)) !== null) {
$this->setEncryptionKey($key); $this->setEncryptionKey($key);
} else { } else {
$key = $this->generateRandomKey(); $key = $this->generateRandomKey();
$this->setEncryptionKey($key); $this->setEncryptionKey($key);
\Yii::$application->setGlobalState(self::STATE_ENCRYPTION_KEY, $key); \Yii::$app->setGlobalState(self::STATE_ENCRYPTION_KEY, $key);
} }
return $this->_encryptionKey; return $this->_encryptionKey;
} }
......
...@@ -58,7 +58,7 @@ class Theme extends Component ...@@ -58,7 +58,7 @@ class Theme extends Component
if (empty($this->pathMap)) { if (empty($this->pathMap)) {
if ($this->basePath !== null) { if ($this->basePath !== null) {
$this->basePath = FileHelper::ensureDirectory($this->basePath); $this->basePath = FileHelper::ensureDirectory($this->basePath);
$this->pathMap = array(Yii::$application->getBasePath() => $this->basePath); $this->pathMap = array(Yii::$app->getBasePath() => $this->basePath);
} else { } else {
throw new InvalidConfigException("Theme::basePath must be set."); throw new InvalidConfigException("Theme::basePath must be set.");
} }
......
...@@ -112,7 +112,7 @@ use \yii\base\Component; ...@@ -112,7 +112,7 @@ use \yii\base\Component;
* </ul> * </ul>
* *
* UrlManager is a default application component that may be accessed via * UrlManager is a default application component that may be accessed via
* {@link \Yii::$application->urlManager}. * {@link \Yii::$app->urlManager}.
* *
* @property string $baseUrl The base URL of the application (the part after host name and before query string). * @property string $baseUrl The base URL of the application (the part after host name and before query string).
* If {@link showScriptName} is true, it will include the script name part. * If {@link showScriptName} is true, it will include the script name part.
...@@ -214,7 +214,7 @@ class UrlManager extends Component ...@@ -214,7 +214,7 @@ class UrlManager extends Component
{ {
if(empty($this->rules) || $this->getUrlFormat()===self::GET_FORMAT) if(empty($this->rules) || $this->getUrlFormat()===self::GET_FORMAT)
return; return;
if($this->cacheID!==false && ($cache=\Yii::$application->getComponent($this->cacheID))!==null) if($this->cacheID!==false && ($cache=\Yii::$app->getComponent($this->cacheID))!==null)
{ {
$hash=md5(serialize($this->rules)); $hash=md5(serialize($this->rules));
if(($data=$cache->get(self::CACHE_KEY))!==false && isset($data[1]) && $data[1]===$hash) if(($data=$cache->get(self::CACHE_KEY))!==false && isset($data[1]) && $data[1]===$hash)
...@@ -464,9 +464,9 @@ class UrlManager extends Component ...@@ -464,9 +464,9 @@ class UrlManager extends Component
else else
{ {
if($this->showScriptName) if($this->showScriptName)
$this->_baseUrl=\Yii::$application->getRequest()->getScriptUrl(); $this->_baseUrl=\Yii::$app->getRequest()->getScriptUrl();
else else
$this->_baseUrl=\Yii::$application->getRequest()->getBaseUrl(); $this->_baseUrl=\Yii::$app->getRequest()->getBaseUrl();
return $this->_baseUrl; return $this->_baseUrl;
} }
} }
...@@ -755,7 +755,7 @@ class CUrlRule extends CBaseUrlRule ...@@ -755,7 +755,7 @@ class CUrlRule extends CBaseUrlRule
if($this->hasHostInfo) if($this->hasHostInfo)
{ {
$hostInfo=\Yii::$application->getRequest()->getHostInfo(); $hostInfo=\Yii::$app->getRequest()->getHostInfo();
if(stripos($url,$hostInfo)===0) if(stripos($url,$hostInfo)===0)
$url=substr($url,strlen($hostInfo)); $url=substr($url,strlen($hostInfo));
} }
......
...@@ -148,7 +148,7 @@ class View extends Component ...@@ -148,7 +148,7 @@ class View extends Component
*/ */
public function renderFile($file, $params = array()) public function renderFile($file, $params = array())
{ {
$renderer = Yii::$application->getViewRenderer(); $renderer = Yii::$app->getViewRenderer();
if ($renderer !== null) { if ($renderer !== null) {
return $renderer->render($this, $file, $params); return $renderer->render($this, $file, $params);
} else { } else {
...@@ -344,7 +344,7 @@ class View extends Component ...@@ -344,7 +344,7 @@ class View extends Component
* *
* A view name can be specified in one of the following formats: * A view name can be specified in one of the following formats:
* *
* - path alias (e.g. "@application/views/site/index"); * - path alias (e.g. "@app/views/site/index");
* - absolute path within application (e.g. "//site/index"): the view name starts with double slashes. * - absolute path within application (e.g. "//site/index"): the view name starts with double slashes.
* The actual view file will be looked for under the [[Application::viewPath|view path]] of the application. * The actual view file will be looked for under the [[Application::viewPath|view path]] of the application.
* - absolute path within module (e.g. "/site/index"): the view name starts with a single slash. * - absolute path within module (e.g. "/site/index"): the view name starts with a single slash.
...@@ -374,7 +374,7 @@ class View extends Component ...@@ -374,7 +374,7 @@ class View extends Component
$view .= '.php'; $view .= '.php';
} }
if (strncmp($view, '@', 1) === 0) { if (strncmp($view, '@', 1) === 0) {
// e.g. "@application/views/common" // e.g. "@app/views/common"
if (($file = Yii::getAlias($view)) === false) { if (($file = Yii::getAlias($view)) === false) {
throw new InvalidConfigException("Invalid path alias: $view"); throw new InvalidConfigException("Invalid path alias: $view");
} }
...@@ -386,18 +386,18 @@ class View extends Component ...@@ -386,18 +386,18 @@ class View extends Component
$class = new \ReflectionClass($this->owner); $class = new \ReflectionClass($this->owner);
$file = dirname($class->getFileName()) . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . $view; $file = dirname($class->getFileName()) . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . $view;
} else { } else {
$file = Yii::$application->getViewPath() . DIRECTORY_SEPARATOR . $view; $file = Yii::$app->getViewPath() . DIRECTORY_SEPARATOR . $view;
} }
} elseif (strncmp($view, '//', 2) !== 0 && Yii::$application->controller !== null) { } elseif (strncmp($view, '//', 2) !== 0 && Yii::$app->controller !== null) {
// e.g. "/site/index" // e.g. "/site/index"
$file = Yii::$application->controller->module->getViewPath() . DIRECTORY_SEPARATOR . ltrim($view, '/'); $file = Yii::$app->controller->module->getViewPath() . DIRECTORY_SEPARATOR . ltrim($view, '/');
} else { } else {
// e.g. "//layouts/main" // e.g. "//layouts/main"
$file = Yii::$application->getViewPath() . DIRECTORY_SEPARATOR . ltrim($view, '/'); $file = Yii::$app->getViewPath() . DIRECTORY_SEPARATOR . ltrim($view, '/');
} }
if (is_file($file)) { if (is_file($file)) {
if ($this->enableTheme && ($theme = Yii::$application->getTheme()) !== null) { if ($this->enableTheme && ($theme = Yii::$app->getTheme()) !== null) {
$file = $theme->apply($file); $file = $theme->apply($file);
} }
return $this->enableI18N ? FileHelper::localize($file, $this->language, $this->sourceLanguage) : $file; return $this->enableI18N ? FileHelper::localize($file, $this->language, $this->sourceLanguage) : $file;
...@@ -423,7 +423,7 @@ class View extends Component ...@@ -423,7 +423,7 @@ class View extends Component
* *
* Like view names, a layout name can take several formats: * Like view names, a layout name can take several formats:
* *
* - path alias (e.g. "@application/views/layouts/main"); * - path alias (e.g. "@app/views/layouts/main");
* - absolute path (e.g. "/main"): the layout name starts with a slash. The actual layout file will be * - absolute path (e.g. "/main"): the layout name starts with a slash. The actual layout file will be
* looked for under the [[Application::layoutPath|layout path]] of the application; * looked for under the [[Application::layoutPath|layout path]] of the application;
* - relative path (e.g. "main"): the actual layout layout file will be looked for under the * - relative path (e.g. "main"): the actual layout layout file will be looked for under the
...@@ -444,10 +444,10 @@ class View extends Component ...@@ -444,10 +444,10 @@ class View extends Component
{ {
/** @var $module Module */ /** @var $module Module */
if (is_string($this->layout)) { if (is_string($this->layout)) {
if (Yii::$application->controller) { if (Yii::$app->controller) {
$module = Yii::$application->controller->module; $module = Yii::$app->controller->module;
} else { } else {
$module = Yii::$application; $module = Yii::$app;
} }
$view = $this->layout; $view = $this->layout;
} elseif ($this->owner instanceof Controller) { } elseif ($this->owner instanceof Controller) {
...@@ -477,13 +477,13 @@ class View extends Component ...@@ -477,13 +477,13 @@ class View extends Component
throw new InvalidConfigException("Invalid path alias: $view"); throw new InvalidConfigException("Invalid path alias: $view");
} }
} elseif (strncmp($view, '/', 1) === 0) { } elseif (strncmp($view, '/', 1) === 0) {
$file = Yii::$application->getLayoutPath() . DIRECTORY_SEPARATOR . $view; $file = Yii::$app->getLayoutPath() . DIRECTORY_SEPARATOR . $view;
} else { } else {
$file = $module->getLayoutPath() . DIRECTORY_SEPARATOR . $view; $file = $module->getLayoutPath() . DIRECTORY_SEPARATOR . $view;
} }
if (is_file($file)) { if (is_file($file)) {
if ($this->enableTheme && ($theme = Yii::$application->getTheme()) !== null) { if ($this->enableTheme && ($theme = Yii::$app->getTheme()) !== null) {
$file = $theme->apply($file); $file = $theme->apply($file);
} }
return $this->enableI18N ? FileHelper::localize($file, $this->language, $this->sourceLanguage) : $file; return $this->enableI18N ? FileHelper::localize($file, $this->language, $this->sourceLanguage) : $file;
......
...@@ -80,7 +80,7 @@ class Widget extends Component ...@@ -80,7 +80,7 @@ class Widget extends Component
* To determine which view file should be rendered, the method calls [[findViewFile()]] which * To determine which view file should be rendered, the method calls [[findViewFile()]] which
* will search in the directories as specified by [[basePath]]. * will search in the directories as specified by [[basePath]].
* *
* View name can be a path alias representing an absolute file path (e.g. `@application/views/layout/index`), * View name can be a path alias representing an absolute file path (e.g. `@app/views/layout/index`),
* or a path relative to [[basePath]]. The file suffix is optional and defaults to `.php` if not given * or a path relative to [[basePath]]. The file suffix is optional and defaults to `.php` if not given
* in the view name. * in the view name.
* *
......
...@@ -74,7 +74,7 @@ class DbCache extends Cache ...@@ -74,7 +74,7 @@ class DbCache extends Cache
public function getDb() public function getDb()
{ {
if ($this->_db === null) { if ($this->_db === null) {
$db = \Yii::$application->getComponent($this->connectionID); $db = \Yii::$app->getComponent($this->connectionID);
if ($db instanceof Connection) { if ($db instanceof Connection) {
$this->_db = $db; $this->_db = $db;
} else { } else {
......
...@@ -91,7 +91,7 @@ class DbDependency extends Dependency ...@@ -91,7 +91,7 @@ class DbDependency extends Dependency
public function getDb() public function getDb()
{ {
if ($this->_db === null) { if ($this->_db === null) {
$db = \Yii::$application->getComponent($this->connectionID); $db = \Yii::$app->getComponent($this->connectionID);
if ($db instanceof Connection) { if ($db instanceof Connection) {
$this->_db = $db; $this->_db = $db;
} else { } else {
......
...@@ -13,7 +13,7 @@ namespace yii\caching; ...@@ -13,7 +13,7 @@ namespace yii\caching;
* DummyCache is a placeholder cache component. * DummyCache is a placeholder cache component.
* *
* DummyCache does not cache anything. It is provided so that one can always configure * DummyCache does not cache anything. It is provided so that one can always configure
* a 'cache' application component and save the check of existence of `\Yii::$application->cache`. * a 'cache' application component and save the check of existence of `\Yii::$app->cache`.
* By replacing DummyCache with some other cache component, one can quickly switch from * By replacing DummyCache with some other cache component, one can quickly switch from
* non-caching mode to caching mode. * non-caching mode to caching mode.
* *
......
...@@ -28,7 +28,7 @@ class FileCache extends Cache ...@@ -28,7 +28,7 @@ class FileCache extends Cache
/** /**
* @var string the directory to store cache files. You may use path alias here. * @var string the directory to store cache files. You may use path alias here.
*/ */
public $cachePath = '@application/runtime/cache'; public $cachePath = '@app/runtime/cache';
/** /**
* @var string cache file suffix. Defaults to '.bin'. * @var string cache file suffix. Defaults to '.bin'.
*/ */
......
...@@ -55,7 +55,7 @@ class HelpController extends Controller ...@@ -55,7 +55,7 @@ class HelpController extends Controller
public function actionIndex($command = null) public function actionIndex($command = null)
{ {
if ($command !== null) { if ($command !== null) {
$result = Yii::$application->createController($command); $result = Yii::$app->createController($command);
if ($result === false) { if ($result === false) {
throw new Exception(Yii::t('yii|No help for unknown command "{command}".', array( throw new Exception(Yii::t('yii|No help for unknown command "{command}".', array(
'{command}' => $command, '{command}' => $command,
...@@ -81,7 +81,7 @@ class HelpController extends Controller ...@@ -81,7 +81,7 @@ class HelpController extends Controller
*/ */
public function getCommands() public function getCommands()
{ {
$commands = $this->getModuleCommands(Yii::$application); $commands = $this->getModuleCommands(Yii::$app);
sort($commands); sort($commands);
return array_unique($commands); return array_unique($commands);
} }
......
...@@ -70,7 +70,7 @@ class MigrateController extends Controller ...@@ -70,7 +70,7 @@ class MigrateController extends Controller
* @var string the directory storing the migration classes. This can be either * @var string the directory storing the migration classes. This can be either
* a path alias or a directory. * a path alias or a directory.
*/ */
public $migrationPath = '@application/migrations'; public $migrationPath = '@app/migrations';
/** /**
* @var string the name of the table for keeping applied migration information. * @var string the name of the table for keeping applied migration information.
*/ */
...@@ -82,7 +82,7 @@ class MigrateController extends Controller ...@@ -82,7 +82,7 @@ class MigrateController extends Controller
public $connectionID = 'db'; public $connectionID = 'db';
/** /**
* @var string the template file for generating new migrations. * @var string the template file for generating new migrations.
* This can be either a path alias (e.g. "@application/migrations/template.php") * This can be either a path alias (e.g. "@app/migrations/template.php")
* or a file path. * or a file path.
*/ */
public $templateFile = '@yii/views/migration.php'; public $templateFile = '@yii/views/migration.php';
...@@ -121,7 +121,7 @@ class MigrateController extends Controller ...@@ -121,7 +121,7 @@ class MigrateController extends Controller
} }
$this->migrationPath = $path; $this->migrationPath = $path;
$this->db = Yii::$application->getComponent($this->connectionID); $this->db = Yii::$app->getComponent($this->connectionID);
if (!$this->db instanceof Connection) { if (!$this->db instanceof Connection) {
throw new Exception("Invalid DB connection \"{$this->connectionID}\"."); throw new Exception("Invalid DB connection \"{$this->connectionID}\".");
} }
...@@ -150,7 +150,7 @@ class MigrateController extends Controller ...@@ -150,7 +150,7 @@ class MigrateController extends Controller
{ {
if (($migrations = $this->getNewMigrations()) === array()) { if (($migrations = $this->getNewMigrations()) === array()) {
echo "No new migration found. Your system is up-to-date.\n"; echo "No new migration found. Your system is up-to-date.\n";
Yii::$application->end(); Yii::$app->end();
} }
$total = count($migrations); $total = count($migrations);
...@@ -576,7 +576,7 @@ class MigrateController extends Controller ...@@ -576,7 +576,7 @@ class MigrateController extends Controller
if ($this->db !== null) { if ($this->db !== null) {
return $this->db; return $this->db;
} else { } else {
$this->db = Yii::$application->getComponent($this->connectionID); $this->db = Yii::$app->getComponent($this->connectionID);
if ($this->db instanceof Connection) { if ($this->db instanceof Connection) {
return $this->db; return $this->db;
} else { } else {
......
...@@ -96,7 +96,7 @@ class ActiveRecord extends Model ...@@ -96,7 +96,7 @@ class ActiveRecord extends Model
*/ */
public static function getDb() public static function getDb()
{ {
return \Yii::$application->getDb(); return \Yii::$app->getDb();
} }
/** /**
......
...@@ -387,7 +387,7 @@ class Command extends \yii\base\Component ...@@ -387,7 +387,7 @@ class Command extends \yii\base\Component
/** @var $cache \yii\caching\Cache */ /** @var $cache \yii\caching\Cache */
if ($db->enableQueryCache && $method !== '') { if ($db->enableQueryCache && $method !== '') {
$cache = \Yii::$application->getComponent($db->queryCacheID); $cache = \Yii::$app->getComponent($db->queryCacheID);
} }
if (isset($cache)) { if (isset($cache)) {
......
...@@ -51,7 +51,7 @@ class Migration extends \yii\base\Component ...@@ -51,7 +51,7 @@ class Migration extends \yii\base\Component
{ {
parent::init(); parent::init();
if ($this->db === null) { if ($this->db === null) {
$this->db = \Yii::$application->getComponent('db'); $this->db = \Yii::$app->getComponent('db');
} }
} }
......
...@@ -117,7 +117,7 @@ class Query extends \yii\base\Component ...@@ -117,7 +117,7 @@ class Query extends \yii\base\Component
public function createCommand($db = null) public function createCommand($db = null)
{ {
if ($db === null) { if ($db === null) {
$db = \Yii::$application->db; $db = \Yii::$app->db;
} }
$sql = $db->getQueryBuilder()->build($this); $sql = $db->getQueryBuilder()->build($this);
return $db->createCommand($sql, $this->params); return $db->createCommand($sql, $this->params);
......
...@@ -87,7 +87,7 @@ abstract class Schema extends \yii\base\Object ...@@ -87,7 +87,7 @@ abstract class Schema extends \yii\base\Object
$realName = $this->getRealTableName($name); $realName = $this->getRealTableName($name);
/** @var $cache Cache */ /** @var $cache Cache */
if ($db->enableSchemaCache && ($cache = \Yii::$application->getComponent($db->schemaCacheID)) !== null && !in_array($name, $db->schemaCacheExclude, true)) { if ($db->enableSchemaCache && ($cache = \Yii::$app->getComponent($db->schemaCacheID)) !== null && !in_array($name, $db->schemaCacheExclude, true)) {
$key = $this->getCacheKey($cache, $name); $key = $this->getCacheKey($cache, $name);
if ($refresh || ($table = $cache->get($key)) === false) { if ($refresh || ($table = $cache->get($key)) === false) {
$table = $this->loadTableSchema($realName); $table = $this->loadTableSchema($realName);
...@@ -171,7 +171,7 @@ abstract class Schema extends \yii\base\Object ...@@ -171,7 +171,7 @@ abstract class Schema extends \yii\base\Object
public function refresh() public function refresh()
{ {
/** @var $cache \yii\caching\Cache */ /** @var $cache \yii\caching\Cache */
if ($this->db->enableSchemaCache && ($cache = \Yii::$application->getComponent($this->db->schemaCacheID)) !== null) { if ($this->db->enableSchemaCache && ($cache = \Yii::$app->getComponent($this->db->schemaCacheID)) !== null) {
foreach ($this->_tables as $name => $table) { foreach ($this->_tables as $name => $table) {
$cache->delete($this->getCacheKey($cache, $name)); $cache->delete($this->getCacheKey($cache, $name));
} }
......
...@@ -10,10 +10,10 @@ class I18N extends Component ...@@ -10,10 +10,10 @@ class I18N extends Component
public function translate($message, $params = array(), $language = null) public function translate($message, $params = array(), $language = null)
{ {
if ($language === null) { if ($language === null) {
$language = Yii::$application->language; $language = Yii::$app->language;
} }
if (preg_match('/^([\w\-\.]+)\|(.*)/', $message, $matches)) { if (strpos($message, '|') !== false && preg_match('/^([\w\-\.]+)\|(.*)/', $message, $matches)) {
$category = $matches[1]; $category = $matches[1];
$message = $matches[2]; $message = $matches[2];
} else { } else {
......
...@@ -49,7 +49,7 @@ class MessageSource extends Component ...@@ -49,7 +49,7 @@ class MessageSource extends Component
{ {
parent::init(); parent::init();
if ($this->sourceLanguage === null) { if ($this->sourceLanguage === null) {
$this->sourceLanguage = Yii::$application->sourceLanguage; $this->sourceLanguage = Yii::$app->sourceLanguage;
} }
} }
......
...@@ -69,7 +69,7 @@ class DbTarget extends Target ...@@ -69,7 +69,7 @@ class DbTarget extends Target
public function getDb() public function getDb()
{ {
if ($this->_db === null) { if ($this->_db === null) {
$db = \Yii::$application->getComponent($this->connectionID); $db = \Yii::$app->getComponent($this->connectionID);
if ($db instanceof Connection) { if ($db instanceof Connection) {
$this->_db = $db; $this->_db = $db;
} else { } else {
......
...@@ -48,7 +48,7 @@ class FileTarget extends Target ...@@ -48,7 +48,7 @@ class FileTarget extends Target
{ {
parent::init(); parent::init();
if ($this->logFile === null) { if ($this->logFile === null) {
$this->logFile = \Yii::$application->getRuntimePath() . DIRECTORY_SEPARATOR . 'application.log'; $this->logFile = \Yii::$app->getRuntimePath() . DIRECTORY_SEPARATOR . 'application.log';
} else { } else {
$this->logFile = \Yii::getAlias($this->logFile); $this->logFile = \Yii::getAlias($this->logFile);
} }
......
...@@ -71,7 +71,7 @@ class CProfileLogRoute extends CWebLogRoute ...@@ -71,7 +71,7 @@ class CProfileLogRoute extends CWebLogRoute
*/ */
public function processLogs($logs) public function processLogs($logs)
{ {
$app = \Yii::$application; $app = \Yii::$app;
if (!($app instanceof CWebApplication) || $app->getRequest()->getIsAjaxRequest()) if (!($app instanceof CWebApplication) || $app->getRequest()->getIsAjaxRequest())
return; return;
......
...@@ -52,7 +52,7 @@ use yii\base\Application; ...@@ -52,7 +52,7 @@ use yii\base\Application;
* as follows: * as follows:
* *
* ~~~ * ~~~
* Yii::$application->log->targets['file']->enabled = false; * Yii::$app->log->targets['file']->enabled = false;
* ~~~ * ~~~
* *
* @author Qiang Xue <qiang.xue@gmail.com> * @author Qiang Xue <qiang.xue@gmail.com>
......
...@@ -110,7 +110,7 @@ abstract class Target extends \yii\base\Component ...@@ -110,7 +110,7 @@ abstract class Target extends \yii\base\Component
protected function getContextMessage() protected function getContextMessage()
{ {
$context = array(); $context = array();
if ($this->logUser && ($user = \Yii::$application->getComponent('user', false)) !== null) { if ($this->logUser && ($user = \Yii::$app->getComponent('user', false)) !== null) {
$context[] = 'User: ' . $user->getName() . ' (ID: ' . $user->getId() . ')'; $context[] = 'User: ' . $user->getName() . ' (ID: ' . $user->getId() . ')';
} }
......
...@@ -46,7 +46,7 @@ class CWebLogRoute extends CLogRoute ...@@ -46,7 +46,7 @@ class CWebLogRoute extends CLogRoute
*/ */
protected function render($view, $data) protected function render($view, $data)
{ {
$app = \Yii::$application; $app = \Yii::$app;
$isAjax = $app->getRequest()->getIsAjaxRequest(); $isAjax = $app->getRequest()->getIsAjaxRequest();
if ($this->showInFireBug) if ($this->showInFireBug)
......
...@@ -91,10 +91,10 @@ class FileHelper ...@@ -91,10 +91,10 @@ class FileHelper
public static function localize($file, $language = null, $sourceLanguage = null) public static function localize($file, $language = null, $sourceLanguage = null)
{ {
if ($language === null) { if ($language === null) {
$language = \Yii::$application->getLanguage(); $language = \Yii::$app->getLanguage();
} }
if ($sourceLanguage === null) { if ($sourceLanguage === null) {
$sourceLanguage = \Yii::$application->sourceLanguage; $sourceLanguage = \Yii::$app->sourceLanguage;
} }
if ($language === $sourceLanguage) { if ($language === $sourceLanguage) {
return $file; return $file;
......
...@@ -61,13 +61,13 @@ class CaptchaValidator extends Validator ...@@ -61,13 +61,13 @@ class CaptchaValidator extends Validator
public function getCaptchaAction() public function getCaptchaAction()
{ {
if (strpos($this->captchaAction, '/') !== false) { // contains controller or module if (strpos($this->captchaAction, '/') !== false) { // contains controller or module
$ca = \Yii::$application->createController($this->captchaAction); $ca = \Yii::$app->createController($this->captchaAction);
if ($ca !== null) { if ($ca !== null) {
list($controller, $actionID) = $ca; list($controller, $actionID) = $ca;
$action = $controller->createAction($actionID); $action = $controller->createAction($actionID);
} }
} else { } else {
$action = \Yii::$application->getController()->createAction($this->captchaAction); $action = \Yii::$app->getController()->createAction($this->captchaAction);
} }
if ($action === null) { if ($action === null) {
......
...@@ -82,7 +82,7 @@ class StringValidator extends Validator ...@@ -82,7 +82,7 @@ class StringValidator extends Validator
} }
if (function_exists('mb_strlen') && $this->encoding !== false) { if (function_exists('mb_strlen') && $this->encoding !== false) {
$length = mb_strlen($value, $this->encoding ? $this->encoding : \Yii::$application->charset); $length = mb_strlen($value, $this->encoding ? $this->encoding : \Yii::$app->charset);
} else { } else {
$length = strlen($value); $length = strlen($value);
} }
......
...@@ -97,7 +97,7 @@ class CAssetManager extends CApplicationComponent ...@@ -97,7 +97,7 @@ class CAssetManager extends CApplicationComponent
{ {
if($this->_basePath===null) if($this->_basePath===null)
{ {
$request=\Yii::$application->getRequest(); $request=\Yii::$app->getRequest();
$this->setBasePath(dirname($request->getScriptFile()).DIRECTORY_SEPARATOR.self::DEFAULT_BASEPATH); $this->setBasePath(dirname($request->getScriptFile()).DIRECTORY_SEPARATOR.self::DEFAULT_BASEPATH);
} }
return $this->_basePath; return $this->_basePath;
...@@ -125,7 +125,7 @@ class CAssetManager extends CApplicationComponent ...@@ -125,7 +125,7 @@ class CAssetManager extends CApplicationComponent
{ {
if($this->_baseUrl===null) if($this->_baseUrl===null)
{ {
$request=\Yii::$application->getRequest(); $request=\Yii::$app->getRequest();
$this->setBaseUrl($request->getBaseUrl().'/'.self::DEFAULT_BASEPATH); $this->setBaseUrl($request->getBaseUrl().'/'.self::DEFAULT_BASEPATH);
} }
return $this->_baseUrl; return $this->_baseUrl;
......
...@@ -59,9 +59,9 @@ class Controller extends \yii\base\Controller ...@@ -59,9 +59,9 @@ class Controller extends \yii\base\Controller
else { else {
$name = ucfirst(basename($this->id)); $name = ucfirst(basename($this->id));
if($this->action!==null && strcasecmp($this->action->id,$this->defaultAction)) if($this->action!==null && strcasecmp($this->action->id,$this->defaultAction))
return $this->_pageTitle=\Yii::$application->name.' - '.ucfirst($this->action->id).' '.$name; return $this->_pageTitle=\Yii::$app->name.' - '.ucfirst($this->action->id).' '.$name;
else else
return $this->_pageTitle=\Yii::$application->name.' - '.$name; return $this->_pageTitle=\Yii::$app->name.' - '.$name;
} }
} }
......
...@@ -87,7 +87,7 @@ class Request extends \yii\base\Request ...@@ -87,7 +87,7 @@ class Request extends \yii\base\Request
} }
if ($this->enableCsrfValidation) { if ($this->enableCsrfValidation) {
\Yii::$application->on('beginRequest', array($this, 'validateCsrfToken')); \Yii::$app->on('beginRequest', array($this, 'validateCsrfToken'));
} }
} }
......
...@@ -307,7 +307,7 @@ class CSort extends CComponent ...@@ -307,7 +307,7 @@ class CSort extends CComponent
$directions = array($attribute => $descending); $directions = array($attribute => $descending);
} }
$url = $this->createUrl(\Yii::$application->getController(), $directions); $url = $this->createUrl(\Yii::$app->getController(), $directions);
return $this->createLink($attribute, $label, $url, $htmlOptions); return $this->createLink($attribute, $label, $url, $htmlOptions);
} }
......
...@@ -126,7 +126,7 @@ class CTheme extends CComponent ...@@ -126,7 +126,7 @@ class CTheme extends CComponent
$module=$module->getParentModule(); $module=$module->getParentModule();
} }
if($module===null) if($module===null)
$layoutName=\Yii::$application->layout; $layoutName=\Yii::$app->layout;
else else
{ {
$layoutName=$module->layout; $layoutName=$module->layout;
......
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