‪TYPO3CMS  ‪main
CurrentObjectPath.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
22 
32 {
36  private array ‪$path;
37 
39  {
40  $this->path = ‪$path;
41  }
42 
43  public function ‪append(‪NodeInterface $node): void
44  {
45  $this->path[] = $node;
46  }
47 
51  public function ‪getAll(): array
52  {
53  return ‪$this->path;
54  }
55 
64  public function ‪getPathAsString(): string
65  {
66  $flatArray = [];
67  foreach ($this->‪getAll() as $pathNode) {
68  if ($pathNode instanceof ‪RootNode) {
69  continue;
70  }
71  $name = $pathNode->getName();
72  if ($name === '') {
73  throw new \RuntimeException('Node names must not be empty string', 1658578645);
74  }
75  $flatArray[] = addcslashes($name, '.');
76  }
77  return implode('.', $flatArray);
78  }
79 
80  public function ‪getFirst(): ‪NodeInterface
81  {
82  return reset($this->path);
83  }
84 
85  public function ‪getLast(): ‪NodeInterface
86  {
87  return $this->path[array_key_last($this->path)];
88  }
89 
91  {
92  return array_slice($this->path, -2, 1)[0];
93  }
94 
95  public function ‪removeLast(): void
96  {
97  array_pop($this->path);
98  }
99 }
‪TYPO3\CMS\Core\TypoScript\AST\CurrentObjectPath\CurrentObjectPath\getFirst
‪getFirst()
Definition: CurrentObjectPath.php:80
‪TYPO3\CMS\Core\TypoScript\AST\CurrentObjectPath\CurrentObjectPath\getSecondLast
‪getSecondLast()
Definition: CurrentObjectPath.php:90
‪TYPO3\CMS\Core\TypoScript\AST\CurrentObjectPath\CurrentObjectPath\removeLast
‪removeLast()
Definition: CurrentObjectPath.php:95
‪TYPO3\CMS\Core\TypoScript\AST\CurrentObjectPath
Definition: CurrentObjectPath.php:18
‪TYPO3\CMS\Core\TypoScript\AST\Node\NodeInterface
Definition: NodeInterface.php:35
‪TYPO3\CMS\Core\TypoScript\AST\CurrentObjectPath\CurrentObjectPath\append
‪append(NodeInterface $node)
Definition: CurrentObjectPath.php:43
‪TYPO3\CMS\Core\TypoScript\AST\CurrentObjectPath\CurrentObjectPath\getAll
‪NodeInterface[] getAll()
Definition: CurrentObjectPath.php:51
‪TYPO3\CMS\Core\TypoScript\AST\CurrentObjectPath\CurrentObjectPath\getPathAsString
‪getPathAsString()
Definition: CurrentObjectPath.php:64
‪TYPO3\CMS\Core\TypoScript\AST\CurrentObjectPath\CurrentObjectPath
Definition: CurrentObjectPath.php:32
‪TYPO3\CMS\Core\TypoScript\AST\Node\RootNode
Definition: RootNode.php:26
‪TYPO3\CMS\Core\TypoScript\AST\CurrentObjectPath\CurrentObjectPath\$path
‪array $path
Definition: CurrentObjectPath.php:36
‪TYPO3\CMS\Core\TypoScript\AST\CurrentObjectPath\CurrentObjectPath\getLast
‪getLast()
Definition: CurrentObjectPath.php:85
‪TYPO3\CMS\Core\TypoScript\AST\CurrentObjectPath\CurrentObjectPath\__construct
‪__construct(NodeInterface ... $path)
Definition: CurrentObjectPath.php:38