TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
CommandApplication.php
Go to the documentation of this file.
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;
19 
26 {
30  protected $bootstrap;
31 
36  protected $entryPointLevel = 4;
37 
43  \TYPO3\CMS\Core\Console\CommandRequestHandler::class,
44  \TYPO3\CMS\Backend\Console\CliRequestHandler::class
45  ];
46 
52  public function __construct($classLoader)
53  {
54  $this->checkEnvironmentOrDie();
55  $this->defineLegacyConstants();
56  $this->bootstrap = Bootstrap::getInstance()
57  ->initializeClassLoader($classLoader)
58  ->setRequestType(TYPO3_REQUESTTYPE_BE | TYPO3_REQUESTTYPE_CLI)
59  ->baseSetup($this->entryPointLevel);
60 
61  foreach ($this->availableRequestHandlers as $requestHandler) {
62  $this->bootstrap->registerRequestHandlerImplementation($requestHandler);
63  }
64 
65  $this->bootstrap->configure();
66  }
67 
74  public function run(callable $execute = null)
75  {
76  $this->bootstrap->handleRequest(new ArgvInput());
77 
78  if ($execute !== null) {
79  call_user_func($execute);
80  }
81 
82  $this->bootstrap->shutdown();
83  }
84 
88  protected function defineLegacyConstants()
89  {
90  define('TYPO3_MODE', 'BE');
91  }
92 
98  protected function checkEnvironmentOrDie()
99  {
100  if (php_sapi_name() !== 'cli') {
101  die('Not called from a command line interface (e.g. a shell or scheduler).' . LF);
102  }
103  }
104 }