[TASK] FormEngine JS refactoring: copy JS files
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Core / CliBootstrap.php
1 <?php
2 namespace TYPO3\CMS\Core\Core;
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 /**
18 * This class encapsulates cli specific bootstrap methods.
19 *
20 * This script is internal code and subject to change.
21 * DO NOT use it in own code, or be prepared your code might
22 * break in future core versions.
23 *
24 * @author Christian Kuhn <lolli@schwarzbu.ch>
25 */
26 class CliBootstrap {
27
28 /**
29 * Check the script is called from a cli environment.
30 *
31 * @return void
32 * @internal This is not a public API method, do not use in own extensions
33 */
34 static public function checkEnvironmentOrDie() {
35 if (substr(php_sapi_name(), 0, 3) === 'cgi') {
36 self::initializeCgiCompatibilityLayerOrDie();
37 } elseif (php_sapi_name() !== 'cli') {
38 die('Not called from a command line interface (e.g. a shell or scheduler).' . LF);
39 }
40 }
41
42 /**
43 * Set up cgi sapi as de facto cli, but check no HTTP
44 * environment variables are set.
45 *
46 * @return void
47 */
48 static protected function initializeCgiCompatibilityLayerOrDie() {
49 // Sanity check: Ensure we're running in a shell or cronjob (and NOT via HTTP)
50 $checkEnvVars = array('HTTP_USER_AGENT', 'HTTP_HOST', 'SERVER_NAME', 'REMOTE_ADDR', 'REMOTE_PORT', 'SERVER_PROTOCOL');
51 foreach ($checkEnvVars as $var) {
52 if (array_key_exists($var, $_SERVER)) {
53 echo 'SECURITY CHECK FAILED! This script cannot be used within your browser!' . LF;
54 echo 'If you are sure that we run in a shell or cronjob, please unset' . LF;
55 echo 'environment variable ' . $var . ' (usually using \'unset ' . $var . '\')' . LF;
56 echo 'before starting this script.' . LF;
57 die;
58 }
59 }
60 // Mimic CLI API in CGI API (you must use the -C/-no-chdir and the -q/--no-header switches!)
61 ini_set('html_errors', 0);
62 ini_set('implicit_flush', 1);
63 ini_set('max_execution_time', 0);
64 define('STDIN', fopen('php://stdin', 'r'));
65 define('STDOUT', fopen('php://stdout', 'w'));
66 define('STDERR', fopen('php://stderr', 'w'));
67 }
68
69 }