[TASK] Use null coalescing operator where possible
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Functional / Fixtures / Extensions / irre_tutorial / Classes / Controller / QueueController.php
1 <?php
2 namespace OliverHader\IrreTutorial\Controller;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * ContentController
19 */
20 class QueueController extends AbstractController
21 {
22 /**
23 * @inject
24 * @var \OliverHader\IrreTutorial\Domain\Repository\ContentRepository
25 */
26 protected $contentRepository;
27
28 /**
29 * @var string
30 */
31 protected $defaultViewObjectName = \TYPO3\CMS\Extbase\Mvc\View\JsonView::class;
32
33 /**
34 */
35 public function indexAction()
36 {
37 $calls = [];
38 $calls[] = ['Content', 'list'];
39 $contents = $this->contentRepository->findAll();
40 foreach ($contents as $content) {
41 $uid = $content->getUid();
42 $calls[] = ['Content', 'show', ['content' => (string)$uid]];
43 }
44 $this->getQueueService()->set($calls);
45 $this->forward('process');
46 }
47
48 /**
49 */
50 public function processAction()
51 {
52 $call = $this->getQueueService()->shift();
53 if ($call === null) {
54 $this->forward('finish');
55 }
56 // Clear these states and fetch fresh entities!
57 $this->getPersistenceManager()->clearState();
58 $this->forward($call[1], $call[0], null, $call[2] ?? null);
59 }
60
61 public function finishAction()
62 {
63 $this->request->setDispatched(true);
64 $value = $this->getQueueService()->getValues();
65 $this->view->assign('value', $value);
66 }
67
68 /**
69 * Finds and instanciates a controller that matches the current request.
70 * If no controller can be found, an instance of NotFoundControllerInterface is returned.
71 *
72 * @param \TYPO3\CMS\Extbase\Mvc\RequestInterface $request The request to dispatch
73 * @throws \TYPO3\CMS\Extbase\Mvc\Exception\InvalidControllerException
74 * @return \TYPO3\CMS\Extbase\Mvc\Controller\ControllerInterface
75 */
76 protected function resolveController(\TYPO3\CMS\Extbase\Mvc\RequestInterface $request)
77 {
78 $controllerObjectName = $request->getControllerObjectName();
79 $controller = $this->objectManager->get($controllerObjectName);
80 if (!$controller instanceof \TYPO3\CMS\Extbase\Mvc\Controller\ControllerInterface) {
81 throw new \TYPO3\CMS\Extbase\Mvc\Exception\InvalidControllerException('Invalid controller "' . $request->getControllerObjectName() . '". The controller must implement the TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ControllerInterface.', 1202921619);
82 }
83 return $controller;
84 }
85 }