for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace WebComplete\core\utils\alias;
class AliasService
{
/**
* @var array
*/
protected $aliases;
* @param array|null $aliases
*
* @throws AliasException
public function __construct(array $aliases = null)
if ($aliases !== null) {
foreach ($aliases as $alias => $value) {
$this->setAlias($alias, $value);
}
* @param string $alias
* @param string $value
public function setAlias(string $alias, string $value)
if (0 !== \strpos($alias, '@')) {
throw new AliasException('Alias should starts with @');
$this->aliases[$alias] = $value;
* @return array
public function getAliases(): array
return $this->aliases;
* @param bool $throwException
* @return string|null
public function get(string $alias, $throwException = true)
return $alias;
$pos = \strpos($alias, '/');
/** @var string $root */
$root = $pos === false ? $alias : \substr($alias, 0, $pos);
if (isset($this->aliases[$root])) {
return $pos === false ? $this->aliases[$root] : $this->aliases[$root] . \substr($alias, $pos);
if ($throwException) {
throw new AliasException("Invalid alias: $alias");
return null;