src/Viserio/Component/Routing/Traits/MiddlewareAwareTrait.php
public function withMiddleware($middleware): MiddlewareAwareContract
    {
        $this->validateInput($middleware);

        if (\is_string($middleware) || \is_object($middleware)) {
            $className = \is_object($middleware) ? \get_class($middleware) : $middleware;

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

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

            return $this;
        }

        foreach ($middleware as $middleware) {
            $className = $this->getMiddlewareClassName($middleware);

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

            $this->middleware[$className] = $middleware;
        }

        return $this;
    }
public function withMiddleware($middleware): MiddlewareAwareContract
    {
        $this->validateInput($middleware);

        if (\is_string($middleware) || \is_object($middleware)) {
            $className = \is_object($middleware) ? \get_class($middleware) : $middleware;

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

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

            return $this;
        }

        foreach ($middleware as $middleware) {
            $className = $this->getMiddlewareClassName($middleware);

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

            $this->middleware[$className] = $middleware;
        }

        return $this;
    }
Adds a middleware or a array of middleware to the route/controller.

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

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

@return \Viserio\Component\Contract\Routing\MiddlewareAware