[!!!][TASK] Drop "documentation" extension
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Console / CommandApplication.php
1 <?php
2 namespace TYPO3\CMS\Core\Console;
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 use Symfony\Component\Console\Input\ArgvInput;
17 use TYPO3\CMS\Core\Core\ApplicationInterface;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19
20 /**
21 * Entry point for the TYPO3 Command Line for Commands
22 * Does not run the RequestHandler as this already runs an Application inside an Application which
23 * is just way too much logic around simple CLI calls
24 */
25 class CommandApplication implements ApplicationInterface
26 {
27 /**
28 */
29 public function __construct()
30 {
31 $this->checkEnvironmentOrDie();
32 }
33
34 /**
35 * Run the Symfony Console application in this TYPO3 application
36 *
37 * @param callable $execute
38 */
39 public function run(callable $execute = null)
40 {
41 $handler = GeneralUtility::makeInstance(CommandRequestHandler::class);
42 $handler->handleRequest(new ArgvInput());
43
44 if ($execute !== null) {
45 call_user_func($execute);
46 }
47 }
48
49 /**
50 * Check the script is called from a cli environment.
51 */
52 protected function checkEnvironmentOrDie()
53 {
54 if (php_sapi_name() !== 'cli') {
55 die('Not called from a command line interface (e.g. a shell or scheduler).' . LF);
56 }
57 }
58 }