Giter Club home page Giter Club logo

aliases's Introduction

Yii 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.

Latest Stable Version Total Downloads Build Status Scrutinizer Code Quality Code Coverage Mutation testing badge static analysis

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/bit/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. http://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.

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');

Unit testing

The package is tested with PHPUnit. To run tests:

./vendor/bin/phpunit

Mutation testing

The package tests are checked with Infection mutation framework. To run it:

./vendor/bin/infection

Static analysis

The code is statically analyzed with Phan. To run static analysis:

./vendor/bin/phan

aliases's People

Contributors

damasco avatar dependabot-preview[bot] avatar samdark avatar skugarev avatar terabytesoftw avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.