public function add($middleware, string $pathConstraint = null): void
    {
        if (is_string($middleware)) {
            $middleware = $this->getContainer()->get($middleware);
        }

        if (!$middleware instanceof MiddlewareInterface) {
            throw new InvalidArgumentException('Middleware must be an instance of ' . MiddlewareInterface::class);
        }

        $this->middleware[] = new Middleware($middleware, $pathConstraint);
    }