TYPO3 CMS  TYPO3_8-7
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  1476122222
64  );
65  }
66  }
67 
72  protected function getStructure($iterator)
73  {
74  $structure = [];
75 
76  if (!$iterator instanceof \Iterator) {
77  $iterator = [$iterator];
78  }
79 
80  foreach ($iterator as $entity) {
81  $dataMap = $this->dataMapFactory->buildDataMap(get_class($entity));
82  $tableName = $dataMap->getTableName();
83  $identifier = $tableName . ':' . $entity->getUid();
85 
86  $structureItem = [];
87  foreach ($properties as $propertyName => $propertyValue) {
88  $columnMap = $dataMap->getColumnMap($propertyName);
89  if ($columnMap !== null) {
90  $propertyName = $columnMap->getColumnName();
91  }
92  if ($propertyValue instanceof \Iterator) {
93  $structureItem[$propertyName] = $this->getStructure($propertyValue);
94  } else {
95  $structureItem[$propertyName] = $propertyValue;
96  }
97  }
98  $structure[$identifier] = $structureItem;
99  }
100 
101  return $structure;
102  }
103 
107  protected function getRuntimeIdentifier()
108  {
109  $arguments = [];
110  foreach ($this->request->getArguments() as $argumentName => $argumentValue) {
111  $arguments[] = $argumentName . '=' . $argumentValue;
112  }
113  return $this->request->getControllerActionName() . '(' . implode(', ', $arguments) . ')';
114  }
115 }
processRequest(\TYPO3\CMS\Extbase\Mvc\RequestInterface $request, \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response)