# aliases
**Repository Path**: mirrors_yiisoft/aliases
## Basic Information
- **Project Name**: aliases
- **Description**: Named paths and URLs storage
- **Primary Language**: Unknown
- **License**: BSD-3-Clause
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2020-08-19
- **Last Updated**: 2026-02-14
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
Yii Aliases
[](https://packagist.org/packages/yiisoft/aliases)
[](https://packagist.org/packages/yiisoft/aliases)
[](https://github.com/yiisoft/aliases/actions/workflows/build.yml)
[](https://codecov.io/gh/yiisoft/aliases)
[](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/aliases/master)
[](https://github.com/yiisoft/aliases/actions/workflows/static.yml?query=branch%3Amaster)
[](https://shepherd.dev/github/yiisoft/aliases)
The package aim is to store path aliases, i.e. short name representing a long path (a file path, a URL, etc.).
Path alias value may have another value as its part. For example, `@vendor` may store path to `vendor` directory
while `@bin` may store `@vendor/bin`.
## Requirements
- PHP 8.1 - 8.5.
## Installation
The package could be installed with [Composer](https://getcomposer.org):
```shell
composer require yiisoft/aliases
```
## General usage
A path alias must start with the character '@' so that it can be easily differentiated from non-alias paths.
```php
use Yiisoft\Aliases\Aliases;
$aliases = new Aliases([
'@root' => __DIR__,
]);
$aliases->set('@vendor', '@root/vendor');
$aliases->set('@bin', '@vendor/bin');
echo $aliases->get('@bin/phpunit');
```
The code about would output "/path/to/vendor/bin/phpunit".
Note that `set()` method does not check if the given path exists or not. All it does is to associate the alias with
the path.
The path could be:
- a directory or a file path (e.g. `/tmp`, `/tmp/main.txt`)
- a URL (e.g. `https://www.yiiframework.com`)
- a path alias (e.g. `@yii/base`). It will be resolved on `get()` call.
Any trailing `/` and `\` characters in the given path will be trimmed.
To bulk translate path aliases into actual paths use `getArray()` method:
```php
$aliases = new Aliases([
'@root' => '/my/app',
]);
// Value will be ['src' => '/my/app/src', 'tests' => '/my/app/tests']
$directories = $aliases->getAll(['src' => '@root/src', 'tests' => '@root/tests']);
```
### Alias priorities
In case multiple aliases are registered with same root (prefix), then the most specific has precedence:
```php
use Yiisoft\Aliases\Aliases;
$aliases = new Aliases([
'@vendor' => __DIR__ . '/vendor',
'@vendor/test' => '/special/location'
]);
echo $aliases->get('@vendor/test');
```
That would output `/special/location` since `@vendor/test` is more specific match than `@vendor`.
### Alias removal
If you need to remove alias runtime:
```php
use Yiisoft\Aliases\Aliases;
$aliases = new Aliases([
'@root' => __DIR__,
]);
$aliases->remove('@root');
```
### Alias references
The package provides `AliasReference` class that implements `ReferenceInterface` from
[Yii Definition](https://github.com/yiisoft/definitions). It allows you to create references to aliases
that will be resolved at runtime:
```php
// Create a reference to an alias
$reference = \Yiisoft\Aliases\AliasReference::to('@public/assets');
// The reference will be resolved when needed
$configPath = $reference->resolve($container);
```
This is particularly useful in dependency injection configurations where you want to inject resolved paths
but the aliases are not available at configuration time.
## Documentation
- [Internals](docs/internals.md)
If you need help or have a question, the [Yii Forum](https://forum.yiiframework.com/c/yii-3-0/63) is a good place for that.
You may also check out other [Yii Community Resources](https://www.yiiframework.com/community).
## License
The Yii Aliases is free software. It is released under the terms of the BSD License.
Please see [`LICENSE`](./LICENSE.md) for more information.
Maintained by [Yii Software](https://www.yiiframework.com/).
## Support the project
[](https://opencollective.com/yiisoft)
## Follow updates
[](https://www.yiiframework.com/)
[](https://twitter.com/yiiframework)
[](https://t.me/yii3en)
[](https://www.facebook.com/groups/yiitalk)
[](https://yiiframework.com/go/slack)