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
10 namespace Zend\Server\Method
;
15 * Method definition metadata
20 * @var \Zend\Server\Method\Callback
27 protected $invokeArguments = array();
32 protected $methodHelp = '';
45 * @var array Array of \Zend\Server\Method\Prototype objects
47 protected $prototypes = array();
52 * @param null|array $options
54 public function __construct($options = null)
56 if ((null !== $options) && is_array($options)) {
57 $this->setOptions($options);
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);
82 * @return \Zend\Server\Method\Definition
84 public function setName($name)
86 $this->name
= (string) $name;
95 public function getName()
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;
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;
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);
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);
176 * @return array $prototypes Array of \Zend\Server\Method\Prototype objects or arrays
178 public function getPrototypes()
180 return $this->prototypes
;
186 * @param string $methodHelp
187 * @return \Zend\Server\Method\Definition
189 public function setMethodHelp($methodHelp)
191 $this->methodHelp
= (string) $methodHelp;
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;
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;
244 * Retrieve invoke arguments
248 public function getInvokeArguments()
250 return $this->invokeArguments
;
258 public function toArray()
260 $prototypes = $this->getPrototypes();
261 $signatures = array();
262 foreach ($prototypes as $prototype) {
263 $signatures[] = $prototype->toArray();
267 'name' => $this->getName(),
268 'callback' => $this->getCallback()->toArray(),
269 'prototypes' => $signatures,
270 'methodHelp' => $this->getMethodHelp(),
271 'invokeArguments' => $this->getInvokeArguments(),
272 'object' => $this->getObject(),