Index: bin/zf.php =================================================================== --- bin/zf.php (revision 21551) +++ bin/zf.php (working copy) @@ -1,9 +1,9 @@ bootstrap(); $zf->run(); } - + /** * bootstrap() * @@ -86,12 +86,12 @@ $this->_homeDirectory = $this->_detectHomeDirectory(); $this->_storageDirectory = $this->_detectStorageDirectory(); $this->_configFile = $this->_detectConfigFile(); - + // setup $this->_setupPHPRuntime(); $this->_setupToolRuntime(); } - + /** * run() * @@ -117,10 +117,10 @@ $this->_runTool(); break; } - + return $this; } - + /** * _detectMode() * @@ -135,25 +135,25 @@ if (!isset($arguments[0])) { return $mode; } - + if ($arguments[0] == $_SERVER['PHP_SELF']) { $this->_executable = array_shift($arguments); } - + if (!isset($arguments[0])) { return $mode; } - + if ($arguments[0] == '--setup') { $mode = 'runSetup'; } elseif ($arguments[0] == '--info') { $mode = 'runInfo'; - } - - return $mode; + } + + return $mode; } - + /** * _detectHomeDirectory() - detect the home directory in a variety of different places * @@ -174,9 +174,9 @@ $this->_logMessage('Home directory does not exist at ' . $homeDirectory, $returnMessages); } } - + $homeDirectory = getenv('HOME'); // HOME environment variable - + if ($homeDirectory) { $this->_logMessage('Home directory found in environment variable HOME with value ' . $homeDirectory, $returnMessages); if (!$mustExist || ($mustExist && file_exists($homeDirectory))) { @@ -184,11 +184,11 @@ } else { $this->_logMessage('Home directory does not exist at ' . $homeDirectory, $returnMessages); } - + } $homeDirectory = getenv('HOMEPATH'); - + if ($homeDirectory) { $this->_logMessage('Home directory found in environment variable HOMEPATH with value ' . $homeDirectory, $returnMessages); if (!$mustExist || ($mustExist && file_exists($homeDirectory))) { @@ -199,7 +199,7 @@ } $homeDirectory = getenv('USERPROFILE'); - + if ($homeDirectory) { $this->_logMessage('Home directory found in environment variable USERPROFILE with value ' . $homeDirectory, $returnMessages); if (!$mustExist || ($mustExist && file_exists($homeDirectory))) { @@ -208,10 +208,10 @@ $this->_logMessage('Home directory does not exist at ' . $homeDirectory, $returnMessages); } } - + return false; } - + /** * _detectStorageDirectory() - Detect where the storage directory is from a variaty of possiblities * @@ -222,7 +222,7 @@ protected function _detectStorageDirectory($mustExist = true, $returnMessages = true) { $storageDirectory = false; - + $storageDirectory = getenv('ZF_STORAGE_DIR'); if ($storageDirectory) { $this->_logMessage('Storage directory path found in environment variable ZF_STORAGE_DIR with value ' . $storageDirectory, $returnMessages); @@ -232,9 +232,9 @@ $this->_logMessage('Storage directory does not exist at ' . $storageDirectory, $returnMessages); } } - + $homeDirectory = ($this->_homeDirectory) ? $this->_homeDirectory : $this->_detectHomeDirectory(true, false); - + if ($homeDirectory) { $storageDirectory = $homeDirectory . '/.zf/'; $this->_logMessage('Storage directory assumed in home directory at location ' . $storageDirectory, $returnMessages); @@ -244,10 +244,10 @@ $this->_logMessage('Storage directory does not exist at ' . $storageDirectory, $returnMessages); } } - + return false; } - + /** * _detectConfigFile() - Detect config file location from a variety of possibilities * @@ -258,7 +258,7 @@ protected function _detectConfigFile($mustExist = true, $returnMessages = true) { $configFile = null; - + $configFile = getenv('ZF_CONFIG_FILE'); if ($configFile) { $this->_logMessage('Config file found environment variable ZF_CONFIG_FILE at ' . $configFile, $returnMessages); @@ -268,7 +268,7 @@ $this->_logMessage('Config file does not exist at ' . $configFile, $returnMessages); } } - + $homeDirectory = ($this->_homeDirectory) ? $this->_homeDirectory : $this->_detectHomeDirectory(true, false); if ($homeDirectory) { $configFile = $homeDirectory . '/.zf.ini'; @@ -279,7 +279,7 @@ $this->_logMessage('Config file does not exist at ' . $configFile, $returnMessages); } } - + $storageDirectory = ($this->_storageDirectory) ? $this->_storageDirectory : $this->_detectStorageDirectory(true, false); if ($storageDirectory) { $configFile = $storageDirectory . '/zf.ini'; @@ -290,11 +290,11 @@ $this->_logMessage('Config file does not exist at ' . $configFile, $returnMessages); } } - + return false; } - + /** * _setupPHPRuntime() - parse the config file if it exists for php ini values to set * @@ -302,14 +302,14 @@ */ protected function _setupPHPRuntime() { - // set php runtime settings - ini_set('display_errors', true); - + // set php runtime settings + ini_set('display_errors', true); + // support the changing of the current working directory, necessary for some providers if (isset($_ENV['ZEND_TOOL_CURRENT_WORKING_DIRECTORY'])) { chdir($_ENV['ZEND_TOOL_CURRENT_WORKING_DIRECTORY']); } - + if (!$this->_configFile) { return; } @@ -323,10 +323,8 @@ } } } - - return null; } - + /** * _setupToolRuntime() - setup the tools include_path and load the proper framwork parts that * enable Zend_Tool to work. @@ -338,14 +336,14 @@ $includePathPrepend = getenv('ZEND_TOOL_INCLUDE_PATH_PREPEND'); $includePathFull = getenv('ZEND_TOOL_INCLUDE_PATH'); - + // check if the user has not provided anything if (!($includePathPrepend || $includePathFull)) { if ($this->_tryClientLoad()) { return; } } - + // if ZF is not in the include_path, but relative to this file, put it in the include_path if ($includePathPrepend || $includePathFull) { if (isset($includePathPrepend) && ($includePathPrepend !== false)) { @@ -354,24 +352,22 @@ set_include_path($includePathFull); } } - + if ($this->_tryClientLoad()) { return; } - + $zfIncludePath['relativePath'] = dirname(__FILE__) . '/../library/'; if (file_exists($zfIncludePath['relativePath'] . 'Zend/Tool/Framework/Client/Console.php')) { set_include_path(realpath($zfIncludePath['relativePath']) . PATH_SEPARATOR . get_include_path()); } - + if (!$this->_tryClientLoad()) { $this->_mode = 'runError'; return; } - - return null; } - + /** * _tryClientLoad() - Attempt to load the Zend_Tool_Framework_Client_Console to enable the tool to run. * @@ -392,10 +388,10 @@ include 'Zend/Tool/Framework/Client/Console.php'; $this->_clientLoaded = class_exists('Zend_Tool_Framework_Client_Console'); } - + return $this->_clientLoaded; } - + /** * _runError() - Output the error screen that tells the user that the tool was not setup * in a sane way @@ -404,9 +400,9 @@ */ protected function _runError() { - + echo <<_messages) . PHP_EOL; - + echo PHP_EOL; - + echo 'To change the setup of this tool, run: "zf --setup"'; - + echo PHP_EOL; } - + /** * _runSetup() - parse the request to see which setup command to run * @@ -462,7 +457,7 @@ protected function _runSetup() { $setupCommand = (isset($_SERVER['argv'][2])) ? $_SERVER['argv'][2] : null; - + switch ($setupCommand) { case 'storage-directory': $this->_runSetupStorageDirectory(); @@ -474,8 +469,7 @@ $this->_runSetupMoreInfo(); break; } - - return null; + } /** @@ -486,15 +480,15 @@ protected function _runSetupStorageDirectory() { $storageDirectory = $this->_detectStorageDirectory(false, false); - + if (file_exists($storageDirectory)) { echo 'Directory already exists at ' . $storageDirectory . PHP_EOL . 'Cannot create storage directory.'; return; } - + mkdir($storageDirectory); - + echo 'Storage directory created at ' . $storageDirectory . PHP_EOL; } @@ -506,29 +500,28 @@ protected function _runSetupConfigFile() { $configFile = $this->_detectConfigFile(false, false); - + if (file_exists($configFile)) { echo 'File already exists at ' . $configFile . PHP_EOL . 'Cannot write new config file.'; return; } - + $includePath = get_include_path(); - + $contents = 'php.include_path = "' . $includePath . '"'; - + file_put_contents($configFile, $contents); - + $iniValues = ini_get_all(); if ($iniValues['include_path']['global_value'] != $iniValues['include_path']['local_value']) { echo 'NOTE: the php include_path to be used with the tool has been written' . PHP_EOL . 'to the config file, using ZF_INCLUDE_PATH (or other include_path setters)' . PHP_EOL . 'is no longer necessary.' . PHP_EOL . PHP_EOL; } - + echo 'Config file written to ' . $configFile . PHP_EOL; - - return null; + } /** @@ -541,12 +534,12 @@ $homeDirectory = $this->_detectHomeDirectory(false, false); $storageDirectory = $this->_detectStorageDirectory(false, false); $configFile = $this->_detectConfigFile(false, false); - + echo <<_configFile) && $this->_configFile) { - $configOptions['configOptions']['configFilepath'] = $this->_configFile; - } - if (isset($this->_storageDirectory) && $this->_storageDirectory) { - $configOptions['storageOptions']['directory'] = $this->_storageDirectory; - } - - // ensure that zf.php loads the Zend_Tool_Project features - $configOptions['classesToLoad'] = 'Zend_Tool_Project_Provider_Manifest'; - - $console = new Zend_Tool_Framework_Client_Console($configOptions); - $console->dispatch(); - return null; + + $configOptions = array(); + if (isset($this->_configFile) && $this->_configFile) { + $configOptions['configOptions']['configFilepath'] = $this->_configFile; + } + if (isset($this->_storageDirectory) && $this->_storageDirectory) { + $configOptions['storageOptions']['directory'] = $this->_storageDirectory; + } + + // ensure that zf.php loads the Zend_Tool_Project features + $configOptions['classesToLoad'] = 'Zend_Tool_Project_Provider_Manifest'; + + $console = new Zend_Tool_Framework_Client_Console($configOptions); + $console->dispatch(); } /** @@ -621,15 +614,11 @@ if (!$storeMessage) { return; } - + $this->_messages[] = $message; } - - } if (!getenv('ZF_NO_MAIN')) { ZF::main(); } - -