TYPO3 CMS  TYPO3_8-7
CommandApplication.php
Go to the documentation of this file.
1 <?php
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  */
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_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 
73  public function run(callable $execute = null)
74  {
75  $this->bootstrap->handleRequest(new ArgvInput());
76 
77  if ($execute !== null) {
78  call_user_func($execute);
79  }
80 
81  $this->bootstrap->shutdown();
82  }
83 
87  protected function defineLegacyConstants()
88  {
89  define('TYPO3_MODE', 'BE');
90  }
91 
95  protected function checkEnvironmentOrDie()
96  {
97  if (php_sapi_name() !== 'cli') {
98  die('Not called from a command line interface (e.g. a shell or scheduler).' . LF);
99  }
100  }
101 }