public function alias($original, $alias)
    {
        if (empty($original) || ! is_string($original)) {
            throw new ConfigException(
                InjectorException::M_NON_EMPTY_STRING_ALIAS,
                InjectorException::E_NON_EMPTY_STRING_ALIAS
            );
        }
        if (empty($alias) || ! is_string($alias)) {
            throw new ConfigException(
                InjectorException::M_NON_EMPTY_STRING_ALIAS,
                InjectorException::E_NON_EMPTY_STRING_ALIAS
            );
        }

        $originalNormalized = $this->normalizeName($original);

        if (isset($this->shares[$originalNormalized])) {
            throw new ConfigException(
                sprintf(
                    InjectorException::M_SHARED_CANNOT_ALIAS,
                    $this->normalizeName(get_class($this->shares[$originalNormalized])),
                    $alias
                ),
                InjectorException::E_SHARED_CANNOT_ALIAS
            );
        }

        if (array_key_exists($originalNormalized, $this->shares)) {
            $aliasNormalized                = $this->normalizeName($alias);
            $this->shares[$aliasNormalized] = null;
            unset($this->shares[$originalNormalized]);
        }

        $this->aliases[$originalNormalized] = $alias;

        return $this;
    }
public function alias($original, $alias)
    {
        if (empty($original) || ! is_string($original)) {
            throw new ConfigException(
                InjectorException::M_NON_EMPTY_STRING_ALIAS,
                InjectorException::E_NON_EMPTY_STRING_ALIAS
            );
        }
        if (empty($alias) || ! is_string($alias)) {
            throw new ConfigException(
                InjectorException::M_NON_EMPTY_STRING_ALIAS,
                InjectorException::E_NON_EMPTY_STRING_ALIAS
            );
        }

        $originalNormalized = $this->normalizeName($original);

        if (isset($this->shares[$originalNormalized])) {
            throw new ConfigException(
                sprintf(
                    InjectorException::M_SHARED_CANNOT_ALIAS,
                    $this->normalizeName(get_class($this->shares[$originalNormalized])),
                    $alias
                ),
                InjectorException::E_SHARED_CANNOT_ALIAS
            );
        }

        if (array_key_exists($originalNormalized, $this->shares)) {
            $aliasNormalized                = $this->normalizeName($alias);
            $this->shares[$aliasNormalized] = null;
            unset($this->shares[$originalNormalized]);
        }

        $this->aliases[$originalNormalized] = $alias;

        return $this;
    }
public function alias ( $ original , $ alias ) { if ( empty ( $ original ) || ! is_string ( $ original ) ) { throw new ConfigException ( InjectorException :: M_NON_EMPTY_STRING_ALIAS , InjectorException :: E_NON_EMPTY_STRING_ALIAS ) ; } if ( empty ( $ alias ) || ! is_string ( $ alias ) ) { throw new ConfigException ( InjectorException :: M_NON_EMPTY_STRING_ALIAS , InjectorException :: E_NON_EMPTY_STRING_ALIAS ) ; } $ originalNormalized = $ this -> normalizeName ( $ original ) ; if ( isset ( $ this -> shares [ $ originalNormalized ] ) ) { throw new ConfigException ( sprintf ( InjectorException :: M_SHARED_CANNOT_ALIAS , $ this -> normalizeName ( get_class ( $ this -> shares [ $ originalNormalized ] ) ) , $ alias ) , InjectorException :: E_SHARED_CANNOT_ALIAS ) ; } if ( array_key_exists ( $ originalNormalized , $ this -> shares ) ) { $ aliasNormalized = $ this -> normalizeName ( $ alias ) ; $ this -> shares [ $ aliasNormalized ] = null ; unset ( $ this -> shares [ $ originalNormalized ] ) ; } $ this -> aliases [ $ originalNormalized ] = $ alias ; return $ this ; }
Define an alias for all occurrences of a given typehint

Use this method to specify implementation classes for interface and abstract class typehints.

@param string $original The typehint to replace
@param string $alias    The implementation name

@throws ConfigException if any argument is empty or not a string
@return InjectorInterface
Define an alias for all occurrences of a given typehint