TYPO3 CMS  TYPO3_7-6
Parser.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 
21 {
25  protected $paths = [];
26 
30  protected $records = [];
31 
35  public function getPaths()
36  {
37  return $this->paths;
38  }
39 
43  public function getRecords()
44  {
45  return $this->records;
46  }
47 
52  public function parse(array $structure, array $path = [])
53  {
54  $this->process($structure);
55  }
56 
61  protected function process(array $iterator, array $path = [])
62  {
63  foreach ($iterator as $identifier => $properties) {
64  if (!is_array($properties)) {
65  continue;
66  }
67  $this->addRecord($identifier, $properties);
68  $this->addPath($identifier, $path);
69  foreach ($properties as $propertyName => $propertyValue) {
70  if (!is_array($propertyValue)) {
71  continue;
72  }
73  $nestedPath = array_merge($path, [$identifier, $propertyName]);
74  $this->process($propertyValue, $nestedPath);
75  }
76  }
77  }
78 
83  protected function addRecord($identifier, array $properties)
84  {
85  if (isset($this->records[$identifier])) {
86  return;
87  }
88 
89  foreach ($properties as $propertyName => $propertyValue) {
90  if (is_array($propertyValue)) {
91  unset($properties[$propertyName]);
92  }
93  }
94 
95  $this->records[$identifier] = $properties;
96  }
97 
102  protected function addPath($identifier, array $path)
103  {
104  if (!isset($this->paths[$identifier])) {
105  $this->paths[$identifier] = [];
106  }
107 
108  $this->paths[$identifier][] = $path;
109  }
110 }
process(array $iterator, array $path=[])
Definition: Parser.php:61
parse(array $structure, array $path=[])
Definition: Parser.php:52