|
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_Service_Console |
|
17 * @subpackage Exception |
|
18 * @version $Id$ |
|
19 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) |
|
20 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
21 * @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com) |
|
22 * @license http://phpazure.codeplex.com/license |
|
23 */ |
|
24 |
|
25 /** |
|
26 * @see Zend_Service_Console_Command_ParameterSource_ParameterSourceInterface |
|
27 */ |
|
28 require_once 'Zend/Service/Console/Command/ParameterSource/ParameterSourceInterface.php'; |
|
29 |
|
30 /** |
|
31 * @category Zend |
|
32 * @package Zend_Service_Console |
|
33 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) |
|
34 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
35 * @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com) |
|
36 * @license http://phpazure.codeplex.com/license |
|
37 */ |
|
38 class Zend_Service_Console_Command_ParameterSource_Env |
|
39 implements Zend_Service_Console_Command_ParameterSource_ParameterSourceInterface |
|
40 { |
|
41 /** |
|
42 * Get value for a named parameter. |
|
43 * |
|
44 * @param mixed $parameter Parameter to get a value for |
|
45 * @param array $argv Argument values passed to the script when run in console. |
|
46 * @return mixed |
|
47 */ |
|
48 public function getValueForParameter($parameter, $argv = array()) |
|
49 { |
|
50 // Default value |
|
51 $parameterValue = null; |
|
52 |
|
53 // Fetch value for parameter |
|
54 foreach ($parameter->aliases as $alias) { |
|
55 while (strpos($alias, '-') !== false) { |
|
56 $alias = substr($alias, 1); |
|
57 } |
|
58 $value = getenv($alias); |
|
59 |
|
60 if (!is_null($value) && $value !== false) { |
|
61 $parameterValue = $value; |
|
62 break; |
|
63 } |
|
64 } |
|
65 |
|
66 if (strtolower($parameterValue) == 'true') { |
|
67 $parameterValue = true; |
|
68 } else if (strtolower($parameterValue) == 'false') { |
|
69 $parameterValue = false; |
|
70 } |
|
71 |
|
72 // Done! |
|
73 return $parameterValue; |
|
74 } |
|
75 } |