Fixed bug #5838: cli_dispatch.phpsh doesn't work on windows platforms
[Packages/TYPO3.CMS.git] / typo3 / cli_dispatch.phpsh
1 #! /usr/bin/php -q
2 <?php
3 /***************************************************************
4 * Copyright notice
5 *
6 * (c) 2005-2008 Kasper Skaarhoj (kasperYYYY@typo3.com)
7 * All rights reserved
8 *
9 * This script is part of the TYPO3 project. The TYPO3 project is
10 * free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * The GNU General Public License can be found at
16 * http://www.gnu.org/copyleft/gpl.html.
17 * A copy is found in the textfile GPL.txt and important notices to the license
18 * from the author is found in LICENSE.txt distributed with these scripts.
19 *
20 *
21 * This script is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * This copyright notice MUST APPEAR in all copies of the script!
27 ***************************************************************/
28
29 /**
30 * Command Line Interface module dispatcher
31 *
32 * $Id: cli_dispatch.phpsh 2665 2007-11-05 19:38:07Z ingmars $
33 *
34 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
35 *
36 * This script takes a "cliKey" as first argument and uses that to look up the path of the script to include in the end.
37 * See configuration of this feature in $TYPO3_CONF_VARS['SC_OPTIONS']['GLOBAL']['cliKeys'].
38 * The point is to have only ONE script dealing with the environment initialization while the actual processing is all a developer should care for.
39 *
40 */
41
42 if (PHP_SAPI!='cli') {
43 die('Not called from a command line interface (eg. a shell or scheduler).'.chr(10));
44 }
45
46 // Defining circumstances for CLI mode:
47 define('TYPO3_cliMode', TRUE);
48
49 // Get path to this script
50 $temp_PATH_thisScript = isset($_SERVER['argv'][0]) ? $_SERVER['argv'][0] : (isset($_ENV['_']) ? $_ENV['_'] : $_SERVER['_']);
51
52 // Figure out if the path is relative
53 $relativePath = FALSE;
54 if (stristr(PHP_OS,'win') && !stristr(PHP_OS,'darwin')) {
55 // Windows
56 if (!preg_match('/^([A-Z]:)?\\\/', $temp_PATH_thisScript)) {
57 $relativePath = TRUE;
58 }
59 } else {
60 // *nix, et al
61 if ($temp_PATH_thisScript{0} != '/') {
62 $relativePath = TRUE;
63 }
64 }
65
66 // Resolve path
67 if ($relativePath) {
68 $workingDirectory = $_SERVER['PWD'] ? $_SERVER['PWD'] : getcwd();
69 if ($workingDirectory) {
70 $temp_PATH_thisScript =
71 $workingDirectory.'/'.ereg_replace('\.\/','',$temp_PATH_thisScript);
72 if (!@is_file($temp_PATH_thisScript)) {
73 die ('Relative path found, but an error occured during resolving of the absolute path: '.$temp_PATH_thisScript.chr(10));
74 }
75 } else {
76 die ('Relative path found, but resolving absolute path is not supported on this platform.'.chr(10));
77 }
78 }
79
80 // Define absolute path to this script
81 define('PATH_thisScript',$temp_PATH_thisScript);
82
83 if (!isset($_SERVER['argv'][1])) {
84 die ('First argument must be a valid key.'.chr(10));
85 }
86
87 // First argument is a key that points to the script configuration
88 define('TYPO3_cliKey', $_SERVER['argv'][1]);
89
90 // Include init file:
91 require(dirname(PATH_thisScript).'/init.php');
92
93 if (defined('TYPO3_cliInclude')) {
94 include(TYPO3_cliInclude);
95 } else {
96 die('No include file configured for key "'.TYPO3_cliKey.'".'.chr(10));
97 }
98
99 ?>