801b3d7b667dc56acf71cdaf9003eb5f338c8a79
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Functional / Framework / Frontend / ResponseSection.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Functional\Framework\Frontend;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2014 Oliver Hader <oliver.hader@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 /**
28 * Model of frontend response content
29 */
30 class ResponseSection {
31
32 /**
33 * @var string
34 */
35 protected $identifier;
36
37 /**
38 * @var array
39 */
40 protected $structure;
41
42 /**
43 * @var array
44 */
45 protected $structurePaths;
46
47 /**
48 * @var array
49 */
50 protected $records;
51
52 /**
53 * @var array
54 */
55 protected $queries;
56
57 /**
58 * @param string $identifier
59 * @param array $data
60 */
61 public function __construct($identifier, array $data) {
62 $this->identifier = (string)$identifier;
63 $this->structure = $data['structure'];
64 $this->structurePaths = $data['structurePaths'];
65 $this->records = $data['records'];
66
67 if (!empty($data['queries'])) {
68 $this->queries = $data['queries'];
69 }
70 }
71
72 /**
73 * @return string
74 */
75 public function getIdentifier() {
76 return $this->identifier;
77 }
78
79 /**
80 * @return array
81 */
82 public function getStructure() {
83 return $this->structure;
84 }
85
86 /**
87 * @return array
88 */
89 public function getStructurePaths() {
90 return $this->structurePaths;
91 }
92
93 /**
94 * @return array
95 */
96 public function getRecords() {
97 return $this->records;
98 }
99
100 /**
101 * @return array
102 */
103 public function getQueries() {
104 return $this->queries;
105 }
106
107 /**
108 * @param string $recordIdentifier
109 * @param string $fieldName
110 * @return array
111 */
112 public function findStructures($recordIdentifier, $fieldName = '') {
113 $structures = array();
114
115 if (empty($this->structurePaths[$recordIdentifier])) {
116 return $structures;
117 }
118
119 foreach ($this->structurePaths[$recordIdentifier] as $steps) {
120 $structure = $this->structure;
121 $steps[] = $recordIdentifier;
122
123 if (!empty($fieldName)) {
124 $steps[] = $fieldName;
125 }
126
127 foreach ($steps as $step) {
128 if (!isset($structure[$step])) {
129 $structure = NULL;
130 break;
131 }
132 $structure = $structure[$step];
133 }
134
135 if (!empty($structure)) {
136 $structures[implode('/', $steps)] = $structure;
137 }
138 }
139
140 return $structures;
141 }
142
143 }