‪TYPO3CMS  ‪main
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 
49  public function ‪processRequest(‪RequestInterface ‪$request): ResponseInterface
50  {
51  try {
52  return parent::processRequest(‪$request);
53  } catch (‪Exception $exception) {
54  throw new \RuntimeException(
55  $this->‪getRuntimeIdentifier() . ': ' . $exception->getMessage() . ' (' . $exception->getCode() . ')',
56  1476049553
57  );
58  }
59  }
60 
64  protected function ‪getStructure($iterator): array
65  {
66  $structure = [];
67 
68  if (!$iterator instanceof \Iterator) {
69  $iterator = [$iterator];
70  }
71 
72  foreach ($iterator as $entity) {
73  $dataMap = $this->dataMapFactory->buildDataMap(get_class($entity));
74  $tableName = $dataMap->getTableName();
75  ‪$identifier = $tableName . ':' . $entity->getUid();
76  $properties = ObjectAccess::getGettableProperties($entity);
77 
78  $structureItem = [];
79  foreach ($properties as $propertyName => $propertyValue) {
80  $columnMap = $dataMap->getColumnMap($propertyName);
81  if ($columnMap !== null) {
82  $propertyName = $columnMap->getColumnName();
83  }
84  if ($propertyValue instanceof \Iterator) {
85  $structureItem[$propertyName] = $this->‪getStructure($propertyValue);
86  } else {
87  $structureItem[$propertyName] = $propertyValue;
88  }
89  }
90  $structure[‪$identifier] = $structureItem;
91  }
92 
93  return $structure;
94  }
95 
99  protected function ‪process($value)
100  {
101  if ($this->queueService->isActive()) {
102  $this->queueService->addValue($this->‪getRuntimeIdentifier(), $value);
103  return (new ‪ForwardResponse('process'))->withControllerName('Queue');
104  }
105  $this->view->assign('value', $value);
106  return $this->responseFactory->createResponse()
107  ->withBody($this->streamFactory->createStream($this->view->render()));
108  }
109 
110  protected function ‪getRuntimeIdentifier(): string
111  {
112  ‪$arguments = [];
113  foreach ($this->request->getArguments() as $argumentName => $argumentValue) {
114  ‪$arguments[] = $argumentName . '=' . $argumentValue;
115  }
116  return $this->request->getControllerActionName() . '(' . implode(', ', ‪$arguments) . ')';
117  }
118 }
‪TYPO3\CMS\Extbase\Property\Exception
Definition: DuplicateObjectException.php:18
‪TYPO3\CMS\Extbase\Mvc\Controller\ActionController\$request
‪RequestInterface $request
Definition: ActionController.php:110
‪TYPO3Tests\TestIrreForeignfield\Controller
Definition: AbstractController.php:18
‪TYPO3Tests\TestIrreForeignfield\Service\QueueService
Definition: QueueService.php:26
‪TYPO3Tests\TestIrreForeignfield\Controller\AbstractController\processRequest
‪processRequest(RequestInterface $request)
Definition: AbstractController.php:49
‪TYPO3Tests\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\Reflection\ObjectAccess
Definition: ObjectAccess.php:39
‪TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory
Definition: DataMapFactory.php:34
‪TYPO3Tests\TestIrreForeignfield\Controller\AbstractController
Definition: AbstractController.php:34
‪TYPO3Tests\TestIrreForeignfield\Controller\AbstractController\getStructure
‪getStructure($iterator)
Definition: AbstractController.php:64
‪TYPO3Tests\TestIrreForeignfield\Controller\AbstractController\$dataMapFactory
‪DataMapFactory $dataMapFactory
Definition: AbstractController.php:35
‪TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface
Definition: DomainObjectInterface.php:33
‪TYPO3Tests\TestIrreForeignfield\Controller\AbstractController\$queueService
‪QueueService $queueService
Definition: AbstractController.php:36
‪TYPO3\CMS\Extbase\Property\Exception
Definition: Exception.php:25
‪TYPO3\CMS\Extbase\Mvc\Controller\ActionController\$arguments
‪Arguments $arguments
Definition: ActionController.php:123
‪TYPO3Tests\TestIrreForeignfield\Controller\AbstractController\getRuntimeIdentifier
‪getRuntimeIdentifier()
Definition: AbstractController.php:110
‪TYPO3\CMS\Extbase\Mvc\RequestInterface
Definition: RequestInterface.php:24
‪TYPO3\CMS\Extbase\Mvc\Controller\ActionController
Definition: ActionController.php:63
‪TYPO3Tests\TestIrreForeignfield\Controller\AbstractController\process
‪process($value)
Definition: AbstractController.php:99
‪TYPO3\CMS\Webhooks\Message\$identifier
‪identifier readonly string $identifier
Definition: FileAddedMessage.php:37