File indexing completed on 2025-01-26 05:29:52
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Service_Console 0017 * @subpackage Exception 0018 * @version $Id$ 0019 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0020 * @license http://framework.zend.com/license/new-bsd New BSD License 0021 * @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com) 0022 * @license http://phpazure.codeplex.com/license 0023 */ 0024 0025 /** 0026 * @see Zend_Service_Console_Command_ParameterSource_ParameterSourceInterface 0027 */ 0028 // require_once 'Zend/Service/Console/Command/ParameterSource/ParameterSourceInterface.php'; 0029 0030 /** 0031 * @category Zend 0032 * @package Zend_Service_Console 0033 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0034 * @license http://framework.zend.com/license/new-bsd New BSD License 0035 * @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com) 0036 * @license http://phpazure.codeplex.com/license 0037 */ 0038 class Zend_Service_Console_Command_ParameterSource_ConfigFile 0039 implements Zend_Service_Console_Command_ParameterSource_ParameterSourceInterface 0040 { 0041 /** 0042 * Get value for a named parameter. 0043 * 0044 * @param mixed $parameter Parameter to get a value for 0045 * @param array $argv Argument values passed to the script when run in console. 0046 * @return mixed 0047 */ 0048 public function getValueForParameter($parameter, $argv = array()) 0049 { 0050 // Configuration file path 0051 $configurationFilePath = null; 0052 0053 // Check if a path to a configuration file is specified 0054 foreach ($argv as $parameterInput) { 0055 $parameterInput = explode('=', $parameterInput, 2); 0056 0057 if (strtolower($parameterInput[0]) == '--configfile' || strtolower($parameterInput[0]) == '-f') { 0058 if (!isset($parameterInput[1])) { 0059 // require_once 'Zend/Service/Console/Exception.php'; 0060 throw new Zend_Service_Console_Exception("No path to a configuration file is given. Specify the path using the --ConfigFile or -F switch."); 0061 } 0062 $configurationFilePath = $parameterInput[1]; 0063 break; 0064 } 0065 } 0066 0067 // Value given? 0068 if (is_null($configurationFilePath)) { 0069 return null; 0070 } 0071 if (!file_exists($configurationFilePath)) { 0072 // require_once 'Zend/Service/Console/Exception.php'; 0073 throw new Zend_Service_Console_Exception("Invalid configuration file given. Specify the correct path using the --ConfigFile or -F switch."); 0074 } 0075 0076 // Parse values 0077 $iniValues = parse_ini_file($configurationFilePath); 0078 0079 // Default value 0080 $parameterValue = null; 0081 0082 // Loop aliases 0083 foreach ($parameter->aliases as $alias) { 0084 if (array_key_exists($alias, $iniValues)) { 0085 $parameterValue = $iniValues[$alias]; break; 0086 } else if (array_key_exists(strtolower($alias), $iniValues)) { 0087 $parameterValue = $iniValues[strtolower($alias)]; break; 0088 } else if (array_key_exists(str_replace('-', '', $alias), $iniValues)) { 0089 $parameterValue = $iniValues[str_replace('-', '', $alias)]; break; 0090 } else if (array_key_exists(strtolower(str_replace('-', '', $alias)), $iniValues)) { 0091 $parameterValue = $iniValues[strtolower(str_replace('-', '', $alias))]; break; 0092 } 0093 } 0094 0095 if (strtolower($parameterValue) == 'true') { 0096 $parameterValue = true; 0097 } else if (strtolower($parameterValue) == 'false') { 0098 $parameterValue = false; 0099 } 0100 0101 // Done! 0102 return $parameterValue; 0103 } 0104 }