‪TYPO3CMS  9.5
TreeNodeCollection.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
20 class ‪TreeNodeCollection extends \ArrayObject
21 {
30  public function ‪__construct(array $data = [])
31  {
32  parent::__construct();
33  if (!empty($data)) {
34  $this->‪dataFromArray($data);
35  }
36  }
37 
41  public function ‪asort()
42  {
43  $this->uasort([$this, 'nodeCompare']);
44  }
45 
55  public function ‪nodeCompare(\‪TYPO3\CMS\Backend\Tree\‪TreeNode $node, \‪TYPO3\CMS\Backend\Tree\‪TreeNode $otherNode)
56  {
57  return $node->compareTo($otherNode);
58  }
59 
65  public function ‪serialize()
66  {
67  return ‪serialize($this->‪toArray());
68  }
69 
76  public function ‪unserialize($serializedString)
77  {
78  $arrayRepresentation = ‪unserialize($serializedString);
79  if ($arrayRepresentation['serializeClassName'] !== static::class) {
80  throw new \TYPO3\CMS\Core\Exception('Deserialized object type is not identical!', 1294586647);
81  }
82  $this->‪dataFromArray($arrayRepresentation);
83  }
84 
90  public function ‪toArray()
91  {
92  $arrayRepresentation = [
93  'serializeClassName' => static::class
94  ];
95  $iterator = $this->getIterator();
96  while ($iterator->valid()) {
97  $arrayRepresentation[] = $iterator->current()->toArray();
98  $iterator->next();
99  }
100  return $arrayRepresentation;
101  }
102 
108  public function ‪dataFromArray($data)
109  {
110  unset($data['serializeClassName']);
111  foreach ($data as $index => $nodeArray) {
112  $node = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($nodeArray['serializeClassName'], $nodeArray);
113  $this->offsetSet($index, $node);
114  }
115  }
116 }
‪TYPO3
‪TYPO3\CMS\Backend\Tree\TreeNodeCollection\__construct
‪__construct(array $data=[])
Definition: TreeNodeCollection.php:30
‪TYPO3\CMS\Backend\Tree\TreeNodeCollection\serialize
‪string serialize()
Definition: TreeNodeCollection.php:65
‪TYPO3\CMS\Backend\Tree
Definition: AbstractTree.php:2
‪TYPO3\CMS\Backend\Tree\TreeNodeCollection\unserialize
‪unserialize($serializedString)
Definition: TreeNodeCollection.php:76
‪TYPO3\CMS\Backend\Tree\TreeNodeCollection
Definition: TreeNodeCollection.php:21
‪TYPO3\CMS\Backend\Tree\TreeNode
Definition: TreeNode.php:23
‪TYPO3\CMS\Backend\Tree\TreeNodeCollection\nodeCompare
‪int nodeCompare(\TYPO3\CMS\Backend\Tree\TreeNode $node, \TYPO3\CMS\Backend\Tree\TreeNode $otherNode)
Definition: TreeNodeCollection.php:55
‪TYPO3\CMS\Backend\Tree\TreeNodeCollection\dataFromArray
‪dataFromArray($data)
Definition: TreeNodeCollection.php:108
‪TYPO3\CMS\Backend\Tree\TreeNodeCollection\asort
‪asort()
Definition: TreeNodeCollection.php:41
‪TYPO3\CMS\Backend\Tree\TreeNodeCollection\toArray
‪array toArray()
Definition: TreeNodeCollection.php:90