[TASK] Deprecate Extbase CommandControllers and @cli annotation
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Command / ExtbaseCommand.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Command;
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 use Symfony\Component\Console\Application;
18 use Symfony\Component\Console\Command\Command;
19 use Symfony\Component\Console\Input\InputInterface;
20 use Symfony\Component\Console\Output\OutputInterface;
21 use TYPO3\CMS\Core\Utility\GeneralUtility;
22 use TYPO3\CMS\Extbase\Core\Bootstrap;
23
24 /**
25 * Wrapper to wrap an Extbase command from a command controller into a Symfony Command
26 * @deprecated since TYPO3 v9, will be removed in TYPO3 v10.0. Use symfony/console commands instead.
27 */
28 class ExtbaseCommand extends Command
29 {
30 /**
31 * Extbase's command
32 * @var \TYPO3\CMS\Extbase\Mvc\Cli\Command
33 */
34 protected $command;
35
36 /**
37 * Extbase has its own validation logic, so it is disabled in this place
38 */
39 protected function configure()
40 {
41 $this->ignoreValidationErrors();
42 }
43
44 /**
45 * Sets the extbase command to be used for fetching the description etc.
46 *
47 * @param \TYPO3\CMS\Extbase\Mvc\Cli\Command $command
48 */
49 public function setExtbaseCommand(\TYPO3\CMS\Extbase\Mvc\Cli\Command $command)
50 {
51 $this->command = $command;
52 }
53
54 /**
55 * Sets the application instance for this command.
56 * Also uses the setApplication call now, as $this->configure() is called
57 * too early
58 *
59 * @param Application $application An Application instance
60 */
61 public function setApplication(Application $application = null)
62 {
63 parent::setApplication($application);
64 $description = $this->command->getDescription();
65 $description = str_replace(LF, ' ', $description);
66 $this->setDescription($description);
67 }
68
69 /**
70 * Executes the command to find any Extbase command
71 *
72 * @param InputInterface $input
73 * @param OutputInterface $output
74 */
75 protected function execute(InputInterface $input, OutputInterface $output)
76 {
77 // ugly hack because extbase only knows "help" (hardcoded, but already defined by symfony)
78 // and "extbase:help:help"
79 if ($_SERVER['argv'][1] === 'extbase:help') {
80 $_SERVER['argv'][1] = 'extbase:help:help';
81 }
82 $bootstrap = GeneralUtility::makeInstance(Bootstrap::class);
83 $bootstrap->run('', []);
84 }
85 }