public function setAlias($alias, $path)
    {
        if (strncmp($alias, '@', 1)) {
            $alias = '@' . $alias;
        }
        $pos = strpos($alias, '/');
        $root = $pos === false ? $alias : substr($alias, 0, $pos);
        if ($path !== null) {
            $path = strncmp($path, '@', 1) ? rtrim($path, '\\/') : $this->getAlias($path);
            if (!isset($this->aliases[$root])) {
                if ($pos === false) {
                    $this->aliases[$root] = $path;
                } else {
                    $this->aliases[$root] = [$alias => $path];
                }
            } elseif (is_string($this->aliases[$root])) {
                if ($pos === false) {
                    $this->aliases[$root] = $path;
                } else {
                    $this->aliases[$root] = [
                        $alias => $path,
                        $root => $this->aliases[$root],
                    ];
                }
            } else {
                $this->aliases[$root][$alias] = $path;
                krsort($this->aliases[$root]);
            }
        } elseif (isset($this->aliases[$root])) {
            if (is_array($this->aliases[$root])) {
                unset($this->aliases[$root][$alias]);
            } elseif ($pos === false) {
                unset($this->aliases[$root]);
            }
        }
    }
public function setAlias($alias, $path)
    {
        if (strncmp($alias, '@', 1)) {
            $alias = '@' . $alias;
        }
        $pos = strpos($alias, '/');
        $root = $pos === false ? $alias : substr($alias, 0, $pos);
        if ($path !== null) {
            $path = strncmp($path, '@', 1) ? rtrim($path, '\\/') : $this->getAlias($path);
            if (!isset($this->aliases[$root])) {
                if ($pos === false) {
                    $this->aliases[$root] = $path;
                } else {
                    $this->aliases[$root] = [$alias => $path];
                }
            } elseif (is_string($this->aliases[$root])) {
                if ($pos === false) {
                    $this->aliases[$root] = $path;
                } else {
                    $this->aliases[$root] = [
                        $alias => $path,
                        $root => $this->aliases[$root],
                    ];
                }
            } else {
                $this->aliases[$root][$alias] = $path;
                krsort($this->aliases[$root]);
            }
        } elseif (isset($this->aliases[$root])) {
            if (is_array($this->aliases[$root])) {
                unset($this->aliases[$root][$alias]);
            } elseif ($pos === false) {
                unset($this->aliases[$root]);
            }
        }
    }
public function setAlias ( $ alias , $ path ) { if ( strncmp ( $ alias , '@' , 1 ) ) { $ alias = '@' . $ alias ; } $ pos = strpos ( $ alias , '/' ) ; $ root = $ pos === false ? $ alias : substr ( $ alias , 0 , $ pos ) ; if ( $ path !== null ) { $ path = strncmp ( $ path , '@' , 1 ) ? rtrim ( $ path , '\\/' ) : $ this -> getAlias ( $ path ) ; if ( ! isset ( $ this -> aliases [ $ root ] ) ) { if ( $ pos === false ) { $ this -> aliases [ $ root ] = $ path ; } else { $ this -> aliases [ $ root ] = [ $ alias => $ path ] ; } } elseif ( is_string ( $ this -> aliases [ $ root ] ) ) { if ( $ pos === false ) { $ this -> aliases [ $ root ] = $ path ; } else { $ this -> aliases [ $ root ] = [ $ alias => $ path , $ root => $ this -> aliases [ $ root ] , ] ; } } else { $ this -> aliases [ $ root ] [ $ alias ] = $ path ; krsort ( $ this -> aliases [ $ root ] ) ; } } elseif ( isset ( $ this -> aliases [ $ root ] ) ) { if ( is_array ( $ this -> aliases [ $ root ] ) ) { unset ( $ this -> aliases [ $ root ] [ $ alias ] ) ; } elseif ( $ pos === false ) { unset ( $ this -> aliases [ $ root ] ) ; } } }
Registers a path alias.

A path alias is a short name representing a long path (a file path, a URL, etc.)
For example, we use '@reaction' as the alias of the path to the Reaction framework directory.

A path alias must start with the character '@' so that it can be easily differentiated
from non-alias paths.

Note that this method does not check if the given path exists or not. All it does is
to associate the alias with the path.

Any trailing '/' and '\' characters in the given path will be trimmed.

See the [guide article on aliases](guide:concept-aliases) for more information.

@param string $alias the alias name (e.g. "@yii"). It must start with a '@' character.
It may contain the forward slash '/' which serves as boundary character when performing
alias translation by [[getAlias()]].
@param string $path the path corresponding to the alias. If this is null, the alias will
be removed. Trailing '/' and '\' characters will be trimmed. This can be

- a directory or a file path (e.g. `/tmp`, `/tmp/main.txt`)
- a URL (e.g. `http://www.example.com`)
- a path alias (e.g. `@root/config`). In this case, the path alias will be converted into the
actual path first by calling [[getAlias()]].

@see getAlias()
Registers a path alias .