‪TYPO3CMS  11.5
AbstractController.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
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 
19 
20 use Psr\Http\Message\ResponseInterface;
29 
34 {
37 
38  public function ‪__construct(
41  ) {
42  $this->dataMapFactory = ‪$dataMapFactory;
43  $this->queueService = ‪$queueService;
44  }
45 
51  public function ‪processRequest(‪RequestInterface ‪$request): ResponseInterface
52  {
53  try {
54  return parent::processRequest(‪$request);
55  } catch (‪Exception $exception) {
56  throw new \RuntimeException(
57  $this->‪getRuntimeIdentifier() . ': ' . $exception->getMessage() . ' (' . $exception->getCode() . ')',
58  1476049553
59  );
60  }
61  }
62 
67  protected function ‪getStructure($iterator): array
68  {
69  $structure = [];
70 
71  if (!$iterator instanceof \Iterator) {
72  $iterator = [$iterator];
73  }
74 
75  foreach ($iterator as $entity) {
76  $dataMap = $this->dataMapFactory->buildDataMap(get_class($entity));
77  $tableName = $dataMap->getTableName();
78  $identifier = $tableName . ':' . $entity->getUid();
79  $properties = ‪ObjectAccess::getGettableProperties($entity);
80 
81  $structureItem = [];
82  foreach ($properties as $propertyName => $propertyValue) {
83  $columnMap = $dataMap->getColumnMap($propertyName);
84  if ($columnMap !== null) {
85  $propertyName = $columnMap->getColumnName();
86  }
87  if ($propertyValue instanceof \Iterator) {
88  $structureItem[$propertyName] = $this->‪getStructure($propertyValue);
89  } else {
90  $structureItem[$propertyName] = $propertyValue;
91  }
92  }
93  $structure[$identifier] = $structureItem;
94  }
95 
96  return $structure;
97  }
98 
102  protected function ‪process($value)
103  {
104  if ($this->queueService->isActive()) {
105  $this->queueService->addValue($this->‪getRuntimeIdentifier(), $value);
106  return (new ‪ForwardResponse('process'))->withControllerName('Queue');
107  }
108  $this->view->assign('value', $value);
109  return $this->responseFactory->createResponse()
110  ->withBody($this->streamFactory->createStream($this->view->render()));
111  }
112 
116  protected function ‪getRuntimeIdentifier(): string
117  {
118  ‪$arguments = [];
119  foreach ($this->request->getArguments() as $argumentName => $argumentValue) {
120  ‪$arguments[] = $argumentName . '=' . $argumentValue;
121  }
122  return $this->request->getControllerActionName() . '(' . implode(', ', ‪$arguments) . ')';
123  }
124 }
‪TYPO3\CMS\Extbase\Property\Exception
Definition: DuplicateObjectException.php:18
‪TYPO3\CMS\Extbase\Mvc\Controller\ActionController\$arguments
‪TYPO3 CMS Extbase Mvc Controller Arguments $arguments
Definition: ActionController.php:159
‪TYPO3\CMS\Extbase\Mvc\Controller\ActionController\$request
‪Request $request
Definition: ActionController.php:129
‪TYPO3\TestIrreForeignfield\Controller\AbstractController\__construct
‪__construct(DataMapFactory $dataMapFactory, QueueService $queueService)
Definition: AbstractController.php:38
‪TYPO3\CMS\Extbase\Http\ForwardResponse
Definition: ForwardResponse.php:24
‪TYPO3\CMS\Extbase\DomainObject\AbstractEntity
Definition: AbstractEntity.php:22
‪TYPO3\CMS\Extbase\Reflection\ObjectAccess
Definition: ObjectAccess.php:39
‪TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory
Definition: DataMapFactory.php:39
‪TYPO3\TestIrreForeignfield\Controller\AbstractController\$queueService
‪QueueService $queueService
Definition: AbstractController.php:36
‪TYPO3\TestIrreForeignfield\Controller\AbstractController
Definition: AbstractController.php:34
‪TYPO3\TestIrreForeignfield\Controller\AbstractController\getStructure
‪array getStructure($iterator)
Definition: AbstractController.php:67
‪TYPO3\TestIrreForeignfield\Controller\AbstractController\getRuntimeIdentifier
‪string getRuntimeIdentifier()
Definition: AbstractController.php:116
‪TYPO3\CMS\Extbase\Reflection\ObjectAccess\getGettableProperties
‪static array getGettableProperties(object $object)
Definition: ObjectAccess.php:371
‪TYPO3\CMS\Extbase\Property\Exception
Definition: Exception.php:25
‪TYPO3\TestIrreForeignfield\Service\QueueService
Definition: QueueService.php:26
‪TYPO3\CMS\Extbase\Mvc\RequestInterface
Definition: RequestInterface.php:27
‪TYPO3\CMS\Extbase\Mvc\Controller\ActionController
Definition: ActionController.php:65
‪TYPO3\TestIrreForeignfield\Controller\AbstractController\processRequest
‪ResponseInterface processRequest(RequestInterface $request)
Definition: AbstractController.php:51
‪TYPO3\TestIrreForeignfield\Controller\AbstractController\process
‪process($value)
Definition: AbstractController.php:102
‪TYPO3\TestIrreForeignfield\Controller\AbstractController\$dataMapFactory
‪DataMapFactory $dataMapFactory
Definition: AbstractController.php:35
‪TYPO3\TestIrreForeignfield\Controller
Definition: AbstractController.php:18