Get support for yiisoft/aliases
If you're new to LTH, please see our FAQ for more information on what it is we do.
Support Options
Unfortunately, there are currently no active helpers for this repository on the platform. Until they become available, we reccomend the following actions:
View Open IssuesTake a look to see if anyone else has experienced the same issue as you and if they managed to solve it.
Open an IssueMake sure to read any relevant guidelines for opening issues on this repo before posting a new issue.
Sponsor directlyCheck out the page and see if there are any options to sponsor this project or it's developers directly.
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:
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.
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:
$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:
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:
use Yiisoft\Aliases\Aliases;
$aliases = new Aliases([
'@root' => __DIR__,
]);
$aliases->remove('@root');
Documentation
If you need help or have a question, the Yii Forum is a good place for that. You may also check out other Yii Community Resources.
License
The Yii Aliases is free software. It is released under the terms of the BSD License.
Please see LICENSE
for more information.
Maintained by Yii Software.
Support the project
Follow updates
Our Mission
We want to make open source more sustainable. The entire platform was born from this and everything we do is in aid of this.
From the Blog
Interesting Articles
-
Generating income from open source
Jun 23 • 8 min read
-
2023 State of OSS
Apr 23 • 45 min read ★
-
A funding experiment...
Aug 19 • 10 min read
-
But You Said I could
Aug 19 • 2 min read
Thank you for checking out LiveTechHelper |
2025 © lth-dev incorporated
p-e622a1a2