getParentPath() public static method

Get the parent path of the given Node path.
public static getParentPath ( string $path ) : string
$path string
return string
コード例 #1
0
 /**
  * Sets the absolute path of this node
  *
  * @param string $path
  * @param boolean $recursive
  * @return void
  * @throws \InvalidArgumentException if the given node path is invalid.
  */
 public function setPath($path, $recursive = true)
 {
     if (!is_string($path) || preg_match(NodeInterface::MATCH_PATTERN_PATH, $path) !== 1) {
         throw new \InvalidArgumentException('Invalid path "' . $path . '" (a path must be a valid string, be absolute (starting with a slash) and contain only the allowed characters).', 1284369857);
     }
     if ($path === $this->path) {
         return;
     }
     if ($recursive === true) {
         /** @var $childNodeData NodeData */
         foreach ($this->getChildNodeData() as $childNodeData) {
             $childNodeData->setPath(NodePaths::addNodePathSegment($path, $childNodeData->getName()));
         }
     }
     $pathBeforeChange = $this->path;
     $this->path = $path;
     $this->calculatePathHash();
     $this->parentPath = NodePaths::getParentPath($path);
     $this->calculateParentPathHash();
     $this->depth = NodePaths::getPathDepth($path);
     if ($pathBeforeChange !== null) {
         // this method is called both for changing the path AND in the constructor of Node; so we only want to do
         // these things below if called OUTSIDE a constructor.
         $this->emitNodePathChanged($this);
         $this->addOrUpdate();
     }
 }
コード例 #2
0
 /**
  * Replaces relative path segments ("." or "..") in a given path
  *
  * @param string $path absolute node path with relative path elements ("." or "..").
  * @return string
  */
 public static function replaceRelativePathElements($path)
 {
     $pathSegments = explode('/', $path);
     $absolutePath = '';
     foreach ($pathSegments as $pathSegment) {
         switch ($pathSegment) {
             case '.':
                 continue;
                 break;
             case '..':
                 $absolutePath = NodePaths::getParentPath($absolutePath);
                 break;
             default:
                 $absolutePath = NodePaths::addNodePathSegment($absolutePath, $pathSegment);
                 break;
         }
     }
     return $absolutePath;
 }
コード例 #3
0
 /**
  * Find NodeData by parent path without any dimension reduction and grouping by identifier
  *
  * Only used internally for setting the path of all child nodes
  *
  * @param string $parentPath
  * @param Workspace $workspace
  * @return array<\Neos\ContentRepository\Domain\Model\NodeData> A unreduced array of NodeData
  */
 public function findByParentWithoutReduce($parentPath, Workspace $workspace)
 {
     $parentPath = strtolower($parentPath);
     $workspaces = $this->collectWorkspaceAndAllBaseWorkspaces($workspace);
     $queryBuilder = $this->createQueryBuilder($workspaces);
     $this->addParentPathConstraintToQueryBuilder($queryBuilder, $parentPath);
     $query = $queryBuilder->getQuery();
     $foundNodes = $query->getResult();
     $childNodeDepth = NodePaths::getPathDepth($parentPath) + 1;
     /** @var $addedNode NodeData */
     foreach ($this->addedNodes as $addedNode) {
         if ($addedNode->getDepth() === $childNodeDepth && NodePaths::getParentPath($addedNode->getPath()) === $parentPath && in_array($addedNode->getWorkspace(), $workspaces)) {
             $foundNodes[] = $addedNode;
         }
     }
     /** @var $removedNode NodeData */
     foreach ($this->removedNodes as $removedNode) {
         if ($removedNode->getDepth() === $childNodeDepth && NodePaths::getParentPath($removedNode->getPath()) === $parentPath && in_array($removedNode->getWorkspace(), $workspaces)) {
             $foundNodes = array_filter($foundNodes, function ($nodeData) use($removedNode) {
                 return $nodeData !== $removedNode;
             });
         }
     }
     return $foundNodes;
 }