private function matchControllerDirect($requestUrl) { /* * Seeking in classnames */ $maxMatchScore = -1; foreach ($this->getControllerPathNamesFromClassFiles() as $controllerName) { $pureControllerName = str_replace(DIRECTORY_SEPARATOR, '', $controllerName); $phpDocUrlPrefix = $this->getUrlPrefixDefinitionOverController($pureControllerName); if ($phpDocUrlPrefix !== null && $maxMatchScore < ($score = (new UrlPattern($phpDocUrlPrefix))->getMatchScoreUrl($requestUrl))) { $maxMatchScore = $score; $pattern = '@^' . $phpDocUrlPrefix . '(?!\\w+)@'; $this->controller = $pureControllerName; $theRestOfRequestUrl = preg_replace($pattern, '', $requestUrl, 1); // return the rest of request url } else { if ($maxMatchScore < ($score = (new UrlPattern('/' . $controllerName))->getMatchScoreUrl($requestUrl))) { $maxMatchScore = $score; $pattern = '@^/' . $controllerName . '(?!\\w+)@'; $this->controller = $pureControllerName; $theRestOfRequestUrl = preg_replace($pattern, '', $requestUrl, 1); // returns the rest of request url } } } /* * Seeking in parent routing items */ foreach ($this->routingCollection->getRoutingItems() as $routingItem) { if ($routingItem->isParent() && $maxMatchScore < ($score = (new UrlPattern($routingItem->getUrlPrefix()))->getMatchScoreUrl($requestUrl))) { $maxMatchScore = $score; $pattern = '@^' . $routingItem->getUrlPrefix() . '(?!\\w+)@'; $this->controller = $routingItem->getController(); $theRestOfRequestUrl = preg_replace($pattern, '', $requestUrl, 1); } } if (isset($this->controller)) { return $theRestOfRequestUrl; } return false; }
/** * Return parent routing item if this has;else null * @return RoutingItem|null */ public function getParentItem() { if ($this->hasParent()) { if (!$this->parentItem) { $routingCollection = new RoutingCollection(); $this->parentItem = $routingCollection->getRoutingItem($this->parentSlug); } return $this->parentItem; } else { return null; } }