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 / Server / Method / Prototype.php
blob0c8fe89cecad36447281ede70a1125f04ca5d6ca
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\Server\Method;
12 /**
13 * Method prototype metadata
15 class Prototype
17 /**
18 * @var string Return type
20 protected $returnType = 'void';
22 /**
23 * @var array Map parameter names to parameter index
25 protected $parameterNameMap = array();
27 /**
28 * @var array Method parameters
30 protected $parameters = array();
32 /**
33 * Constructor
35 * @param null|array $options
37 public function __construct($options = null)
39 if ((null !== $options) && is_array($options)) {
40 $this->setOptions($options);
44 /**
45 * Set return value
47 * @param string $returnType
48 * @return \Zend\Server\Method\Prototype
50 public function setReturnType($returnType)
52 $this->returnType = $returnType;
53 return $this;
56 /**
57 * Retrieve return type
59 * @return string
61 public function getReturnType()
63 return $this->returnType;
66 /**
67 * Add a parameter
69 * @param string $parameter
70 * @return \Zend\Server\Method\Prototype
72 public function addParameter($parameter)
74 if ($parameter instanceof Parameter) {
75 $this->parameters[] = $parameter;
76 if (null !== ($name = $parameter->getName())) {
77 $this->parameterNameMap[$name] = count($this->parameters) - 1;
79 } else {
80 $parameter = new Parameter(array(
81 'type' => (string) $parameter,
82 ));
83 $this->parameters[] = $parameter;
85 return $this;
88 /**
89 * Add parameters
91 * @param array $parameters
92 * @return \Zend\Server\Method\Prototype
94 public function addParameters(array $parameters)
96 foreach ($parameters as $parameter) {
97 $this->addParameter($parameter);
99 return $this;
103 * Set parameters
105 * @param array $parameters
106 * @return \Zend\Server\Method\Prototype
108 public function setParameters(array $parameters)
110 $this->parameters = array();
111 $this->parameterNameMap = array();
112 $this->addParameters($parameters);
113 return $this;
117 * Retrieve parameters as list of types
119 * @return array
121 public function getParameters()
123 $types = array();
124 foreach ($this->parameters as $parameter) {
125 $types[] = $parameter->getType();
127 return $types;
131 * Get parameter objects
133 * @return array
135 public function getParameterObjects()
137 return $this->parameters;
141 * Retrieve a single parameter by name or index
143 * @param string|int $index
144 * @return null|\Zend\Server\Method\Parameter
146 public function getParameter($index)
148 if (!is_string($index) && !is_numeric($index)) {
149 return null;
151 if (array_key_exists($index, $this->parameterNameMap)) {
152 $index = $this->parameterNameMap[$index];
154 if (array_key_exists($index, $this->parameters)) {
155 return $this->parameters[$index];
157 return null;
161 * Set object state from array
163 * @param array $options
164 * @return \Zend\Server\Method\Prototype
166 public function setOptions(array $options)
168 foreach ($options as $key => $value) {
169 $method = 'set' . ucfirst($key);
170 if (method_exists($this, $method)) {
171 $this->$method($value);
174 return $this;
178 * Serialize to array
180 * @return array
182 public function toArray()
184 return array(
185 'returnType' => $this->getReturnType(),
186 'parameters' => $this->getParameters(),