File indexing completed on 2025-01-26 05:25:28
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Service 0017 * @subpackage StrikeIron 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 * @version $Id$ 0021 */ 0022 0023 /** 0024 * Decorates a StrikeIron response object returned by the SOAP extension 0025 * to provide more a PHP-like interface. 0026 * 0027 * @category Zend 0028 * @package Zend_Service 0029 * @subpackage StrikeIron 0030 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0031 * @license http://framework.zend.com/license/new-bsd New BSD License 0032 */ 0033 class Zend_Service_StrikeIron_Decorator 0034 { 0035 /** 0036 * Name of the decorated object 0037 * @var null|string 0038 */ 0039 protected $_name = null; 0040 0041 /** 0042 * Object to decorate 0043 * @var object 0044 */ 0045 protected $_object = null; 0046 0047 /** 0048 * Class constructor 0049 * 0050 * @param object $object Object to decorate 0051 * @param null|string $name Name of the object 0052 */ 0053 public function __construct($object, $name = null) 0054 { 0055 $this->_object = $object; 0056 $this->_name = $name; 0057 } 0058 0059 /** 0060 * Proxy property access to the decorated object, inflecting 0061 * the property name and decorating any child objects returned. 0062 * If the property is not found in the decorated object, return 0063 * NULL as a convenience feature to avoid notices. 0064 * 0065 * @param string $property Property name to retrieve 0066 * @return mixed Value of property or NULL 0067 */ 0068 public function __get($property) 0069 { 0070 $result = null; 0071 0072 if (! isset($this->_object->$property)) { 0073 $property = $this->_inflect($property); 0074 } 0075 0076 if (isset($this->_object->$property)) { 0077 $result = $this->_object->$property; 0078 $result = $this->_decorate($result); 0079 } 0080 return $result; 0081 } 0082 0083 /** 0084 * Proxy method calls to the decorated object. This will only 0085 * be used when the SOAPClient returns a custom PHP object via 0086 * its classmap option so no inflection is done. 0087 * 0088 * @param string $method Name of method called 0089 * @param array $args Arguments for method 0090 */ 0091 public function __call($method, $args) 0092 { 0093 return call_user_func_array(array($this->_object, $method), $args); 0094 } 0095 0096 /** 0097 * Inflect a property name from PHP-style to the result object's 0098 * style. The default implementation here only inflects the case 0099 * of the first letter, e.g. from "fooBar" to "FooBar". 0100 * 0101 * @param string $property Property name to inflect 0102 * @return string Inflected property name 0103 */ 0104 protected function _inflect($property) 0105 { 0106 return ucfirst($property); 0107 } 0108 0109 /** 0110 * Decorate a value returned by the result object. The default 0111 * implementation here only decorates child objects. 0112 * 0113 * @param mixed $result Value to decorate 0114 * @return mixed Decorated result 0115 */ 0116 protected function _decorate($result) 0117 { 0118 if (is_object($result)) { 0119 $result = new self($result); 0120 } 0121 return $result; 0122 } 0123 0124 /** 0125 * Return the object being decorated 0126 * 0127 * @return object 0128 */ 0129 public function getDecoratedObject() 0130 { 0131 return $this->_object; 0132 } 0133 0134 /** 0135 * Return the name of the object being decorated 0136 * 0137 * @return null|string 0138 */ 0139 public function getDecoratedObjectName() 0140 { 0141 return $this->_name; 0142 } 0143 }