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 / Definition.php
blob2908c2135c55637243e26e40d7f718f9b8d03fee
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 use Zend\Server;
14 /**
15 * Method definition metadata
17 class Definition
19 /**
20 * @var \Zend\Server\Method\Callback
22 protected $callback;
24 /**
25 * @var array
27 protected $invokeArguments = array();
29 /**
30 * @var string
32 protected $methodHelp = '';
34 /**
35 * @var string
37 protected $name;
39 /**
40 * @var null|object
42 protected $object;
44 /**
45 * @var array Array of \Zend\Server\Method\Prototype objects
47 protected $prototypes = array();
49 /**
50 * Constructor
52 * @param null|array $options
54 public function __construct($options = null)
56 if ((null !== $options) && is_array($options)) {
57 $this->setOptions($options);
61 /**
62 * Set object state from options
64 * @param array $options
65 * @return \Zend\Server\Method\Definition
67 public function setOptions(array $options)
69 foreach ($options as $key => $value) {
70 $method = 'set' . ucfirst($key);
71 if (method_exists($this, $method)) {
72 $this->$method($value);
75 return $this;
78 /**
79 * Set method name
81 * @param string $name
82 * @return \Zend\Server\Method\Definition
84 public function setName($name)
86 $this->name = (string) $name;
87 return $this;
90 /**
91 * Get method name
93 * @return string
95 public function getName()
97 return $this->name;
101 * Set method callback
103 * @param array|\Zend\Server\Method\Callback $callback
104 * @throws Server\Exception\InvalidArgumentException
105 * @return \Zend\Server\Method\Definition
107 public function setCallback($callback)
109 if (is_array($callback)) {
110 $callback = new Callback($callback);
111 } elseif (!$callback instanceof Callback) {
112 throw new Server\Exception\InvalidArgumentException('Invalid method callback provided');
114 $this->callback = $callback;
115 return $this;
119 * Get method callback
121 * @return \Zend\Server\Method\Callback
123 public function getCallback()
125 return $this->callback;
129 * Add prototype to method definition
131 * @param array|\Zend\Server\Method\Prototype $prototype
132 * @throws Server\Exception\InvalidArgumentException
133 * @return \Zend\Server\Method\Definition
135 public function addPrototype($prototype)
137 if (is_array($prototype)) {
138 $prototype = new Prototype($prototype);
139 } elseif (!$prototype instanceof Prototype) {
140 throw new Server\Exception\InvalidArgumentException('Invalid method prototype provided');
142 $this->prototypes[] = $prototype;
143 return $this;
147 * Add multiple prototypes at once
149 * @param array $prototypes Array of \Zend\Server\Method\Prototype objects or arrays
150 * @return \Zend\Server\Method\Definition
152 public function addPrototypes(array $prototypes)
154 foreach ($prototypes as $prototype) {
155 $this->addPrototype($prototype);
157 return $this;
161 * Set all prototypes at once (overwrites)
163 * @param array $prototypes Array of \Zend\Server\Method\Prototype objects or arrays
164 * @return \Zend\Server\Method\Definition
166 public function setPrototypes(array $prototypes)
168 $this->prototypes = array();
169 $this->addPrototypes($prototypes);
170 return $this;
174 * Get all prototypes
176 * @return array $prototypes Array of \Zend\Server\Method\Prototype objects or arrays
178 public function getPrototypes()
180 return $this->prototypes;
184 * Set method help
186 * @param string $methodHelp
187 * @return \Zend\Server\Method\Definition
189 public function setMethodHelp($methodHelp)
191 $this->methodHelp = (string) $methodHelp;
192 return $this;
196 * Get method help
198 * @return string
200 public function getMethodHelp()
202 return $this->methodHelp;
206 * Set object to use with method calls
208 * @param object $object
209 * @throws Server\Exception\InvalidArgumentException
210 * @return \Zend\Server\Method\Definition
212 public function setObject($object)
214 if (!is_object($object) && (null !== $object)) {
215 throw new Server\Exception\InvalidArgumentException('Invalid object passed to ' . __CLASS__ . '::' . __METHOD__);
217 $this->object = $object;
218 return $this;
222 * Get object to use with method calls
224 * @return null|object
226 public function getObject()
228 return $this->object;
232 * Set invoke arguments
234 * @param array $invokeArguments
235 * @return \Zend\Server\Method\Definition
237 public function setInvokeArguments(array $invokeArguments)
239 $this->invokeArguments = $invokeArguments;
240 return $this;
244 * Retrieve invoke arguments
246 * @return array
248 public function getInvokeArguments()
250 return $this->invokeArguments;
254 * Serialize to array
256 * @return array
258 public function toArray()
260 $prototypes = $this->getPrototypes();
261 $signatures = array();
262 foreach ($prototypes as $prototype) {
263 $signatures[] = $prototype->toArray();
266 return array(
267 'name' => $this->getName(),
268 'callback' => $this->getCallback()->toArray(),
269 'prototypes' => $signatures,
270 'methodHelp' => $this->getMethodHelp(),
271 'invokeArguments' => $this->getInvokeArguments(),
272 'object' => $this->getObject(),