Source of file Callback.php
Size: 3,935 Bytes - Last Modified: 2014-03-12T23:21:18+01:00
/home/theseer/Downloads/ZendFramework-2.3.0/library/Zend/Server/Method/Callback.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 | <?php /** * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Server\Method; use Zend\Server; /** * Method callback metadata */ class Callback { /** * @var string Class name for class method callback */ protected $class; /** * @var string Function name for function callback */ protected $function; /** * @var string Method name for class method callback */ protected $method; /** * @var string Callback type */ protected $type; /** * @var array Valid callback types */ protected $types = array('function', 'static', 'instance'); /** * Constructor * * @param null|array $options */ public function __construct($options = null) { if ((null !== $options) && is_array($options)) { $this->setOptions($options); } } /** * Set object state from array of options * * @param array $options * @return \Zend\Server\Method\Callback */ 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 callback class * * @param string $class * @return \Zend\Server\Method\Callback */ public function setClass($class) { if (is_object($class)) { $class = get_class($class); } $this->class = $class; return $this; } /** * Get callback class * * @return string|null */ public function getClass() { return $this->class; } /** * Set callback function * * @param string $function * @return \Zend\Server\Method\Callback */ public function setFunction($function) { $this->function = (string) $function; $this->setType('function'); return $this; } /** * Get callback function * * @return null|string */ public function getFunction() { return $this->function; } /** * Set callback class method * * @param string $method * @return \Zend\Server\Method\Callback */ public function setMethod($method) { $this->method = $method; return $this; } /** * Get callback class method * * @return null|string */ public function getMethod() { return $this->method; } /** * Set callback type * * @param string $type * @return Callback * @throws Server\Exception\InvalidArgumentException */ public function setType($type) { if (!in_array($type, $this->types)) { throw new Server\Exception\InvalidArgumentException('Invalid method callback type "' . $type . '" passed to ' . __CLASS__ . '::' . __METHOD__); } $this->type = $type; return $this; } /** * Get callback type * * @return string */ public function getType() { return $this->type; } /** * Cast callback to array * * @return array */ public function toArray() { $type = $this->getType(); $array = array( 'type' => $type, ); if ('function' == $type) { $array['function'] = $this->getFunction(); } else { $array['class'] = $this->getClass(); $array['method'] = $this->getMethod(); } return $array; } } |