96011a30d3037567341c5d40ab95f73aea6073fe
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Mvc / Cli / RequestHandler.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Mvc\Cli;
3
4 /***************************************************************
5 * Copyright notice
6 * All rights reserved
7 *
8 * This class is a backport of the corresponding class of TYPO3 Flow.
9 * All credits go to the TYPO3 Flow team.
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * The generic command line interface request handler for the MVC framework.
29 *
30 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
31 */
32 class RequestHandler implements \TYPO3\CMS\Extbase\Mvc\RequestHandlerInterface {
33
34 /**
35 * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
36 * @inject
37 */
38 protected $objectManager;
39
40 /**
41 * @var \TYPO3\CMS\Extbase\Mvc\Dispatcher
42 * @inject
43 */
44 protected $dispatcher;
45
46 /**
47 * @var \TYPO3\CMS\Extbase\Mvc\Cli\RequestBuilder
48 * @inject
49 */
50 protected $requestBuilder;
51
52 /**
53 * @var \TYPO3\CMS\Extbase\Service\EnvironmentService
54 * @inject
55 */
56 protected $environmentService;
57
58 /**
59 * Handles the request
60 *
61 * @return void
62 */
63 public function handleRequest() {
64 $commandLine = isset($_SERVER['argv']) ? $_SERVER['argv'] : array();
65 $request = $this->requestBuilder->build(array_slice($commandLine, 1));
66 /** @var $response \TYPO3\CMS\Extbase\Mvc\Cli\Response */
67 $response = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\Cli\\Response');
68 $this->dispatcher->dispatch($request, $response);
69 $response->send();
70 }
71
72 /**
73 * This request handler can handle any command line request.
74 *
75 * @return boolean If the request is a command line request, TRUE otherwise FALSE
76 */
77 public function canHandleRequest() {
78 return $this->environmentService->isEnvironmentInCliMode();
79 }
80
81 /**
82 * Returns the priority - how eager the handler is to actually handle the
83 * request.
84 *
85 * @return integer The priority of the request handler.
86 */
87 public function getPriority() {
88 return 100;
89 }
90 }
91
92 ?>