|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace WsdlToPhp\PackageBase; |
| 4 | + |
| 5 | +abstract class AbstractStructBase |
| 6 | +{ |
| 7 | + /** |
| 8 | + * Generic method called when an object has been exported with var_export() functions |
| 9 | + * It allows to return an object instantiated with the values |
| 10 | + * @uses ApiWsdlClass::_set() |
| 11 | + * @param array $array the exported values |
| 12 | + * @return Struct |
| 13 | + */ |
| 14 | + public static function __set_state(array $array) |
| 15 | + { |
| 16 | + $className = get_called_class(); |
| 17 | + $object = @new $className(); |
| 18 | + foreach ($array as $name=>$value) { |
| 19 | + $object->_set($name, $value); |
| 20 | + } |
| 21 | + return $object; |
| 22 | + } |
| 23 | + /** |
| 24 | + * Generic method setting value |
| 25 | + * @throws \InvalidArgumentException |
| 26 | + * @param string $name property name to set |
| 27 | + * @param mixed $value property value to use |
| 28 | + * @return Struct |
| 29 | + */ |
| 30 | + public function _set($name, $value) |
| 31 | + { |
| 32 | + $setMethod = 'set' . ucfirst($name); |
| 33 | + if (method_exists($this, $setMethod)) { |
| 34 | + $this->$setMethod($value); |
| 35 | + } else { |
| 36 | + throw new \InvalidArgumentException(sprintf('Setter does not exist for "%s" property', $name)); |
| 37 | + } |
| 38 | + return $this; |
| 39 | + } |
| 40 | + /** |
| 41 | + * Generic method getting value |
| 42 | + * @throws \InvalidArgumentException |
| 43 | + * @param string $name property name to get |
| 44 | + * @return mixed |
| 45 | + */ |
| 46 | + public function _get($name) |
| 47 | + { |
| 48 | + $getMethod = 'get' . ucfirst($name); |
| 49 | + if (method_exists($this, $getMethod)) { |
| 50 | + return $this->$getMethod(); |
| 51 | + } |
| 52 | + throw new \InvalidArgumentException(sprintf('Getter does not exist for "%s" property', $name)); |
| 53 | + } |
| 54 | +} |
0 commit comments