‪TYPO3CMS  11.5
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 
48  #[\ReturnTypeWillChange]
49  public function ‪asort($flags = SORT_REGULAR)
50  {
51  $this->uasort([$this, 'nodeCompare']);
52  }
53 
63  public function ‪nodeCompare(‪TreeNode $node, ‪TreeNode $otherNode)
64  {
65  return $node->‪compareTo($otherNode);
66  }
67 
74  #[\ReturnTypeWillChange]
75  public function ‪serialize()
76  {
77  return ‪serialize($this->‪__serialize());
78  }
79 
85  #[\ReturnTypeWillChange]
86  public function ‪__serialize()
87  {
88  return $this->‪toArray();
89  }
90 
98  #[\ReturnTypeWillChange]
99  public function ‪unserialize($serializedString)
100  {
101  $this->‪__unserialize(‪unserialize($serializedString));
102  }
103 
110  #[\ReturnTypeWillChange]
111  public function ‪__unserialize($arrayRepresentation)
112  {
113  if ($arrayRepresentation['serializeClassName'] !== static::class) {
114  throw new ‪Exception('Deserialized object type is not identical!', 1294586647);
115  }
116  $this->‪dataFromArray($arrayRepresentation);
117  }
118 
124  public function ‪toArray()
125  {
126  $arrayRepresentation = [
127  'serializeClassName' => static::class,
128  ];
129  $iterator = $this->getIterator();
130  while ($iterator->valid()) {
131  $arrayRepresentation[] = $iterator->current()->toArray();
132  $iterator->next();
133  }
134  return $arrayRepresentation;
135  }
136 
142  public function ‪dataFromArray($data)
143  {
144  unset($data['serializeClassName']);
145  foreach ($data as $index => $nodeArray) {
146  $node = GeneralUtility::makeInstance($nodeArray['serializeClassName'], $nodeArray);
147  $this->offsetSet($index, $node);
148  }
149  }
150 }
‪TYPO3\CMS\Backend\Tree\TreeNodeCollection\__serialize
‪__serialize()
Definition: TreeNodeCollection.php:86
‪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\TreeNodeCollection\serialize
‪string serialize()
Definition: TreeNodeCollection.php:75
‪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\unserialize
‪unserialize($serializedString)
Definition: TreeNodeCollection.php:99
‪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:142
‪TYPO3\CMS\Backend\Tree\TreeNodeCollection\__unserialize
‪__unserialize($arrayRepresentation)
Definition: TreeNodeCollection.php:111
‪TYPO3\CMS\Backend\Tree\TreeNodeCollection\asort
‪asort($flags=SORT_REGULAR)
Definition: TreeNodeCollection.php:49
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Backend\Tree\TreeNode\compareTo
‪int compareTo($other)
Definition: TreeNode.php:170
‪TYPO3\CMS\Backend\Tree\TreeNodeCollection\toArray
‪array toArray()
Definition: TreeNodeCollection.php:124