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_StdIn 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 // Default value 0051 $parameterValue = null; 0052 0053 // Check STDIN for data 0054 if (ftell(STDIN) !== false) { 0055 // Read from STDIN 0056 $fs = fopen("php://stdin", "r"); 0057 if ($fs !== false) { 0058 /* 0059 while (!feof($fs)) { 0060 $data = fread($fs, 1); 0061 var_dump($data); 0062 $parameterValue .= $data; 0063 } */ 0064 $parameterValue = stream_get_contents($fs); 0065 fclose($fs); 0066 } 0067 0068 // Remove ending \r\n 0069 $parameterValue = rtrim($parameterValue); 0070 0071 if (strtolower($parameterValue) == 'true') { 0072 $parameterValue = true; 0073 } else if (strtolower($parameterValue) == 'false') { 0074 $parameterValue = false; 0075 } 0076 } 0077 0078 // Done! 0079 return $parameterValue; 0080 } 0081 }