https://github.com/yiisoft/aliases
Named paths and URLs storage
https://github.com/yiisoft/aliases
alias hacktoberfest path yii3
Last synced: 4 months ago
JSON representation
Named paths and URLs storage
- Host: GitHub
- URL: https://github.com/yiisoft/aliases
- Owner: yiisoft
- License: bsd-3-clause
- Created: 2019-07-10T21:11:46.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-04-14T12:26:37.000Z (about 1 year ago)
- Last Synced: 2024-04-15T03:09:11.405Z (about 1 year ago)
- Topics: alias, hacktoberfest, path, yii3
- Language: PHP
- Homepage: https://www.yiiframework.com/
- Size: 145 KB
- Stars: 25
- Watchers: 20
- Forks: 9
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
Yii Aliases
[](https://packagist.org/packages/yiisoft/aliases)
[](https://packagist.org/packages/yiisoft/aliases)
[](https://github.com/yiisoft/aliases/actions?query=workflow%3Abuild)
[](https://scrutinizer-ci.com/g/yiisoft/aliases/?branch=master)
[](https://scrutinizer-ci.com/g/yiisoft/aliases/?branch=master)
[](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/aliases/master)
[](https://github.com/yiisoft/aliases/actions?query=workflow%3A%22static+analysis%22)
[](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 7.4 or higher.
## 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 {@see 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');
```## 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)