getParameter(MiddlewareContext::PARAM_MIDDLEWARE_ID); $route = $context->getParameter(MiddlewareContext::PARAM_ROUTE); $map = $this->getMiddlewareHandler()->getOption(MiddlewareRequestHandler::OPTION_MAP); $this->getMiddlewareHandler()->setOption( MiddlewareRequestHandler::OPTION_MAP, array_merge_recursive($map, [$route => [$middlewareId]]) ); return $this; } public function detach(ContextInterface $context): self { $middlewareId = $context->getParameter(MiddlewareContext::PARAM_MIDDLEWARE_ID); $route = $context->getParameter(MiddlewareContext::PARAM_ROUTE); $map = $this->getMiddlewareHandler()->getOption(MiddlewareRequestHandler::OPTION_MAP); if ($middlewareId && $route) { $routed = $map[$route]; if (($key = array_search( $middlewareId, $routed )) !== false) { unset($routed[$key]); $map[$route] = $routed; } } if ($route && !$middlewareId) { unset($map[$route]); } $this->getMiddlewareHandler()->setOption(MiddlewareRequestHandler::OPTION_MAP, array_filter($map)); return $this; } public function getMiddlewareHandler(): MiddlewareRequestHandler { if ($this->getServiceManager()->has(MiddlewareRequestHandler::SERVICE_ID)) { return $this->getServiceManager()->get(MiddlewareRequestHandler::SERVICE_ID); } return new MiddlewareRequestHandler(); } }