src/Viserio/Component/Routing/Traits/MiddlewareAwareTrait.php
public function aliasMiddleware(string $name, $middleware)
    {
        if (isset($this->middleware[$name])) {
            throw new RuntimeException(\sprintf('Alias [%s] already exists.', $name));
        }

        if (\is_string($middleware) || \is_object($middleware)) {
            $className = $this->getMiddlewareClassName($middleware);

            if (\class_exists($className)) {
                $this->validateMiddleware($className);
            }

            $this->middleware[$name] = $middleware;

            return $this;
        }

        throw new UnexpectedValueException(\sprintf('Expected string or object; received [%s].', \gettype($middleware)));
    }
public function aliasMiddleware(string $name, $middleware)
    {
        if (isset($this->middleware[$name])) {
            throw new RuntimeException(\sprintf('Alias [%s] already exists.', $name));
        }

        if (\is_string($middleware) || \is_object($middleware)) {
            $className = $this->getMiddlewareClassName($middleware);

            if (\class_exists($className)) {
                $this->validateMiddleware($className);
            }

            $this->middleware[$name] = $middleware;

            return $this;
        }

        throw new UnexpectedValueException(\sprintf('Expected string or object; received [%s].', \gettype($middleware)));
    }
Register a short-hand name for a middleware.

@param string                                      $name
@param \Psr\Http\Server\MiddlewareInterface|string $middleware

@throws \Viserio\Component\Contract\Routing\Exception\RuntimeException         if alias exists
@throws \Viserio\Component\Contract\Routing\Exception\UnexpectedValueException if wrong type is given

@return $this