-
Notifications
You must be signed in to change notification settings - Fork 638
/
CommandApplication.php
58 lines (53 loc) · 1.62 KB
/
CommandApplication.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
namespace TYPO3\CMS\Core\Console;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use Symfony\Component\Console\Input\ArgvInput;
use TYPO3\CMS\Core\Core\ApplicationInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Entry point for the TYPO3 Command Line for Commands
* Does not run the RequestHandler as this already runs an Application inside an Application which
* is just way too much logic around simple CLI calls
*/
class CommandApplication implements ApplicationInterface
{
/**
*/
public function __construct()
{
$this->checkEnvironmentOrDie();
}
/**
* Run the Symfony Console application in this TYPO3 application
*
* @param callable $execute
*/
public function run(callable $execute = null)
{
$handler = GeneralUtility::makeInstance(CommandRequestHandler::class);
$handler->handleRequest(new ArgvInput());
if ($execute !== null) {
call_user_func($execute);
}
}
/**
* Check the script is called from a cli environment.
*/
protected function checkEnvironmentOrDie()
{
if (php_sapi_name() !== 'cli') {
die('Not called from a command line interface (e.g. a shell or scheduler).' . LF);
}
}
}