[TASK] Re-work/simplify copyright header in PHP files - Part 4
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Functional / Framework / Frontend / Renderer.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Functional\Framework\Frontend;
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
17 /**
18 * Model of frontend response
19 */
20 class Renderer implements \TYPO3\CMS\Core\SingletonInterface {
21
22 /**
23 * @var array
24 */
25 protected $sections = array();
26
27 /**
28 * @param string $content
29 * @param NULL|array $configuration
30 * @return void
31 */
32 public function parseValues($content, array $configuration = NULL) {
33 if (empty($content)) {
34 return;
35 }
36
37 $values = json_decode($content, TRUE);
38
39 if (empty($values) || !is_array($values)) {
40 return;
41 }
42
43 $asPrefix = (!empty($configuration['as']) ? $configuration['as'] . ':' : NULL);
44 foreach ($values as $identifier => $structure) {
45 $parser = $this->createParser();
46 $parser->parse($structure);
47
48 $section = array(
49 'structure' => $structure,
50 'structurePaths' => $parser->getPaths(),
51 'records' => $parser->getRecords(),
52 );
53
54 $this->addSection($section, $asPrefix . $identifier);
55 }
56 }
57
58 /**
59 * @param array $section
60 * @param NULL|string $as
61 */
62 public function addSection(array $section, $as = NULL) {
63 if (!empty($as)) {
64 $this->sections[$as] = $section;
65 } else {
66 $this->sections[] = $section;
67 }
68 }
69
70 /**
71 * @param string $content
72 * @param NULL|array $configuration
73 * @return string
74 */
75 public function renderSections($content, array $configuration = NULL) {
76 $content = json_encode($this->sections);
77 return $content;
78 }
79
80 /**
81 * @return Parser
82 */
83 protected function createParser() {
84 return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
85 'TYPO3\\CMS\\Core\\Tests\\Functional\\Framework\\Frontend\\Parser'
86 );
87 }
88
89 }