Commit 3e2bcfdf authored by Alexander Makarov's avatar Alexander Makarov

Refactored Module::setBasePath to remove instanceof condition

parent e8eccc28
...@@ -221,6 +221,18 @@ abstract class Application extends Module ...@@ -221,6 +221,18 @@ abstract class Application extends Module
return ''; return '';
} }
/**
* Sets the root directory of the applicaition and the @app alias.
* This method can only be invoked at the beginning of the constructor.
* @param string $path the root directory of the application.
* @throws InvalidParamException if the directory does not exist.
*/
public function setBasePath($path)
{
parent::setBasePath($path);
Yii::setAlias('@app', $this->getBasePath());
}
/** /**
* Runs the application. * Runs the application.
* This is the main entrance of an application. * This is the main entrance of an application.
......
...@@ -217,9 +217,6 @@ abstract class Module extends Component ...@@ -217,9 +217,6 @@ abstract class Module extends Component
$p = realpath($path); $p = realpath($path);
if ($p !== false && is_dir($p)) { if ($p !== false && is_dir($p)) {
$this->_basePath = $p; $this->_basePath = $p;
if ($this instanceof Application) {
Yii::setAlias('@app', $p);
}
} else { } else {
throw new InvalidParamException("The directory does not exist: $path"); throw new InvalidParamException("The directory does not exist: $path");
} }
......
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