[TASK] Update to latest class alias loader version
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Classes / Http / Application.php
1 <?php
2 namespace TYPO3\CMS\Frontend\Http;
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 TYPO3\CMS\Core\Core\ApplicationInterface;
18 use TYPO3\CMS\Core\Core\Bootstrap;
19
20 /**
21 * Entry point for the TYPO3 Frontend
22 */
23 class Application implements ApplicationInterface {
24
25 /**
26 * @var Bootstrap
27 */
28 protected $bootstrap;
29
30 /**
31 * Usually this is equal to PATH_site = kept empty
32 * @var string
33 */
34 protected $entryPointPath = '';
35
36 /**
37 * All available request handlers that can deal with a Frontend Request
38 * @var array
39 */
40 protected $availableRequestHandlers = array(
41 \TYPO3\CMS\Frontend\Http\RequestHandler::class,
42 \TYPO3\CMS\Frontend\Http\EidRequestHandler::class
43 );
44
45 /**
46 * Constructor setting up legacy constant and register available Request Handlers
47 *
48 * @param \Composer\Autoload\ClassLoader $classLoader an instance of the class loader
49 */
50 public function __construct($classLoader) {
51 $this->defineLegacyConstants();
52
53 $this->bootstrap = Bootstrap::getInstance()
54 ->initializeClassLoader($classLoader)
55 ->baseSetup($this->entryPointPath);
56
57 // Redirect to install tool if base configuration is not found
58 if (!$this->bootstrap->checkIfEssentialConfigurationExists()) {
59 $this->bootstrap->redirectToInstallTool($this->entryPointPath);
60 }
61
62 foreach ($this->availableRequestHandlers as $requestHandler) {
63 $this->bootstrap->registerRequestHandlerImplementation($requestHandler);
64 }
65
66 $this->bootstrap->configure();
67 }
68
69 /**
70 * Starting point
71 *
72 * @param callable $execute
73 * @return void
74 */
75 public function run(callable $execute = NULL) {
76 $this->bootstrap->handleRequest(\TYPO3\CMS\Core\Http\ServerRequestFactory::fromGlobals());
77
78 if ($execute !== NULL) {
79 if ($execute instanceof \Closure) {
80 $execute->bindTo($this);
81 }
82 call_user_func($execute);
83 }
84
85 $this->bootstrap->shutdown();
86 }
87
88 /**
89 * Define constants and variables
90 */
91 protected function defineLegacyConstants() {
92 define('TYPO3_MODE', 'FE');
93 }
94 }