/** * Make a sitetree model * * @param \Cmsable\Routing\TreeScope\TreeScope $scope * @return \Cmsable\Model\SiteTreeModelInterface **/ protected function makeModel(TreeScope $scope) { $model = clone $this->treeModelPrototype; $model->setRootId($scope->getModelRootId()); $model->setPathPrefix($scope->getPathPrefix()); return $model; }
public function getFirstMatchingNode(TreeScope $scope, $originalPath) { $pathPrefix = $this->cleanPathPrefix($scope->getPathPrefix()); $path = $this->getTranslatedPath($originalPath, $pathPrefix); $treeModel = $this->treeManager->get($scope); // If $path matches a node path return it if ($node = $treeModel->pageByPath($path)) { return $node; } else { $requestSegments = explode('/', $path); $pathStack = array(); $i = 0; foreach ($requestSegments as $segment) { $pathStack[] = $segment; $currentPath = implode('/', $pathStack); if ($this->isPathPrefix($segment, $pathPrefix, $i)) { continue; } $pathExists = $treeModel->pathExists($currentPath); if (!$pathExists && $i == 0) { return; } // if the first segment if (!$treeModel->pathExists($currentPath)) { array_pop($pathStack); $parentPath = implode('/', $pathStack); return $treeModel->pageByPath($parentPath); } $i++; } } }
/** * Adds the passed scope to the scope array * * @param \Cmsable\Routing\TreeScope\TreeScope $treeScope * @return void **/ protected function addToScopes(TreeScope $scope) { $this->scopes[] = $scope; $this->scopeByName[$scope->getName()] = $scope; $this->scopeByModelRootId[$scope->getModelRootId()] = $scope; $this->scopeByPathPrefix[$scope->getPathPrefix()] = $scope; }