mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-16 23:48:16 +08:00
Implemented "@app/runtime" alias.
This commit is contained in:
@ -67,30 +67,12 @@ class Application extends Module
|
||||
* Constructor.
|
||||
* @param array $config name-value pairs that will be used to initialize the object properties.
|
||||
* Note that the configuration must contain both [[id]] and [[basePath]].
|
||||
* @throws InvalidConfigException if either [[id]] or [[basePath]] configuration is missing.
|
||||
*/
|
||||
public function __construct($config = array())
|
||||
{
|
||||
Yii::$app = $this;
|
||||
|
||||
if (!isset($config['id'])) {
|
||||
throw new InvalidConfigException('The "id" configuration is required.');
|
||||
}
|
||||
|
||||
if (isset($config['basePath'])) {
|
||||
$this->setBasePath($config['basePath']);
|
||||
Yii::setAlias('@app', $this->getBasePath());
|
||||
unset($config['basePath']);
|
||||
} else {
|
||||
throw new InvalidConfigException('The "basePath" configuration is required.');
|
||||
}
|
||||
|
||||
if (isset($config['timeZone'])) {
|
||||
$this->setTimeZone($config['timeZone']);
|
||||
unset($config['timeZone']);
|
||||
} elseif (!ini_get('date.timezone')) {
|
||||
$this->setTimeZone('UTC');
|
||||
}
|
||||
$this->preInit($config);
|
||||
|
||||
$this->registerErrorHandlers();
|
||||
$this->registerCoreComponents();
|
||||
@ -98,6 +80,42 @@ class Application extends Module
|
||||
Component::__construct($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pre-initializes the application.
|
||||
* This method is called at the beginning of the application constructor.
|
||||
* When this method is called, none of the application properties are initialized yet.
|
||||
* The default implementation will initialize a few important properties
|
||||
* that may be referenced during the initialization of the rest of the properties.
|
||||
* @param array $config the application configuration
|
||||
* @throws InvalidConfigException if either [[id]] or [[basePath]] configuration is missing.
|
||||
*/
|
||||
public function preInit($config)
|
||||
{
|
||||
if (!isset($config['id'])) {
|
||||
throw new InvalidConfigException('The "id" configuration is required.');
|
||||
}
|
||||
if (!isset($config['basePath'])) {
|
||||
throw new InvalidConfigException('The "basePath" configuration is required.');
|
||||
}
|
||||
|
||||
$this->setBasePath($config['basePath']);
|
||||
Yii::setAlias('@app', $this->getBasePath());
|
||||
unset($config['basePath']);
|
||||
|
||||
if (isset($config['runtime'])) {
|
||||
$this->setRuntimePath($config['runtime']);
|
||||
unset($config['runtime']);
|
||||
}
|
||||
Yii::setAlias('@app/runtime', $this->getRuntimePath());
|
||||
|
||||
if (isset($config['timeZone'])) {
|
||||
$this->setTimeZone($config['timeZone']);
|
||||
unset($config['timeZone']);
|
||||
} elseif (!ini_get('date.timezone')) {
|
||||
$this->setTimeZone('UTC');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers error handlers.
|
||||
*/
|
||||
|
@ -27,7 +27,7 @@ class FileCache extends Cache
|
||||
* @var string the directory to store cache files. You may use path alias here.
|
||||
* If not set, it will use the "cache" subdirectory under the application runtime path.
|
||||
*/
|
||||
public $cachePath;
|
||||
public $cachePath = '@app/runtime/cache';
|
||||
/**
|
||||
* @var string cache file suffix. Defaults to '.bin'.
|
||||
*/
|
||||
@ -52,11 +52,7 @@ class FileCache extends Cache
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
if ($this->cachePath === null) {
|
||||
$this->cachePath = Yii::$app->getRuntimePath() . DIRECTORY_SEPARATOR . 'cache';
|
||||
} else {
|
||||
$this->cachePath = Yii::getAlias($this->cachePath);
|
||||
}
|
||||
$this->cachePath = Yii::getAlias($this->cachePath);
|
||||
if (!is_dir($this->cachePath)) {
|
||||
mkdir($this->cachePath, 0777, true);
|
||||
}
|
||||
|
Reference in New Issue
Block a user