[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/lib/zend/Zend/Server/Method/ -> Callback.php (source)

   1  <?php
   2  /**
   3   * Zend Framework
   4   *
   5   * LICENSE
   6   *
   7   * This source file is subject to the new BSD license that is bundled
   8   * with this package in the file LICENSE.txt.
   9   * It is also available through the world-wide-web at this URL:
  10   * http://framework.zend.com/license/new-bsd
  11   * If you did not receive a copy of the license and are unable to
  12   * obtain it through the world-wide-web, please send an email
  13   * to [email protected] so we can send you a copy immediately.
  14   *
  15   * @category   Zend
  16   * @package    Zend_Server
  17   * @subpackage Method
  18   * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  19   * @license    http://framework.zend.com/license/new-bsd     New BSD License
  20   * @version    $Id$
  21   */
  22  
  23  /**
  24   * Method callback metadata
  25   *
  26   * @category   Zend
  27   * @package    Zend_Server
  28   * @subpackage Method
  29   * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  30   * @license    http://framework.zend.com/license/new-bsd     New BSD License
  31   */
  32  class Zend_Server_Method_Callback
  33  {
  34      /**
  35       * @var string Class name for class method callback
  36       */
  37      protected $_class;
  38  
  39      /**
  40       * @var string Function name for function callback
  41       */
  42      protected $_function;
  43  
  44      /**
  45       * @var string Method name for class method callback
  46       */
  47      protected $_method;
  48  
  49      /**
  50       * @var string Callback type
  51       */
  52      protected $_type;
  53  
  54      /**
  55       * @var array Valid callback types
  56       */
  57      protected $_types = array('function', 'static', 'instance');
  58  
  59      /**
  60       * Constructor
  61       *
  62       * @param  null|array $options
  63       * @return void
  64       */
  65      public function __construct($options = null)
  66      {
  67          if ((null !== $options) && is_array($options))  {
  68              $this->setOptions($options);
  69          }
  70      }
  71  
  72      /**
  73       * Set object state from array of options
  74       *
  75       * @param  array $options
  76       * @return Zend_Server_Method_Callback
  77       */
  78      public function setOptions(array $options)
  79      {
  80          foreach ($options as $key => $value) {
  81              $method = 'set' . ucfirst($key);
  82              if (method_exists($this, $method)) {
  83                  $this->$method($value);
  84              }
  85          }
  86          return $this;
  87      }
  88  
  89      /**
  90       * Set callback class
  91       *
  92       * @param  string $class
  93       * @return Zend_Server_Method_Callback
  94       */
  95      public function setClass($class)
  96      {
  97          if (is_object($class)) {
  98              $class = get_class($class);
  99          }
 100          $this->_class = $class;
 101          return $this;
 102      }
 103  
 104      /**
 105       * Get callback class
 106       *
 107       * @return string|null
 108       */
 109      public function getClass()
 110      {
 111          return $this->_class;
 112      }
 113  
 114      /**
 115       * Set callback function
 116       *
 117       * @param  string $function
 118       * @return Zend_Server_Method_Callback
 119       */
 120      public function setFunction($function)
 121      {
 122          $this->_function = (string) $function;
 123          $this->setType('function');
 124          return $this;
 125      }
 126  
 127      /**
 128       * Get callback function
 129       *
 130       * @return null|string
 131       */
 132      public function getFunction()
 133      {
 134          return $this->_function;
 135      }
 136  
 137      /**
 138       * Set callback class method
 139       *
 140       * @param  string $method
 141       * @return Zend_Server_Method_Callback
 142       */
 143      public function setMethod($method)
 144      {
 145          $this->_method = $method;
 146          return $this;
 147      }
 148  
 149      /**
 150       * Get callback class  method
 151       *
 152       * @return null|string
 153       */
 154      public function getMethod()
 155      {
 156          return $this->_method;
 157      }
 158  
 159      /**
 160       * Set callback type
 161       *
 162       * @param  string $type
 163       * @return Zend_Server_Method_Callback
 164       * @throws Zend_Server_Exception
 165       */
 166      public function setType($type)
 167      {
 168          if (!in_array($type, $this->_types)) {
 169              require_once 'Zend/Server/Exception.php';
 170              throw new Zend_Server_Exception('Invalid method callback type  passed to ' . __CLASS__ . '::' . __METHOD__);
 171          }
 172          $this->_type = $type;
 173          return $this;
 174      }
 175  
 176      /**
 177       * Get callback type
 178       *
 179       * @return string
 180       */
 181      public function getType()
 182      {
 183          return $this->_type;
 184      }
 185  
 186      /**
 187       * Cast callback to array
 188       *
 189       * @return array
 190       */
 191      public function toArray()
 192      {
 193          $type = $this->getType();
 194          $array = array(
 195              'type' => $type,
 196          );
 197          if ('function' == $type) {
 198              $array['function'] = $this->getFunction();
 199          } else {
 200              $array['class']  = $this->getClass();
 201              $array['method'] = $this->getMethod();
 202          }
 203          return $array;
 204      }
 205  }


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1