f34018e5fdca8ed17f29d9dd3f79ec801e076b80
[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 *
6 * Copyright notice
7 *
8 * (c) 2014 Oliver Hader <oliver.hader@typo3.org>
9 *
10 * All rights reserved
11 *
12 * This script is part of the TYPO3 project. The TYPO3 project is
13 * free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * The GNU General Public License can be found at
19 * http://www.gnu.org/copyleft/gpl.html.
20 *
21 * This script is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * This copyright notice MUST APPEAR in all copies of the script!
27 ***************************************************************/
28
29 /**
30 * ContentController
31 */
32 class QueueController extends AbstractController {
33
34 /**
35 * @inject
36 * @var \OliverHader\IrreTutorial\Domain\Repository\ContentRepository
37 */
38 protected $contentRepository;
39
40 /**
41 * @var string
42 */
43 protected $defaultViewObjectName = 'TYPO3\\CMS\\Extbase\\Mvc\\View\\JsonView';
44
45 /**
46 * @return void
47 */
48 public function indexAction() {
49 $calls = array();
50 $calls[] = array('Content', 'list');
51 $contents = $this->contentRepository->findAll();
52 foreach ($contents as $content) {
53 $uid = $content->getUid();
54 $calls[] = array('Content', 'show', array('content' => (string)$uid));
55 }
56 $this->getQueueService()->set($calls);
57 $this->forward('process');
58 }
59
60 /**
61 * @return void
62 */
63 public function processAction() {
64 $call = $this->getQueueService()->shift();
65 if ($call === NULL) {
66 $this->forward('finish');
67 }
68 // Clear these states and fetch fresh entities!
69 $this->getPersistenceManager()->clearState();
70 $this->forward($call[1], $call[0], NULL, isset($call[2]) ? $call[2] : NULL);
71 }
72
73 public function finishAction() {
74 $this->request->setDispatched(TRUE);
75 $value = $this->getQueueService()->getValues();
76 $this->view->assign('value', $value);
77 }
78
79 /**
80 * Finds and instanciates a controller that matches the current request.
81 * If no controller can be found, an instance of NotFoundControllerInterface is returned.
82 *
83 * @param \TYPO3\CMS\Extbase\Mvc\RequestInterface $request The request to dispatch
84 * @throws \TYPO3\CMS\Extbase\Mvc\Exception\InvalidControllerException
85 * @return \TYPO3\CMS\Extbase\Mvc\Controller\ControllerInterface
86 */
87 protected function resolveController(\TYPO3\CMS\Extbase\Mvc\RequestInterface $request) {
88 $controllerObjectName = $request->getControllerObjectName();
89 $controller = $this->objectManager->get($controllerObjectName);
90 if (!$controller instanceof \TYPO3\CMS\Extbase\Mvc\Controller\ControllerInterface) {
91 throw new \TYPO3\CMS\Extbase\Mvc\Exception\InvalidControllerException('Invalid controller "' . $request->getControllerObjectName() . '". The controller must implement the TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ControllerInterface.', 1202921619);
92 }
93 return $controller;
94 }
95
96 }