[BUGFIX] Show loading label while scanning broken extensions
[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 = [];
26
27 /**
28 * @param string $content
29 * @param NULL|array $configuration
30 * @return void
31 */
32 public function parseValues($content, array $configuration = null)
33 {
34 if (empty($content)) {
35 return;
36 }
37
38 $values = json_decode($content, true);
39
40 if (empty($values) || !is_array($values)) {
41 return;
42 }
43
44 $asPrefix = (!empty($configuration['as']) ? $configuration['as'] . ':' : null);
45 foreach ($values as $identifier => $structure) {
46 $parser = $this->createParser();
47 $parser->parse($structure);
48
49 $section = [
50 'structure' => $structure,
51 'structurePaths' => $parser->getPaths(),
52 'records' => $parser->getRecords(),
53 ];
54
55 $this->addSection($section, $asPrefix . $identifier);
56 }
57 }
58
59 /**
60 * @param array $section
61 * @param NULL|string $as
62 */
63 public function addSection(array $section, $as = null)
64 {
65 if (!empty($as)) {
66 $this->sections[$as] = $section;
67 } else {
68 $this->sections[] = $section;
69 }
70 }
71
72 /**
73 * @param string $content
74 * @param NULL|array $configuration
75 * @return string
76 */
77 public function renderSections($content, array $configuration = null)
78 {
79 $content = json_encode($this->sections);
80 return $content;
81 }
82
83 /**
84 * @return Parser
85 */
86 protected function createParser()
87 {
88 return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
89 \TYPO3\CMS\Core\Tests\Functional\Framework\Frontend\Parser::class
90 );
91 }
92 }