@ -48,28 +50,6 @@ use yii\base\InvalidCallException;
* Starting from lifecycle 3, if a PHP error or an uncaught exception occurs,
* the application will switch to its error handling logic and jump to step 6 afterwards.
*
* @property string $basePath Returns the root path of the application.
* @property CCache $cache Returns the cache component.
* @property CPhpMessageSource $coreMessages Returns the core message translations.
* @property CDateFormatter $dateFormatter Returns the locale-dependent date formatter.
* @property \yii\db\Connection $db Returns the database connection component.
* @property CErrorHandler $errorHandler Returns the error handler component.
* @property string $extensionPath Returns the root directory that holds all third-party extensions.
* @property string $id Returns the unique identifier for the application.
* @property string $language Returns the language that the user is using and the application should be targeted to.
* @property CLocale $locale Returns the locale instance.
* @property string $localeDataPath Returns the directory that contains the locale data.
* @property CMessageSource $messages Returns the application message translations component.
* @property CNumberFormatter $numberFormatter The locale-dependent number formatter.
* @property CHttpRequest $request Returns the request component.
* @property string $runtimePath Returns the directory that stores runtime files.
* @property CSecurityManager $securityManager Returns the security manager component.
* @property CStatePersister $statePersister Returns the state persister component.
* @property string $timeZone Returns the time zone used by this application.
* @property UrlManager $urlManager Returns the URL manager component.
* @property string $baseUrl Returns the relative URL for the application
* @property string $homeUrl the homepage URL
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
@ -127,12 +107,12 @@ class Application extends Module
*/
public function __construct($id, $basePath, $config = array())
{
\Yii::$application = $this;
Yii::$application = $this;
$this->id = $id;
$this->setBasePath($basePath);
$this->registerDefaultAliases();
$this->registerCoreComponents();
parent::__construct($id, $this, $config);
Component::__construct($config);
}
/**
@ -202,28 +182,6 @@ class Application extends Module
}
/**
* Runs a controller with the given route and parameters.
* @param string $route the route (e.g. `post/create`)
* @param array $params the parameters to be passed to the controller action
* @return integer the exit status (0 means normal, non-zero values mean abnormal)
* @throws BadRequestException if the route cannot be resolved into a controller
*/
public function runController($route, $params = array())
{
$result = $this->createController($route);
if ($result === false) {
throw new BadRequestException(\Yii::t('yii', 'Unable to resolve the request.'));
}
/** @var $controller Controller */
list($controller, $action) = $result;
$priorController = $this->controller;
$this->controller = $controller;
$status = $controller->run($action, $params);
$this->controller = $priorController;
return $status;
}
/**
* Returns the directory that stores runtime files.
* @return string the directory that stores runtime files. Defaults to 'protected/runtime'.
*/
@ -238,15 +196,15 @@ class Application extends Module
/**
* Sets the directory that stores runtime files.
* @param string $path the directory that stores runtime files.
* @throws InvalidCallException if the directory does not exist or is not writable
* @throws InvalidConfigException if the directory does not exist or is not writable
*/
public function setRuntimePath($path)
{
$p = \Yii::getAlias($path);
if ($p === false || !is_dir($p) || !is_writable($path)) {
throw new InvalidCallException("Application runtime path \"$path\" is invalid. Please make sure it is a directory writable by the Web server process.");
} else {
$p = FileHelper::ensureDirectory($path);
if (is_writable($p)) {
$this->_runtimePath = $p;
} else {
throw new InvalidConfigException("Runtime path must be writable by the Web server process: $path");
}
}
@ -295,34 +253,61 @@ class Application extends Module
date_default_timezone_set($value);
}
/**
* Returns the locale instance.
* @param string $localeID the locale ID (e.g. en_US). If null, the {@link getLanguage application language ID} will be used.