/** * Returns whether page should be considered active or not * * This method will compare the page properties against the route matches * composed in the object. * * @param bool $recursive [optional] whether page should be considered * active if any child pages are active. Default is * false. * @return bool whether page should be considered active or not */ public function isActive($recursive = false) { if (!$this->active) { $reqParams = []; if ($this->routeMatch instanceof RouteMatch || $this->routeMatch instanceof MvcRouter\RouteMatch) { $reqParams = $this->routeMatch->getParams(); if (isset($reqParams[self::ORIGINAL_CONTROLLER])) { $reqParams['controller'] = $reqParams[self::ORIGINAL_CONTROLLER]; } $pageParams = $this->params; if (null !== $this->controller) { $pageParams['controller'] = $this->controller; } if (null !== $this->action) { $pageParams['action'] = $this->action; } if (null !== $this->getRoute()) { if ($this->routeMatch->getMatchedRouteName() === $this->getRoute() && count(array_intersect_assoc($reqParams, $pageParams)) == count($pageParams)) { $this->active = true; return $this->active; } else { return parent::isActive($recursive); } } } $pageParams = $this->params; if (null !== $this->controller) { $pageParams['controller'] = $this->controller; } else { /** * @todo In ZF1, this was configurable and pulled from the front controller */ $pageParams['controller'] = 'index'; } if (null !== $this->action) { $pageParams['action'] = $this->action; } else { /** * @todo In ZF1, this was configurable and pulled from the front controller */ $pageParams['action'] = 'index'; } if (count(array_intersect_assoc($reqParams, $pageParams)) == count($pageParams)) { $this->active = true; return true; } } return parent::isActive($recursive); }
/** * Create a successful RouteResult from the given RouteMatch. * * @param RouteMatch $match * @return RouteResult */ private function marshalSuccessResultFromRouteMatch(RouteMatch $match) { $params = $match->getParams(); if (array_key_exists(self::METHOD_NOT_ALLOWED_ROUTE, $params)) { return RouteResult::fromRouteFailure($this->allowedMethodsByPath[$params[self::METHOD_NOT_ALLOWED_ROUTE]]); } return RouteResult::fromRouteMatch($this->getMatchedRouteName($match->getMatchedRouteName()), $params['middleware'], $params); }