47 public static function main()
79 switch ($this->_mode) {
108 $arguments = $_SERVER[
'argv'];
112 if (!isset($arguments[0])) {
116 if ($arguments[0] == $_SERVER[
'PHP_SELF']) {
117 $this->_executable = array_shift($arguments);
120 if (!isset($arguments[0])) {
124 if ($arguments[0] ==
'--setup') {
126 } elseif ($arguments[0] ==
'--info') {
143 $homeDirectory = null;
145 $homeDirectory = getenv(
'ZF_HOME');
146 if ($homeDirectory) {
147 $this->
_logMessage(
'Home directory found in environment variable ZF_HOME with value ' . $homeDirectory, $returnMessages);
148 if (!$mustExist || ($mustExist && file_exists($homeDirectory))) {
149 return $homeDirectory;
151 $this->
_logMessage(
'Home directory does not exist at ' . $homeDirectory, $returnMessages);
155 $homeDirectory = getenv(
'HOME');
157 if ($homeDirectory) {
158 $this->
_logMessage(
'Home directory found in environment variable HOME with value ' . $homeDirectory, $returnMessages);
159 if (!$mustExist || ($mustExist && file_exists($homeDirectory))) {
160 return $homeDirectory;
162 $this->
_logMessage(
'Home directory does not exist at ' . $homeDirectory, $returnMessages);
167 $homeDirectory = getenv(
'HOMEPATH');
169 if ($homeDirectory) {
170 $this->
_logMessage(
'Home directory found in environment variable HOMEPATH with value ' . $homeDirectory, $returnMessages);
171 if (!$mustExist || ($mustExist && file_exists($homeDirectory))) {
172 return $homeDirectory;
174 $this->
_logMessage(
'Home directory does not exist at ' . $homeDirectory, $returnMessages);
178 $homeDirectory = getenv(
'USERPROFILE');
180 if ($homeDirectory) {
181 $this->
_logMessage(
'Home directory found in environment variable USERPROFILE with value ' . $homeDirectory, $returnMessages);
182 if (!$mustExist || ($mustExist && file_exists($homeDirectory))) {
183 return $homeDirectory;
185 $this->
_logMessage(
'Home directory does not exist at ' . $homeDirectory, $returnMessages);
201 $storageDirectory =
false;
203 $storageDirectory = getenv(
'ZF_STORAGE_DIR');
204 if ($storageDirectory) {
205 $this->
_logMessage(
'Storage directory path found in environment variable ZF_STORAGE_DIR with value ' . $storageDirectory, $returnMessages);
206 if (!$mustExist || ($mustExist && file_exists($storageDirectory))) {
207 return $storageDirectory;
209 $this->
_logMessage(
'Storage directory does not exist at ' . $storageDirectory, $returnMessages);
215 if ($homeDirectory) {
216 $storageDirectory = $homeDirectory .
'/.zf/';
217 $this->
_logMessage(
'Storage directory assumed in home directory at location ' . $storageDirectory, $returnMessages);
218 if (!$mustExist || ($mustExist && file_exists($storageDirectory))) {
219 return $storageDirectory;
221 $this->
_logMessage(
'Storage directory does not exist at ' . $storageDirectory, $returnMessages);
239 $configFile = getenv(
'ZF_CONFIG_FILE');
241 $this->
_logMessage(
'Config file found environment variable ZF_CONFIG_FILE at ' . $configFile, $returnMessages);
242 if (!$mustExist || ($mustExist && file_exists($configFile))) {
245 $this->
_logMessage(
'Config file does not exist at ' . $configFile, $returnMessages);
250 if ($homeDirectory) {
251 $configFile = $homeDirectory .
'/.zf.ini';
252 $this->
_logMessage(
'Config file assumed in home directory at location ' . $configFile, $returnMessages);
253 if (!$mustExist || ($mustExist && file_exists($configFile))) {
256 $this->
_logMessage(
'Config file does not exist at ' . $configFile, $returnMessages);
261 if ($storageDirectory) {
262 $configFile = $storageDirectory .
'/zf.ini';
263 $this->
_logMessage(
'Config file assumed in storage directory at location ' . $configFile, $returnMessages);
264 if (!$mustExist || ($mustExist && file_exists($configFile))) {
267 $this->
_logMessage(
'Config file does not exist at ' . $configFile, $returnMessages);
283 ini_set(
'display_errors',
true);
286 $cwd = getenv(
'ZEND_TOOL_CURRENT_WORKING_DIRECTORY');
287 if ($cwd !=
'' && realpath($cwd)) {
291 if (!$this->_configFile) {
294 $zfINISettings = parse_ini_file($this->_configFile);
295 $phpINISettings = ini_get_all();
296 foreach ($zfINISettings as $zfINIKey => $zfINIValue) {
297 if (substr($zfINIKey, 0, 4) ===
'php.') {
298 $phpINIKey = substr($zfINIKey, 4);
299 if (array_key_exists($phpINIKey, $phpINISettings)) {
300 ini_set($phpINIKey, $zfINIValue);
315 $includePathPrepend = getenv(
'ZEND_TOOL_INCLUDE_PATH_PREPEND');
316 $includePathFull = getenv(
'ZEND_TOOL_INCLUDE_PATH');
319 if (!($includePathPrepend || $includePathFull)) {
326 if ($includePathPrepend || $includePathFull) {
327 if (isset($includePathPrepend) && ($includePathPrepend !==
false)) {
328 set_include_path($includePathPrepend . PATH_SEPARATOR . get_include_path());
329 } elseif (isset($includePathFull) && ($includePathFull !==
false)) {
330 set_include_path($includePathFull);
338 $zfIncludePath[
'relativePath'] = dirname(__FILE__) .
'/../library/';
339 if (file_exists($zfIncludePath[
'relativePath'] .
'Zend/Tool/Framework/Client/Console.php')) {
340 set_include_path(realpath($zfIncludePath[
'relativePath']) . PATH_SEPARATOR . get_include_path());
344 $this->_mode =
'runError';
359 $this->_clientLoaded =
false;
360 $fh = @fopen(
'Zend/Tool/Framework/Client/Console.php',
'r',
true);
366 include
'Zend/Tool/Framework/Client/Console.php';
367 $this->_clientLoaded = class_exists(
'Zend_Tool_Framework_Client_Console');
384 *****************************
ZF ERROR ********************************
385 In order to
run the zf command, you need to ensure that Zend Framework
386 is inside your include_path. There are a variety of ways that you can
387 ensure that
this zf command line tool knows where the Zend Framework
388 library is on your system, but not all of them can be described here.
390 The easiest way to
get the zf command running is to give it the include
391 path via an environment variable ZEND_TOOL_INCLUDE_PATH or
392 ZEND_TOOL_INCLUDE_PATH_PREPEND with the proper include path to use,
393 then
run the command
"zf --setup". This command is designed to create
394 a storage location
for your user, as well as create the zf.ini file
395 that the zf command will consult in order to
run properly on your
398 Example you would
run:
400 $ ZEND_TOOL_INCLUDE_PATH=/path/to/library zf --setup
402 Your are encourged to read more in the link that follows.
416 echo
'Zend_Tool & CLI Setup Information' . PHP_EOL
417 .
'(available via the command line "zf --info")'
420 echo
' * ' . implode(PHP_EOL .
' * ', $this->_messages) . PHP_EOL;
424 echo
'To change the setup of this tool, run: "zf --setup"';
437 $setupCommand = (isset($_SERVER[
'argv'][2])) ? $_SERVER[
'argv'][2] : null;
439 switch ($setupCommand) {
440 case 'storage-directory':
461 if (file_exists($storageDirectory)) {
462 echo
'Directory already exists at ' . $storageDirectory . PHP_EOL
463 .
'Cannot create storage directory.';
467 mkdir($storageDirectory);
469 echo
'Storage directory created at ' . $storageDirectory . PHP_EOL;
481 if (file_exists($configFile)) {
482 echo
'File already exists at ' . $configFile . PHP_EOL
483 .
'Cannot write new config file.';
487 $includePath = get_include_path();
489 $contents =
'php.include_path = "' . $includePath .
'"';
491 file_put_contents($configFile, $contents);
493 $iniValues = ini_get_all();
494 if ($iniValues[
'include_path'][
'global_value'] != $iniValues[
'include_path'][
'local_value']) {
495 echo
'NOTE: the php include_path to be used with the tool has been written' . PHP_EOL
496 .
'to the config file, using ZEND_TOOL_INCLUDE_PATH (or other include_path setters)' . PHP_EOL
497 .
'is no longer necessary.' . PHP_EOL . PHP_EOL;
500 echo
'Config file written to ' . $configFile . PHP_EOL;
516 ZF Command Line Tool - Setup
517 ----------------------------
519 Current Paths (Existing or not):
520 Home Directory: {$homeDirectory}
521 Storage Directory: {$storageDirectory}
522 Config File: {$configFile}
524 Important Environment Variables:
526 - the directory
this tool will look
for a home directory
527 - directory must exist
529 - where
this tool will look
for a storage directory
530 - directory must exist
532 - where
this tool will look
for a configuration file
534 - set the include_path
for this tool to use
this value
535 ZF_TOOL_INCLUDE_PATH_PREPEND
536 - prepend the current php.ini include_path with
this value
540 - ZF_HOME, then HOME (*nix), then HOMEPATH (windows)
542 - ZF_STORAGE_DIR, then {home}/.zf/
544 - ZF_CONFIG_FILE, then {home}/.zf.ini, then {home}/zf.ini,
545 then {storage}/zf.ini
548 zf --setup storage-directory
549 - setup the storage directory, directory will be created
550 zf --setup config-file
551 - create the config file with some
default values
565 $configOptions = array();
566 if (isset($this->_configFile) && $this->_configFile) {
569 if (isset($this->_storageDirectory) && $this->_storageDirectory) {
574 $configOptions[
'classesToLoad'] =
'Zend_Tool_Project_Provider_Manifest';
576 $console =
new Zend_Tool_Framework_Client_Console($configOptions);
577 $console->dispatch();
589 if (!$storeMessage) {
593 $this->_messages[] = $message;
599 if (!getenv(
'ZF_NO_MAIN')) {
_detectConfigFile($mustExist=true, $returnMessages=true)
_detectConfigFile() - Detect config file location from a variety of possibilities ...
_setupToolRuntime()
_setupToolRuntime() - setup the tools include_path and load the proper framwork parts that enable Zen...
_runSetupMoreInfo()
_runSetupMoreInfo() - return more information about what can be setup, and what is setup ...
_detectStorageDirectory($mustExist=true, $returnMessages=true)
_detectStorageDirectory() - Detect where the storage directory is from a variaty of possiblities ...
_runTool()
_runTool() - This is where the magic happens, dispatch Zend_Tool
_detectMode()
_detectMode()
_runInfo()
_runInfo() - this command will produce information about the setup of this script and Zend_Tool ...
_detectHomeDirectory($mustExist=true, $returnMessages=true)
_detectHomeDirectory() - detect the home directory in a variety of different places ...
_logMessage($message, $storeMessage=true)
_logMessage() - Internal method used to log setup and information messages.
_runSetupStorageDirectory()
_runSetupStorageDirectory() - if the storage directory does not exist, create it
_runSetupConfigFile()
_runSetupConfigFile()
_tryClientLoad()
_tryClientLoad() - Attempt to load the Zend_Tool_Framework_Client_Console to enable the tool to run...
_runSetup()
_runSetup() - parse the request to see which setup command to run
_setupPHPRuntime()
_setupPHPRuntime() - parse the config file if it exists for php ini values to set ...
_runError()
_runError() - Output the error screen that tells the user that the tool was not setup in a sane way ...