‪TYPO3CMS  ‪main
TreeNodeCollection.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
20 
24 class ‪TreeNodeCollection extends \ArrayObject
25 {
34  public function ‪__construct(array $data = [])
35  {
36  parent::__construct();
37  if (!empty($data)) {
38  $this->‪dataFromArray($data);
39  }
40  }
41 
49  #[\ReturnTypeWillChange]
50  public function ‪asort(int $flags = SORT_REGULAR): bool
51  {
52  $this->uasort($this->‪nodeCompare(...));
53  return true;
54  }
55 
63  public function ‪nodeCompare(‪TreeNode $node, ‪TreeNode $otherNode)
64  {
65  return $node->‪compareTo($otherNode);
66  }
67 
71  public function ‪__serialize(): array
72  {
73  return $this->‪toArray();
74  }
75 
81  public function ‪__unserialize($arrayRepresentation): void
82  {
83  if ($arrayRepresentation['serializeClassName'] !== static::class) {
84  throw new ‪Exception('Deserialized object type is not identical!', 1294586647);
85  }
86  $this->‪dataFromArray($arrayRepresentation);
87  }
88 
94  public function ‪toArray()
95  {
96  $arrayRepresentation = [
97  'serializeClassName' => static::class,
98  ];
99  $iterator = $this->getIterator();
100  while ($iterator->valid()) {
101  $arrayRepresentation[] = $iterator->current()->toArray();
102  $iterator->next();
103  }
104  return $arrayRepresentation;
105  }
106 
112  public function ‪dataFromArray($data)
113  {
114  unset($data['serializeClassName']);
115  foreach ($data as $index => $nodeArray) {
116  $node = GeneralUtility::makeInstance($nodeArray['serializeClassName'], $nodeArray);
117  $this->offsetSet($index, $node);
118  }
119  }
120 }
‪TYPO3\CMS\Backend\Tree\TreeNodeCollection\__serialize
‪__serialize()
Definition: TreeNodeCollection.php:71
‪TYPO3\CMS\Core\Exception
Definition: Exception.php:21
‪TYPO3\CMS\Core\Exception
‪TYPO3\CMS\Backend\Tree\TreeNodeCollection\__construct
‪__construct(array $data=[])
Definition: TreeNodeCollection.php:34
‪TYPO3\CMS\Backend\Tree
Definition: AbstractTree.php:16
‪TYPO3\CMS\Backend\Tree\TreeNodeCollection\nodeCompare
‪int nodeCompare(TreeNode $node, TreeNode $otherNode)
Definition: TreeNodeCollection.php:63
‪TYPO3\CMS\Backend\Tree\TreeNodeCollection
Definition: TreeNodeCollection.php:25
‪TYPO3\CMS\Backend\Tree\TreeNode
Definition: TreeNode.php:25
‪TYPO3\CMS\Backend\Tree\TreeNodeCollection\dataFromArray
‪dataFromArray($data)
Definition: TreeNodeCollection.php:112
‪TYPO3\CMS\Backend\Tree\TreeNodeCollection\__unserialize
‪__unserialize($arrayRepresentation)
Definition: TreeNodeCollection.php:81
‪TYPO3\CMS\Backend\Tree\TreeNodeCollection\asort
‪asort(int $flags=SORT_REGULAR)
Definition: TreeNodeCollection.php:50
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Backend\Tree\TreeNode\compareTo
‪int compareTo($other)
Definition: TreeNode.php:167
‪TYPO3\CMS\Backend\Tree\TreeNodeCollection\toArray
‪array toArray()
Definition: TreeNodeCollection.php:94