Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Console / Request.php
blob16d6bf0d3128285bb346adc7490a9164ee96825e
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\Console;
12 use Zend\Stdlib\Message;
13 use Zend\Stdlib\Parameters;
14 use Zend\Stdlib\RequestInterface;
16 class Request extends Message implements RequestInterface
18 /**
19 * @var \Zend\Stdlib\Parameters
21 protected $params = null;
23 /**
24 * @var \Zend\Stdlib\Parameters
26 protected $envParams = null;
28 /**
29 * @var string
31 protected $scriptName = null;
33 /**
34 * Create a new CLI request
36 * @param array|null $args Console arguments. If not supplied, $_SERVER['argv'] will be used
37 * @param array|null $env Environment data. If not supplied, $_ENV will be used
38 * @throws Exception\RuntimeException
40 public function __construct(array $args = null, array $env = null)
42 if ($args === null) {
43 if (!isset($_SERVER['argv'])) {
44 $errorDescription = (ini_get('register_argc_argv') == false)
45 ? "Cannot create Console\\Request because PHP ini option 'register_argc_argv' is set Off"
46 : 'Cannot create Console\\Request because $_SERVER["argv"] is not set for unknown reason.';
47 throw new Exception\RuntimeException($errorDescription);
49 $args = $_SERVER['argv'];
52 if ($env === null) {
53 $env = $_ENV;
56 /**
57 * Extract first param assuming it is the script name
59 if (count($args) > 0) {
60 $this->setScriptName(array_shift($args));
63 /**
64 * Store runtime params
66 $this->params()->fromArray($args);
67 $this->setContent($args);
69 /**
70 * Store environment data
72 $this->env()->fromArray($env);
75 /**
76 * Exchange parameters object
78 * @param \Zend\Stdlib\Parameters $params
79 * @return Request
81 public function setParams(Parameters $params)
83 $this->params = $params;
84 $this->setContent($params);
85 return $this;
88 /**
89 * Return the container responsible for parameters
91 * @return \Zend\Stdlib\Parameters
93 public function getParams()
95 if ($this->params === null) {
96 $this->params = new Parameters();
99 return $this->params;
103 * Return a single parameter.
104 * Shortcut for $request->params()->get()
106 * @param string $name Parameter name
107 * @param string $default (optional) default value in case the parameter does not exist
108 * @return mixed
110 public function getParam($name, $default = null)
112 return $this->params()->get($name, $default);
116 * Return the container responsible for parameters
118 * @return \Zend\Stdlib\Parameters
120 public function params()
122 return $this->getParams();
126 * Provide an alternate Parameter Container implementation for env parameters in this object, (this is NOT the
127 * primary API for value setting, for that see env())
129 * @param \Zend\Stdlib\Parameters $env
130 * @return \Zend\Console\Request
132 public function setEnv(Parameters $env)
134 $this->envParams = $env;
135 return $this;
139 * Return a single parameter container responsible for env parameters
141 * @param string $name Parameter name
142 * @param string $default (optional) default value in case the parameter does not exist
143 * @return \Zend\Stdlib\Parameters
145 public function getEnv($name, $default = null)
147 return $this->env()->get($name, $default);
151 * Return the parameter container responsible for env parameters
153 * @return \Zend\Stdlib\Parameters
155 public function env()
157 if ($this->envParams === null) {
158 $this->envParams = new Parameters();
161 return $this->envParams;
165 * @return string
167 public function toString()
169 return trim(implode(' ', $this->params()->toArray()));
173 * Allow PHP casting of this object
175 * @return string
177 public function __toString()
179 return $this->toString();
183 * @param string $scriptName
185 public function setScriptName($scriptName)
187 $this->scriptName = $scriptName;
191 * @return string
193 public function getScriptName()
195 return $this->scriptName;