Also apply the __toString fix to UserInfo
[cacert-mgr.git] / external / ZendFramework-1.9.5 / bin / zf.php
1 <?php
2 /**
3 * Zend Framework
4 *
5 * LICENSE
6 *
7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
14 *
15 * @category Zend
16 * @package Zend_Tool
17 * @subpackage Framework
18 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
20 * @version $Id$
21 */
22
23 zf_main();
24
25 /**
26 * zf_main() - The main() function to run
27 */
28 function zf_main() {
29 global $_zf;
30 $_zf = array();
31 zf_setup_home_directory();
32 zf_setup_storage_directory();
33 zf_setup_config_file();
34 zf_setup_php_runtime();
35 zf_setup_tool_runtime();
36 zf_run($_zf);
37 }
38
39 function zf_setup_home_directory() {
40 global $_zf;
41
42 // check for explicity set ENV var ZF_HOME
43 if (($zfHome = getenv('ZF_HOME')) && file_exists($zfHome)) {
44 $_zf['HOME'] = $zfHome;
45 } elseif (($home = getenv('HOME'))) {
46 $_zf['HOME'] = $home;
47 } elseif (($home = getenv('HOMEPATH'))) {
48 $_zf['HOME'] = $home;
49 }
50
51 $homeRealpath = realpath($_zf['HOME']);
52
53 if ($homeRealpath) {
54 $_zf['HOME'] = $homeRealpath;
55 } else {
56 unset($_zf['HOME']);
57 }
58
59 }
60
61 function zf_setup_storage_directory() {
62 global $_zf;
63
64 if (($zfStorage = getenv('ZF_STORAGE_DIR')) && file_exists($zfStorage)) {
65 $_zf['STORAGE_DIR'] = $zfStorage;
66 } elseif (isset($_zf['HOME']) && file_exists($_zf['HOME'] . '/.zf/')) {
67 $_zf['STORAGE_DIR'] = $_zf['HOME'] . '/.zf/';
68 } else {
69 return;
70 }
71
72 $storageRealpath = realpath($_zf['STORAGE_DIR']);
73
74 if ($storageRealpath) {
75 $_zf['STORAGE_DIR'] = $storageRealpath;
76 } else {
77 unset($_zf['STORAGE_DIR']);
78 }
79
80 }
81
82 function zf_setup_config_file() {
83 global $_zf;
84
85 if (($zfConfigFile = getenv('ZF_CONFIG_FILE')) && file_exists($zfConfigFile)) {
86 $_zf['CONFIG_FILE'] = $zfConfigFile;
87 } elseif (isset($_zf['HOME'])) {
88 if (file_exists($_zf['HOME'] . '/.zf.ini')) {
89 $_zf['CONFIG_FILE'] = $_zf['HOME'] . '/.zf.ini';
90 } elseif (file_exists($_zf['HOME'] . '/zf.ini')) {
91 $_zf['CONFIG_FILE'] = $_zf['HOME'] . '/zf.ini';
92 }
93 }
94
95 if (isset($_zf['CONFIG_FILE']) && ($zrealpath = realpath($_zf['CONFIG_FILE']))) {
96
97 $_zf['CONFIG_FILE'] = $zrealpath;
98
99 $zsuffix = substr($_zf['CONFIG_FILE'], -4);
100
101 if ($zsuffix === '.ini') {
102 $_zf['CONFIG_TYPE'] = 'ini';
103 } else {
104 unset($_zf['CONFIG_FILE']);
105 }
106
107 }
108
109 }
110
111
112
113 function zf_setup_php_runtime() {
114 global $_zf;
115 if (!isset($_zf['CONFIG_TYPE']) || $_zf['CONFIG_TYPE'] !== 'ini') {
116 return;
117 }
118 $zfini_settings = parse_ini_file($_zf['CONFIG_FILE']);
119 $phpini_settings = ini_get_all();
120 foreach ($zfini_settings as $zfini_key => $zfini_value) {
121 if (substr($zfini_key, 0, 4) === 'php.') {
122 $phpini_key = substr($zfini_key, 4);
123 if (array_key_exists($phpini_key, $phpini_settings)) {
124 ini_set($phpini_key, $zfini_value);
125 }
126 }
127 }
128 }
129
130 function zf_setup_tool_runtime() {
131 //global $_zf;
132
133 // last ditch efforts
134 if (zf_try_client_load()) {
135 return;
136 }
137
138 $zfIncludePath['original'] = get_include_path();
139
140 // if ZF is not in the include_path, but relative to this file, put it in the include_path
141 if (($zfIncludePath['prepend'] = getenv('ZEND_TOOL_INCLUDE_PATH_PREPEND')) || ($zfIncludePath['whole'] = getenv('ZEND_TOOL_INCLUDE_PATH'))) {
142 if (isset($zfIncludePath['prepend']) && ($zfIncludePath['prepend'] !== false) && (($zfIncludePath['prependRealpath'] = realpath($zfIncludePath['prepend'])) !== false)) {
143 set_include_path($zfIncludePath['prependRealpath'] . PATH_SEPARATOR . $zfIncludePath['original']);
144 } elseif (isset($zfIncludePath['whole']) && ($zfIncludePath['whole'] !== false) && (($zfIncludePath['wholeRealpath'] = realpath($zfIncludePath['whole'])) !== false)) {
145 set_include_path($zfIncludePath['wholeRealpath']);
146 }
147 }
148
149 if (zf_try_client_load()) {
150 return;
151 }
152
153 $zfIncludePath['relativePath'] = dirname(__FILE__) . '/../library/';
154 if (file_exists($zfIncludePath['relativePath'] . 'Zend/Tool/Framework/Client/Console.php')) {
155 set_include_path(realpath($zfIncludePath['relativePath']) . PATH_SEPARATOR . get_include_path());
156 }
157
158 if (!zf_try_client_load()) {
159 zf_display_error();
160 exit(1);
161 }
162
163 }
164
165 function zf_try_client_load() {
166 $loaded = @include_once 'Zend/Tool/Framework/Client/Console.php';
167 return $loaded;
168 }
169
170 /**
171 * zf_display_error()
172 */
173 function zf_display_error() {
174
175 echo <<<EOS
176
177 ***************************** ZF ERROR ********************************
178 In order to run the zf command, you need to ensure that Zend Framework
179 is inside your include_path. If you are running this tool without
180 ZendFramework in your include_path, you can alternatively set one of
181 two environment variables to for this tool to work:
182
183 a) ZEND_TOOL_INCLUDE_PATH_PREPEND="/path/to/ZendFramework/library"
184
185 OR alternatively
186
187 b) ZEND_TOOL_INCLUDE_PATH="/path/to/ZendFramework/library"
188
189 The former (a) will make the specified Zend Framework first in the
190 include_path whereas the latter (b) will replace the include_path
191 with the specified path.
192
193 Information:
194
195 EOS;
196
197 echo ' attempted include_path: ' . get_include_path() . PHP_EOL;
198 echo ' script location: ' . $_SERVER['SCRIPT_NAME'] . PHP_EOL;
199
200 }
201
202 function zf_run($zfConfig) {
203 global $_zf;
204 unset($_zf);
205
206 $configOptions = array();
207 if (isset($zfConfig['CONFIG_FILE'])) {
208 $configOptions['configOptions']['configFilepath'] = $zfConfig['CONFIG_FILE'];
209 }
210 if (isset($zfConfig['STORAGE_DIR'])) {
211 $configOptions['storageOptions']['directory'] = $zfConfig['STORAGE_DIR'];
212 }
213
214 Zend_Tool_Framework_Client_Console::main($configOptions);
215 }
216
217
218