TYPO3 CMS  TYPO3_6-2
TreeNodeCollection.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Backend\Tree;
3 
22 class TreeNodeCollection extends \ArrayObject {
23 
32  public function __construct(array $data = array()) {
33  if (count($data)) {
34  $this->dataFromArray($data);
35  }
36  }
37 
43  public function asort() {
44  $this->uasort(array($this, 'nodeCompare'));
45  }
46 
54  public function nodeCompare(\TYPO3\CMS\Backend\Tree\TreeNode $node, \TYPO3\CMS\Backend\Tree\TreeNode $otherNode) {
55  return $node->compareTo($otherNode);
56  }
57 
63  public function serialize() {
64  return serialize($this->toArray());
65  }
66 
74  public function unserialize($serializedString) {
75  $arrayRepresentation = unserialize($serializedString);
76  if ($arrayRepresentation['serializeClassName'] !== get_class($this)) {
77  throw new \TYPO3\CMS\Core\Exception('Deserialized object type is not identical!', 1294586647);
78  }
79  $this->dataFromArray($arrayRepresentation);
80  }
81 
87  public function toArray() {
88  $arrayRepresentation = array(
89  'serializeClassName' => get_class($this)
90  );
91  $iterator = $this->getIterator();
92  while ($iterator->valid()) {
93  $arrayRepresentation[] = $iterator->current()->toArray();
94  $iterator->next();
95  }
96  return $arrayRepresentation;
97  }
98 
105  public function dataFromArray($data) {
106  unset($data['serializeClassName']);
107  foreach ($data as $index => $nodeArray) {
108  $node = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($nodeArray['serializeClassName'], $nodeArray);
109  $this->offsetSet($index, $node);
110  }
111  }
112 
113 }
nodeCompare(\TYPO3\CMS\Backend\Tree\TreeNode $node, \TYPO3\CMS\Backend\Tree\TreeNode $otherNode)