Argv.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. * @see Zend_Service_Console_Command_ParameterSource_ParameterSourceInterface
  26. */
  27. require_once 'Zend/Service/Console/Command/ParameterSource/ParameterSourceInterface.php';
  28. /**
  29. * @category Zend
  30. * @package Zend_Service_Console
  31. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  32. * @license http://framework.zend.com/license/new-bsd New BSD License
  33. * @copyright Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
  34. * @license http://phpazure.codeplex.com/license
  35. */
  36. class Zend_Service_Console_Command_ParameterSource_Argv
  37. implements Zend_Service_Console_Command_ParameterSource_ParameterSourceInterface
  38. {
  39. /**
  40. * Get value for a named parameter.
  41. *
  42. * @param mixed $parameter Parameter to get a value for
  43. * @param array $argv Argument values passed to the script when run in console.
  44. * @return mixed
  45. */
  46. public function getValueForParameter($parameter, $argv = array())
  47. {
  48. // Default value
  49. $parameterValue = null;
  50. // Loop parameter inputs
  51. foreach ($argv as $parameterInput) {
  52. $parameterInput = explode('=', $parameterInput, 2);
  53. if (in_array($parameterInput[0], $parameter->aliases)) {
  54. $parameterValue = isset($parameterInput[1]) ? $parameterInput[1] : true;
  55. break;
  56. }
  57. }
  58. if (strtolower($parameterValue) == 'true') {
  59. $parameterValue = true;
  60. } else if (strtolower($parameterValue) == 'false') {
  61. $parameterValue = false;
  62. }
  63. // Done!
  64. return $parameterValue;
  65. }
  66. }