Skip to content

Commit

Permalink
GeneralConfig::addAlias()
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Jul 13, 2024
1 parent eb47a44 commit ee9ffd2
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions src/config/GeneralConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class GeneralConfig extends BaseConfig
public bool $addTrailingSlashesToUrls = false;

/**
* @var array Any custom Yii [aliases](https://www.yiiframework.com/doc/guide/2.0/en/concept-aliases) that should be defined for every request.
* @var array<string,string|null> Any custom Yii [aliases](https://www.yiiframework.com/doc/guide/2.0/en/concept-aliases) that should be defined for every request.
*
* ```php Static Config
* ->aliases([
Expand Down Expand Up @@ -3386,14 +3386,40 @@ public function addTrailingSlashesToUrls(bool $value = true): self
* ```
*
* @group Environment
* @param array $value
* @param array<string,string|null> $value
* @return self
* @see $aliases
* @since 4.2.0
*/
public function aliases(array $value): self
{
$this->aliases = $value;
$this->aliases = [];
foreach ($value as $name => $path) {
$this->addAlias($name, $path);
}
return $this;
}

/**
* Adds a custom Yii [alias](https://www.yiiframework.com/doc/guide/2.0/en/concept-aliases) that should be defined for every request.
*
* ```php
* ->addAlias('@webroot', '/var/www/')
* ```
*
* @group Environment
* @param string $name
* @param string|null $path
* @return self
* @see $aliases
* @since 4.2.0
*/
public function addAlias(string $name, ?string $path): self
{
if (!str_starts_with($name, '@')) {
$name = "@$name";
}
$this->aliases[$name] = $path;
return $this;
}

Expand Down

0 comments on commit ee9ffd2

Please sign in to comment.