TYPO3 CMS  TYPO3_7-6
Renderer.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 $sections = [];
26 
30  public $cObj;
31 
37  public function parseValues($content, array $configuration = null)
38  {
39  if (empty($content)) {
40  return;
41  }
42 
43  $values = json_decode($content, true);
44 
45  if (empty($values) || !is_array($values)) {
46  return;
47  }
48 
49  $asPrefix = (!empty($configuration['as']) ? $configuration['as'] . ':' : null);
50  foreach ($values as $identifier => $structure) {
51  $parser = $this->createParser();
52  $parser->parse($structure);
53 
54  $section = [
55  'structure' => $structure,
56  'structurePaths' => $parser->getPaths(),
57  'records' => $parser->getRecords(),
58  ];
59 
60  $this->addSection($section, $asPrefix . $identifier);
61  }
62  }
63 
81  public function renderValues($content, array $configuration = null)
82  {
83  if (empty($configuration['values.'])) {
84  return;
85  }
86 
87  $as = (!empty($configuration['as']) ? $configuration['as'] : null);
88  $this->addSection($this->stdWrapValues($configuration['values.']), $as);
89  }
90 
95  public function addSection(array $section, $as = null)
96  {
97  if (!empty($as)) {
98  $this->sections[$as] = $section;
99  } else {
100  $this->sections[] = $section;
101  }
102  }
103 
109  public function renderSections($content, array $configuration = null)
110  {
111  $content = json_encode($this->sections);
112  return $content;
113  }
114 
129  protected function stdWrapValues(array $values)
130  {
131  $renderedValues = [];
132 
133  foreach ($values as $propertyName => $propertyInstruction)
134  {
135  $plainPropertyName = rtrim($propertyName, '.');
136  if (!empty($propertyInstruction['children.'])) {
137  $renderedValues[$plainPropertyName] = $this->stdWrapValues(
138  $propertyInstruction['children.']
139  );
140  } else {
141  $renderedValues[$plainPropertyName] = $this->cObj->stdWrap(
142  '',
143  $propertyInstruction
144  );
145  }
146  }
147 
148  return $renderedValues;
149  }
150 
154  protected function createParser()
155  {
156  return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
157  \TYPO3\CMS\Core\Tests\Functional\Framework\Frontend\Parser::class
158  );
159  }
160 }
renderValues($content, array $configuration=null)
Definition: Renderer.php:81
parseValues($content, array $configuration=null)
Definition: Renderer.php:37
renderSections($content, array $configuration=null)
Definition: Renderer.php:109