123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293 |
- <?php
- /**
- * Zend Framework
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://framework.zend.com/license/new-bsd
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@zend.com so we can send you a copy immediately.
- *
- * @category Zend
- * @package Zend_Server
- * @subpackage Method
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @version $Id$
- */
- /**
- * Method definition metadata
- *
- * @category Zend
- * @package Zend_Server
- * @subpackage Method
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- */
- class Zend_Server_Method_Definition
- {
- /**
- * @var Zend_Server_Method_Callback
- */
- protected $_callback;
- /**
- * @var array
- */
- protected $_invokeArguments = array();
- /**
- * @var string
- */
- protected $_methodHelp = '';
- /**
- * @var string
- */
- protected $_name;
- /**
- * @var null|object
- */
- protected $_object;
- /**
- * @var array Array of Zend_Server_Method_Prototype objects
- */
- protected $_prototypes = array();
- /**
- * Constructor
- *
- * @param null|array $options
- * @return void
- */
- public function __construct($options = null)
- {
- if ((null !== $options) && is_array($options)) {
- $this->setOptions($options);
- }
- }
- /**
- * Set object state from options
- *
- * @param array $options
- * @return Zend_Server_Method_Definition
- */
- public function setOptions(array $options)
- {
- foreach ($options as $key => $value) {
- $method = 'set' . ucfirst($key);
- if (method_exists($this, $method)) {
- $this->$method($value);
- }
- }
- return $this;
- }
- /**
- * Set method name
- *
- * @param string $name
- * @return Zend_Server_Method_Definition
- */
- public function setName($name)
- {
- $this->_name = (string) $name;
- return $this;
- }
- /**
- * Get method name
- *
- * @return string
- */
- public function getName()
- {
- return $this->_name;
- }
- /**
- * Set method callback
- *
- * @param array|Zend_Server_Method_Callback $callback
- * @return Zend_Server_Method_Definition
- */
- public function setCallback($callback)
- {
- if (is_array($callback)) {
- #require_once 'Zend/Server/Method/Callback.php';
- $callback = new Zend_Server_Method_Callback($callback);
- } elseif (!$callback instanceof Zend_Server_Method_Callback) {
- #require_once 'Zend/Server/Exception.php';
- throw new Zend_Server_Exception('Invalid method callback provided');
- }
- $this->_callback = $callback;
- return $this;
- }
- /**
- * Get method callback
- *
- * @return Zend_Server_Method_Callback
- */
- public function getCallback()
- {
- return $this->_callback;
- }
- /**
- * Add prototype to method definition
- *
- * @param array|Zend_Server_Method_Prototype $prototype
- * @return Zend_Server_Method_Definition
- */
- public function addPrototype($prototype)
- {
- if (is_array($prototype)) {
- #require_once 'Zend/Server/Method/Prototype.php';
- $prototype = new Zend_Server_Method_Prototype($prototype);
- } elseif (!$prototype instanceof Zend_Server_Method_Prototype) {
- #require_once 'Zend/Server/Exception.php';
- throw new Zend_Server_Exception('Invalid method prototype provided');
- }
- $this->_prototypes[] = $prototype;
- return $this;
- }
- /**
- * Add multiple prototypes at once
- *
- * @param array $prototypes Array of Zend_Server_Method_Prototype objects or arrays
- * @return Zend_Server_Method_Definition
- */
- public function addPrototypes(array $prototypes)
- {
- foreach ($prototypes as $prototype) {
- $this->addPrototype($prototype);
- }
- return $this;
- }
- /**
- * Set all prototypes at once (overwrites)
- *
- * @param array $prototypes Array of Zend_Server_Method_Prototype objects or arrays
- * @return Zend_Server_Method_Definition
- */
- public function setPrototypes(array $prototypes)
- {
- $this->_prototypes = array();
- $this->addPrototypes($prototypes);
- return $this;
- }
- /**
- * Get all prototypes
- *
- * @return array $prototypes Array of Zend_Server_Method_Prototype objects or arrays
- */
- public function getPrototypes()
- {
- return $this->_prototypes;
- }
- /**
- * Set method help
- *
- * @param string $methodHelp
- * @return Zend_Server_Method_Definition
- */
- public function setMethodHelp($methodHelp)
- {
- $this->_methodHelp = (string) $methodHelp;
- return $this;
- }
- /**
- * Get method help
- *
- * @return string
- */
- public function getMethodHelp()
- {
- return $this->_methodHelp;
- }
- /**
- * Set object to use with method calls
- *
- * @param object $object
- * @return Zend_Server_Method_Definition
- */
- public function setObject($object)
- {
- if (!is_object($object) && (null !== $object)) {
- #require_once 'Zend/Server/Exception.php';
- throw new Zend_Server_Exception('Invalid object passed to ' . __CLASS__ . '::' . __METHOD__);
- }
- $this->_object = $object;
- return $this;
- }
- /**
- * Get object to use with method calls
- *
- * @return null|object
- */
- public function getObject()
- {
- return $this->_object;
- }
- /**
- * Set invoke arguments
- *
- * @param array $invokeArguments
- * @return Zend_Server_Method_Definition
- */
- public function setInvokeArguments(array $invokeArguments)
- {
- $this->_invokeArguments = $invokeArguments;
- return $this;
- }
- /**
- * Retrieve invoke arguments
- *
- * @return array
- */
- public function getInvokeArguments()
- {
- return $this->_invokeArguments;
- }
- /**
- * Serialize to array
- *
- * @return array
- */
- public function toArray()
- {
- $prototypes = $this->getPrototypes();
- $signatures = array();
- foreach ($prototypes as $prototype) {
- $signatures[] = $prototype->toArray();
- }
- return array(
- 'name' => $this->getName(),
- 'callback' => $this->getCallback()->toArray(),
- 'prototypes' => $signatures,
- 'methodHelp' => $this->getMethodHelp(),
- 'invokeArguments' => $this->getInvokeArguments(),
- 'object' => $this->getObject(),
- );
- }
- }
|