TYPO3 CMS  TYPO3_7-6
BlogController.php
Go to the documentation of this file.
1 <?php
2 
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
22 {
27  protected $blogRepository;
28 
32  protected $defaultViewObjectName = \TYPO3\CMS\Extbase\Mvc\View\JsonView::class;
33 
38  protected $dataMapFactory;
39 
43  public function listAction()
44  {
45  $blogs = $this->blogRepository->findAll();
46  $value[$this->getRuntimeIdentifier()] = $this->getStructure($blogs);
47 
48  $this->view->assign('value', $value);
49  }
50 
56  public function processRequest(\TYPO3\CMS\Extbase\Mvc\RequestInterface $request, \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response)
57  {
58  try {
59  parent::processRequest($request, $response);
60  } catch (\TYPO3\CMS\Extbase\Property\Exception $exception) {
61  throw new \RuntimeException(
62  $this->getRuntimeIdentifier() . ': ' . $exception->getMessage() . ' (' . $exception->getCode() . ')'
63  );
64  }
65  }
66 
71  protected function getStructure($iterator)
72  {
73  $structure = [];
74 
75  if (!$iterator instanceof \Iterator) {
76  $iterator = [$iterator];
77  }
78 
79  foreach ($iterator as $entity) {
80  $dataMap = $this->dataMapFactory->buildDataMap(get_class($entity));
81  $tableName = $dataMap->getTableName();
82  $identifier = $tableName . ':' . $entity->getUid();
84 
85  $structureItem = [];
86  foreach ($properties as $propertyName => $propertyValue) {
87  $columnMap = $dataMap->getColumnMap($propertyName);
88  if ($columnMap !== null) {
89  $propertyName = $columnMap->getColumnName();
90  }
91  if ($propertyValue instanceof \Iterator) {
92  $structureItem[$propertyName] = $this->getStructure($propertyValue);
93  } else {
94  $structureItem[$propertyName] = $propertyValue;
95  }
96  }
97  $structure[$identifier] = $structureItem;
98  }
99 
100  return $structure;
101  }
102 
106  protected function getRuntimeIdentifier()
107  {
108  $arguments = [];
109  foreach ($this->request->getArguments() as $argumentName => $argumentValue) {
110  $arguments[] = $argumentName . '=' . $argumentValue;
111  }
112  return $this->request->getControllerActionName() . '(' . implode(', ', $arguments) . ')';
113  }
114 }
processRequest(\TYPO3\CMS\Extbase\Mvc\RequestInterface $request, \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response)