PageRenderTime 48ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/zend/Zend/Server/Method/Callback.php

https://bitbucket.org/synergylearning/campusconnect
PHP | 205 lines | 83 code | 16 blank | 106 comment | 8 complexity | dd210417e3132defb91c98a816df683e MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, Apache-2.0, BSD-3-Clause, AGPL-3.0
  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 license@zend.com 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. * Method callback metadata
  24. *
  25. * @category Zend
  26. * @package Zend_Server
  27. * @subpackage Method
  28. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. */
  31. class Zend_Server_Method_Callback
  32. {
  33. /**
  34. * @var string Class name for class method callback
  35. */
  36. protected $_class;
  37. /**
  38. * @var string Function name for function callback
  39. */
  40. protected $_function;
  41. /**
  42. * @var string Method name for class method callback
  43. */
  44. protected $_method;
  45. /**
  46. * @var string Callback type
  47. */
  48. protected $_type;
  49. /**
  50. * @var array Valid callback types
  51. */
  52. protected $_types = array('function', 'static', 'instance');
  53. /**
  54. * Constructor
  55. *
  56. * @param null|array $options
  57. * @return void
  58. */
  59. public function __construct($options = null)
  60. {
  61. if ((null !== $options) && is_array($options)) {
  62. $this->setOptions($options);
  63. }
  64. }
  65. /**
  66. * Set object state from array of options
  67. *
  68. * @param array $options
  69. * @return Zend_Server_Method_Callback
  70. */
  71. public function setOptions(array $options)
  72. {
  73. foreach ($options as $key => $value) {
  74. $method = 'set' . ucfirst($key);
  75. if (method_exists($this, $method)) {
  76. $this->$method($value);
  77. }
  78. }
  79. return $this;
  80. }
  81. /**
  82. * Set callback class
  83. *
  84. * @param string $class
  85. * @return Zend_Server_Method_Callback
  86. */
  87. public function setClass($class)
  88. {
  89. if (is_object($class)) {
  90. $class = get_class($class);
  91. }
  92. $this->_class = $class;
  93. return $this;
  94. }
  95. /**
  96. * Get callback class
  97. *
  98. * @return string|null
  99. */
  100. public function getClass()
  101. {
  102. return $this->_class;
  103. }
  104. /**
  105. * Set callback function
  106. *
  107. * @param string $function
  108. * @return Zend_Server_Method_Callback
  109. */
  110. public function setFunction($function)
  111. {
  112. $this->_function = (string) $function;
  113. $this->setType('function');
  114. return $this;
  115. }
  116. /**
  117. * Get callback function
  118. *
  119. * @return null|string
  120. */
  121. public function getFunction()
  122. {
  123. return $this->_function;
  124. }
  125. /**
  126. * Set callback class method
  127. *
  128. * @param string $method
  129. * @return Zend_Server_Method_Callback
  130. */
  131. public function setMethod($method)
  132. {
  133. $this->_method = $method;
  134. return $this;
  135. }
  136. /**
  137. * Get callback class method
  138. *
  139. * @return null|string
  140. */
  141. public function getMethod()
  142. {
  143. return $this->_method;
  144. }
  145. /**
  146. * Set callback type
  147. *
  148. * @param string $type
  149. * @return Zend_Server_Method_Callback
  150. * @throws Zend_Server_Exception
  151. */
  152. public function setType($type)
  153. {
  154. if (!in_array($type, $this->_types)) {
  155. require_once 'Zend/Server/Exception.php';
  156. throw new Zend_Server_Exception('Invalid method callback type passed to ' . __CLASS__ . '::' . __METHOD__);
  157. }
  158. $this->_type = $type;
  159. return $this;
  160. }
  161. /**
  162. * Get callback type
  163. *
  164. * @return string
  165. */
  166. public function getType()
  167. {
  168. return $this->_type;
  169. }
  170. /**
  171. * Cast callback to array
  172. *
  173. * @return array
  174. */
  175. public function toArray()
  176. {
  177. $type = $this->getType();
  178. $array = array(
  179. 'type' => $type,
  180. );
  181. if ('function' == $type) {
  182. $array['function'] = $this->getFunction();
  183. } else {
  184. $array['class'] = $this->getClass();
  185. $array['method'] = $this->getMethod();
  186. }
  187. return $array;
  188. }
  189. }