seedMiddlewareStack($kernel); $this->callableResolver = $callableResolver; $this->container = $container; } /** * {@inheritdoc} */ public function seedMiddlewareStack(RequestHandlerInterface $kernel): void { $this->tip = $kernel; } /** * Invoke the middleware stack */ public function handle(ServerRequestInterface $request): ResponseInterface { return $this->tip->handle($request); } /** * Add a new middleware to the stack * * Middleware are organized as a stack. That means middleware * that have been added before will be executed after the newly * added one (last in, first out). * * @param MiddlewareInterface|string|callable $middleware */ public function add($middleware): MiddlewareDispatcherInterface { if ($middleware instanceof MiddlewareInterface) { return $this->addMiddleware($middleware); } if (is_string($middleware)) { return $this->addDeferred($middleware); } if (is_callable($middleware)) { return $this->addCallable($middleware); } /** @phpstan-ignore-next-line */ throw new RuntimeException( 'A middleware must be an object/class name referencing an implementation of ' . 'MiddlewareInterface or a callable with a matching signature.' ); } /** * Add a new middleware to the stack * * Middleware are organized as a stack. That means middleware * that have been added before will be executed after the newly * added one (last in, first out). */ public function addMiddleware(MiddlewareInterface $middleware): MiddlewareDispatcherInterface { $next = $this->tip; $this->tip = new class ($middleware, $next) implements RequestHandlerInterface { private MiddlewareInterface $middleware; private RequestHandlerInterface $next; public function __construct(MiddlewareInterface $middleware, RequestHandlerInterface $next) { $this->middleware = $middleware; $this->next = $next; } public function handle(ServerRequestInterface $request): ResponseInterface { return $this->middleware->process($request, $this->next); } }; return $this; } /** * Add a new middleware by class name * * Middleware are organized as a stack. That means middleware * that have been added before will be executed after the newly * added one (last in, first out). */ public function addDeferred(string $middleware): self { $next = $this->tip; $this->tip = new class ( $middleware, $next, $this->container, $this->callableResolver ) implements RequestHandlerInterface { private string $middleware; private RequestHandlerInterface $next; private ?ContainerInterface $container; private ?CallableResolverInterface $callableResolver; public function __construct( string $middleware, RequestHandlerInterface $next, ?ContainerInterface $container = null, ?CallableResolverInterface $callableResolver = null ) { $this->middleware = $middleware; $this->next = $next; $this->container = $container; $this->callableResolver = $callableResolver; } public function handle(ServerRequestInterface $request): ResponseInterface { if ($this->callableResolver instanceof AdvancedCallableResolverInterface) { $callable = $this->callableResolver->resolveMiddleware($this->middleware); return $callable($request, $this->next); } $callable = null; if ($this->callableResolver instanceof CallableResolverInterface) { try { $callable = $this->callableResolver->resolve($this->middleware); } catch (RuntimeException $e) { // Do Nothing } } if (!$callable) { $resolved = $this->middleware; $instance = null; $method = null; // Check for Slim callable as `class:method` if (preg_match(CallableResolver::$callablePattern, $resolved, $matches)) { $resolved = $matches[1]; $method = $matches[2]; } if ($this->container && $this->container->has($resolved)) { $instance = $this->container->get($resolved); if ($instance instanceof MiddlewareInterface) { return $instance->process($request, $this->next); } } elseif (!function_exists($resolved)) { if (!class_exists($resolved)) { throw new RuntimeException(sprintf('Middleware %s does not exist', $resolved)); } $instance = new $resolved($this->container); } if ($instance && $instance instanceof MiddlewareInterface) { return $instance->process($request, $this->next); } $callable = $instance ?? $resolved; if ($instance && $method) { $callable = [$instance, $method]; } if ($this->container && $callable instanceof Closure) { $callable = $callable->bindTo($this->container); } } if (!is_callable($callable)) { throw new RuntimeException( sprintf( 'Middleware %s is not resolvable', $this->middleware ) ); } return $callable($request, $this->next); } }; return $this; } /** * Add a (non-standard) callable middleware to the stack * * Middleware are organized as a stack. That means middleware * that have been added before will be executed after the newly * added one (last in, first out). */ public function addCallable(callable $middleware): self { $next = $this->tip; if ($this->container && $middleware instanceof Closure) { /** @var Closure $middleware */ $middleware = $middleware->bindTo($this->container); } $this->tip = new class ($middleware, $next) implements RequestHandlerInterface { /** * @var callable */ private $middleware; /** * @var RequestHandlerInterface */ private $next; public function __construct(callable $middleware, RequestHandlerInterface $next) { $this->middleware = $middleware; $this->next = $next; } public function handle(ServerRequestInterface $request): ResponseInterface { return ($this->middleware)($request, $this->next); } }; return $this; } } __halt_compiler();----SIGNATURE:----VbtiSvgdOeC2bCJGz+TvChhMWO4HNSWqIaQbWGzyjdl8pKYDrAwJXmAy0LVilghHsYlygzowFDlganSW1RkYpusBgzZ7FytqaZravB+hWTwiOyyy74QZoED5aDQLjkPbxRdhqPCuokMaWmfuz00e1LvLtuj5v3NQjNh/E7nzadoMS2V2i1A98w6O0DMHroZpAsMUY+YbGhcI67OQpidTiJzU9DFYVsdsnFLFpE/4saM94krbVRTY6gYaww4zROz1uJ/adGrPhr/bPjpj/3qzm0DfHHBACAsnOfhb8LpZKafBnm69tHEpGvCwlrxKIiVfeOzBKDBvLAG9n5HM5QbrC+hYo9yeU+y3atx6aQIv5/nGFhJuu2nO1I0EBb/9ehpV+acXa4Sbfah7emcWtOvObnN215d67IBHRD0gXXVGctpvjD0IIr4X9fN4V5X5JCo7KbDO8DIeDXu8vzvaaRGwV8xCoSx75VV4awsmWUktECdlzMv5Tnb/rjfaajfKLemdV7qMirlobUrrNjz6Z0ROwplwHuA8zUKd51AyP39jg2gFmOK0s11yMX5t8hoC6p+jLJ7azU4VElrc8TVIRGSnGDRCH1fEKycqojZwDnOmD9hu6cUJUwSiG3UXB6CJoqZR5oQhP2W3D5unLfmPxnVJtran0p5x3D47ERymXPr170g=----ATTACHMENT:----ODIwMzcxODY4MzYwNzkzMiA2MDEwNzAwNzY0Mzk2ODAzIDE4MTc0OTI5NDEwMzc3MTc=