[TASK] Add functional tests for dynamic values in Extbase query cache
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Functional / Fixtures / Extensions / blog_example / Classes / Controller / BlogController.php
1 <?php
2
3 namespace ExtbaseTeam\BlogExample\Controller;
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
18 /**
19 * BlogController
20 */
21 class BlogController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
22
23 /**
24 * @inject
25 * @var \ExtbaseTeam\BlogExample\Domain\Repository\BlogRepository
26 */
27 protected $blogRepository;
28
29 /**
30 * @var string
31 */
32 protected $defaultViewObjectName = \TYPO3\CMS\Extbase\Mvc\View\JsonView::class;
33
34 /**
35 * @inject
36 * @var \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory
37 */
38 protected $dataMapFactory;
39
40 /**
41 * @return array
42 */
43 public function listAction() {
44 $blogs = $this->blogRepository->findAll();
45 $value[$this->getRuntimeIdentifier()] = $this->getStructure($blogs);
46
47 $this->view->assign('value', $value);
48 }
49
50 /**
51 * @param \TYPO3\CMS\Extbase\Mvc\RequestInterface $request
52 * @param \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response
53 * @throws \RuntimeException
54 */
55 public function processRequest(\TYPO3\CMS\Extbase\Mvc\RequestInterface $request, \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response) {
56 try {
57 parent::processRequest($request, $response);
58 } catch (\TYPO3\CMS\Extbase\Property\Exception $exception) {
59 throw new \RuntimeException(
60 $this->getRuntimeIdentifier() . ': ' . $exception->getMessage() . ' (' . $exception->getCode() . ')'
61 );
62 }
63 }
64
65 /**
66 * @param \Iterator|\TYPO3\CMS\Extbase\DomainObject\AbstractEntity[] $iterator
67 * @return array
68 */
69 protected function getStructure($iterator) {
70 $structure = array();
71
72 if (!$iterator instanceof \Iterator) {
73 $iterator = array($iterator);
74 }
75
76 foreach ($iterator as $entity) {
77 $dataMap = $this->dataMapFactory->buildDataMap(get_class($entity));
78 $tableName = $dataMap->getTableName();
79 $identifier = $tableName . ':' . $entity->getUid();
80 $properties = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getGettableProperties($entity);
81
82 $structureItem = array();
83 foreach ($properties as $propertyName => $propertyValue) {
84 $columnMap = $dataMap->getColumnMap($propertyName);
85 if ($columnMap !== NULL) {
86 $propertyName = $columnMap->getColumnName();
87 }
88 if ($propertyValue instanceof \Iterator) {
89 $structureItem[$propertyName] = $this->getStructure($propertyValue);
90 } else {
91 $structureItem[$propertyName] = $propertyValue;
92 }
93 }
94 $structure[$identifier] = $structureItem;
95 }
96
97 return $structure;
98 }
99
100 /**
101 * @return string
102 */
103 protected function getRuntimeIdentifier() {
104 $arguments = array();
105 foreach ($this->request->getArguments() as $argumentName => $argumentValue) {
106 $arguments[] = $argumentName . '=' . $argumentValue;
107 }
108 return $this->request->getControllerActionName() . '(' . implode(', ', $arguments) . ')';
109 }
110
111 }