@@ -14,21 +14,21 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | interface XmlSerializable |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * The xmlSerialize method is called during xml writing. |
|
| 19 | - * |
|
| 20 | - * Use the $writer argument to write its own xml serialization. |
|
| 21 | - * |
|
| 22 | - * An important note: do _not_ create a parent element. Any element |
|
| 23 | - * implementing XmlSerializable should only ever write what's considered |
|
| 24 | - * its 'inner xml'. |
|
| 25 | - * |
|
| 26 | - * The parent of the current element is responsible for writing a |
|
| 27 | - * containing element. |
|
| 28 | - * |
|
| 29 | - * This allows serializers to be re-used for different element names. |
|
| 30 | - * |
|
| 31 | - * If you are opening new elements, you must also close them again. |
|
| 32 | - */ |
|
| 33 | - public function xmlSerialize(Writer $writer); |
|
| 17 | + /** |
|
| 18 | + * The xmlSerialize method is called during xml writing. |
|
| 19 | + * |
|
| 20 | + * Use the $writer argument to write its own xml serialization. |
|
| 21 | + * |
|
| 22 | + * An important note: do _not_ create a parent element. Any element |
|
| 23 | + * implementing XmlSerializable should only ever write what's considered |
|
| 24 | + * its 'inner xml'. |
|
| 25 | + * |
|
| 26 | + * The parent of the current element is responsible for writing a |
|
| 27 | + * containing element. |
|
| 28 | + * |
|
| 29 | + * This allows serializers to be re-used for different element names. |
|
| 30 | + * |
|
| 31 | + * If you are opening new elements, you must also close them again. |
|
| 32 | + */ |
|
| 33 | + public function xmlSerialize(Writer $writer); |
|
| 34 | 34 | } |
@@ -23,96 +23,96 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | trait ContextStackTrait |
| 25 | 25 | { |
| 26 | - /** |
|
| 27 | - * This is the element map. It contains a list of XML elements (in clark |
|
| 28 | - * notation) as keys and PHP class names as values. |
|
| 29 | - * |
|
| 30 | - * The PHP class names must implement Sabre\Xml\Element. |
|
| 31 | - * |
|
| 32 | - * Values may also be a callable. In that case the function will be called |
|
| 33 | - * directly. |
|
| 34 | - * |
|
| 35 | - * @var array |
|
| 36 | - */ |
|
| 37 | - public $elementMap = []; |
|
| 26 | + /** |
|
| 27 | + * This is the element map. It contains a list of XML elements (in clark |
|
| 28 | + * notation) as keys and PHP class names as values. |
|
| 29 | + * |
|
| 30 | + * The PHP class names must implement Sabre\Xml\Element. |
|
| 31 | + * |
|
| 32 | + * Values may also be a callable. In that case the function will be called |
|
| 33 | + * directly. |
|
| 34 | + * |
|
| 35 | + * @var array |
|
| 36 | + */ |
|
| 37 | + public $elementMap = []; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * A contextUri pointing to the document being parsed / written. |
|
| 41 | - * This uri may be used to resolve relative urls that may appear in the |
|
| 42 | - * document. |
|
| 43 | - * |
|
| 44 | - * The reader and writer don't use this property, but as it's an extremely |
|
| 45 | - * common use-case for parsing XML documents, it's added here as a |
|
| 46 | - * convenience. |
|
| 47 | - * |
|
| 48 | - * @var string|null |
|
| 49 | - */ |
|
| 50 | - public $contextUri; |
|
| 39 | + /** |
|
| 40 | + * A contextUri pointing to the document being parsed / written. |
|
| 41 | + * This uri may be used to resolve relative urls that may appear in the |
|
| 42 | + * document. |
|
| 43 | + * |
|
| 44 | + * The reader and writer don't use this property, but as it's an extremely |
|
| 45 | + * common use-case for parsing XML documents, it's added here as a |
|
| 46 | + * convenience. |
|
| 47 | + * |
|
| 48 | + * @var string|null |
|
| 49 | + */ |
|
| 50 | + public $contextUri; |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * This is a list of namespaces that you want to give default prefixes. |
|
| 54 | - * |
|
| 55 | - * You must make sure you create this entire list before starting to write. |
|
| 56 | - * They should be registered on the root element. |
|
| 57 | - * |
|
| 58 | - * @var array |
|
| 59 | - */ |
|
| 60 | - public $namespaceMap = []; |
|
| 52 | + /** |
|
| 53 | + * This is a list of namespaces that you want to give default prefixes. |
|
| 54 | + * |
|
| 55 | + * You must make sure you create this entire list before starting to write. |
|
| 56 | + * They should be registered on the root element. |
|
| 57 | + * |
|
| 58 | + * @var array |
|
| 59 | + */ |
|
| 60 | + public $namespaceMap = []; |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * This is a list of custom serializers for specific classes. |
|
| 64 | - * |
|
| 65 | - * The writer may use this if you attempt to serialize an object with a |
|
| 66 | - * class that does not implement XmlSerializable. |
|
| 67 | - * |
|
| 68 | - * Instead it will look at this classmap to see if there is a custom |
|
| 69 | - * serializer here. This is useful if you don't want your value objects |
|
| 70 | - * to be responsible for serializing themselves. |
|
| 71 | - * |
|
| 72 | - * The keys in this classmap need to be fully qualified PHP class names, |
|
| 73 | - * the values must be callbacks. The callbacks take two arguments. The |
|
| 74 | - * writer class, and the value that must be written. |
|
| 75 | - * |
|
| 76 | - * function (Writer $writer, object $value) |
|
| 77 | - * |
|
| 78 | - * @var array |
|
| 79 | - */ |
|
| 80 | - public $classMap = []; |
|
| 62 | + /** |
|
| 63 | + * This is a list of custom serializers for specific classes. |
|
| 64 | + * |
|
| 65 | + * The writer may use this if you attempt to serialize an object with a |
|
| 66 | + * class that does not implement XmlSerializable. |
|
| 67 | + * |
|
| 68 | + * Instead it will look at this classmap to see if there is a custom |
|
| 69 | + * serializer here. This is useful if you don't want your value objects |
|
| 70 | + * to be responsible for serializing themselves. |
|
| 71 | + * |
|
| 72 | + * The keys in this classmap need to be fully qualified PHP class names, |
|
| 73 | + * the values must be callbacks. The callbacks take two arguments. The |
|
| 74 | + * writer class, and the value that must be written. |
|
| 75 | + * |
|
| 76 | + * function (Writer $writer, object $value) |
|
| 77 | + * |
|
| 78 | + * @var array |
|
| 79 | + */ |
|
| 80 | + public $classMap = []; |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * Backups of previous contexts. |
|
| 84 | - * |
|
| 85 | - * @var array |
|
| 86 | - */ |
|
| 87 | - protected $contextStack = []; |
|
| 82 | + /** |
|
| 83 | + * Backups of previous contexts. |
|
| 84 | + * |
|
| 85 | + * @var array |
|
| 86 | + */ |
|
| 87 | + protected $contextStack = []; |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * Create a new "context". |
|
| 91 | - * |
|
| 92 | - * This allows you to safely modify the elementMap, contextUri or |
|
| 93 | - * namespaceMap. After you're done, you can restore the old data again |
|
| 94 | - * with popContext. |
|
| 95 | - */ |
|
| 96 | - public function pushContext() |
|
| 97 | - { |
|
| 98 | - $this->contextStack[] = [ |
|
| 99 | - $this->elementMap, |
|
| 100 | - $this->contextUri, |
|
| 101 | - $this->namespaceMap, |
|
| 102 | - $this->classMap, |
|
| 103 | - ]; |
|
| 104 | - } |
|
| 89 | + /** |
|
| 90 | + * Create a new "context". |
|
| 91 | + * |
|
| 92 | + * This allows you to safely modify the elementMap, contextUri or |
|
| 93 | + * namespaceMap. After you're done, you can restore the old data again |
|
| 94 | + * with popContext. |
|
| 95 | + */ |
|
| 96 | + public function pushContext() |
|
| 97 | + { |
|
| 98 | + $this->contextStack[] = [ |
|
| 99 | + $this->elementMap, |
|
| 100 | + $this->contextUri, |
|
| 101 | + $this->namespaceMap, |
|
| 102 | + $this->classMap, |
|
| 103 | + ]; |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * Restore the previous "context". |
|
| 108 | - */ |
|
| 109 | - public function popContext() |
|
| 110 | - { |
|
| 111 | - list( |
|
| 112 | - $this->elementMap, |
|
| 113 | - $this->contextUri, |
|
| 114 | - $this->namespaceMap, |
|
| 115 | - $this->classMap |
|
| 116 | - ) = array_pop($this->contextStack); |
|
| 117 | - } |
|
| 106 | + /** |
|
| 107 | + * Restore the previous "context". |
|
| 108 | + */ |
|
| 109 | + public function popContext() |
|
| 110 | + { |
|
| 111 | + list( |
|
| 112 | + $this->elementMap, |
|
| 113 | + $this->contextUri, |
|
| 114 | + $this->namespaceMap, |
|
| 115 | + $this->classMap |
|
| 116 | + ) = array_pop($this->contextStack); |
|
| 117 | + } |
|
| 118 | 118 | } |
@@ -25,8 +25,9 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | public static function contains($haystack, $needle, $caseSensitive = true) |
| 27 | 27 | { |
| 28 | - if (empty($needle)) |
|
| 29 | - return true; |
|
| 28 | + if (empty($needle)) { |
|
| 29 | + return true; |
|
| 30 | + } |
|
| 30 | 31 | return $caseSensitive |
| 31 | 32 | ? strpos($haystack, $needle) !== false |
| 32 | 33 | : stripos($haystack, $needle) !== false; |
@@ -62,7 +63,9 @@ discard block |
||
| 62 | 63 | } |
| 63 | 64 | |
| 64 | 65 | // @CHANGE LDR |
| 65 | - if (!is_string($haystack)) return false; |
|
| 66 | + if (!is_string($haystack)) { |
|
| 67 | + return false; |
|
| 68 | + } |
|
| 66 | 69 | |
| 67 | 70 | return (substr($haystack, -$length) === $needle); |
| 68 | 71 | } |
@@ -14,21 +14,21 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class Arr |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * Deep copy given array |
|
| 19 | - * |
|
| 20 | - * @param array $arr |
|
| 21 | - * |
|
| 22 | - * @return array |
|
| 23 | - */ |
|
| 24 | - public static function copy(array $arr) |
|
| 25 | - { |
|
| 26 | - $copy = array(); |
|
| 27 | - foreach ($arr as $key => $value) { |
|
| 28 | - if (is_array($value)) $copy[$key] = static::copy($value); |
|
| 29 | - else if (is_object($value)) $copy[$key] = clone $value; |
|
| 30 | - else $copy[$key] = $value; |
|
| 31 | - } |
|
| 32 | - return $copy; |
|
| 33 | - } |
|
| 17 | + /** |
|
| 18 | + * Deep copy given array |
|
| 19 | + * |
|
| 20 | + * @param array $arr |
|
| 21 | + * |
|
| 22 | + * @return array |
|
| 23 | + */ |
|
| 24 | + public static function copy(array $arr) |
|
| 25 | + { |
|
| 26 | + $copy = array(); |
|
| 27 | + foreach ($arr as $key => $value) { |
|
| 28 | + if (is_array($value)) $copy[$key] = static::copy($value); |
|
| 29 | + else if (is_object($value)) $copy[$key] = clone $value; |
|
| 30 | + else $copy[$key] = $value; |
|
| 31 | + } |
|
| 32 | + return $copy; |
|
| 33 | + } |
|
| 34 | 34 | } |
| 35 | 35 | \ No newline at end of file |
@@ -25,9 +25,13 @@ |
||
| 25 | 25 | { |
| 26 | 26 | $copy = array(); |
| 27 | 27 | foreach ($arr as $key => $value) { |
| 28 | - if (is_array($value)) $copy[$key] = static::copy($value); |
|
| 29 | - else if (is_object($value)) $copy[$key] = clone $value; |
|
| 30 | - else $copy[$key] = $value; |
|
| 28 | + if (is_array($value)) { |
|
| 29 | + $copy[$key] = static::copy($value); |
|
| 30 | + } else if (is_object($value)) { |
|
| 31 | + $copy[$key] = clone $value; |
|
| 32 | + } else { |
|
| 33 | + $copy[$key] = $value; |
|
| 34 | + } |
|
| 31 | 35 | } |
| 32 | 36 | return $copy; |
| 33 | 37 | } |
@@ -14,19 +14,19 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | interface iValidate { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * method used for validation. |
|
| 19 | - * |
|
| 20 | - * @param mixed $input |
|
| 21 | - * data that needs to be validated |
|
| 22 | - * @param ValidationInfo $info |
|
| 23 | - * information to be used for validation |
|
| 24 | - * @return boolean false in case of failure or fixed value in the expected |
|
| 25 | - * type |
|
| 26 | - * @throws \Luracast\Restler\RestException 400 with information about the |
|
| 27 | - * failed |
|
| 28 | - * validation |
|
| 29 | - */ |
|
| 30 | - public static function validate($input, ValidationInfo $info); |
|
| 17 | + /** |
|
| 18 | + * method used for validation. |
|
| 19 | + * |
|
| 20 | + * @param mixed $input |
|
| 21 | + * data that needs to be validated |
|
| 22 | + * @param ValidationInfo $info |
|
| 23 | + * information to be used for validation |
|
| 24 | + * @return boolean false in case of failure or fixed value in the expected |
|
| 25 | + * type |
|
| 26 | + * @throws \Luracast\Restler\RestException 400 with information about the |
|
| 27 | + * failed |
|
| 28 | + * validation |
|
| 29 | + */ |
|
| 30 | + public static function validate($input, ValidationInfo $info); |
|
| 31 | 31 | } |
| 32 | 32 | |
@@ -15,143 +15,143 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class Obj |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * @var bool|string|callable |
|
| 20 | - */ |
|
| 21 | - public static $stringEncoderFunction = false; |
|
| 22 | - /** |
|
| 23 | - * @var bool|string|callable |
|
| 24 | - */ |
|
| 25 | - public static $numberEncoderFunction = false; |
|
| 26 | - /** |
|
| 27 | - * @var array key value pairs for fixing value types using functions. |
|
| 28 | - * For example |
|
| 29 | - * |
|
| 30 | - * 'id'=>'intval' will make sure all values of the id properties |
|
| 31 | - * will be converted to integers intval function |
|
| 32 | - * 'password'=> null will remove all the password entries |
|
| 33 | - */ |
|
| 34 | - public static $fix = array(); |
|
| 35 | - /** |
|
| 36 | - * @var string character that is used to identify sub objects |
|
| 37 | - * |
|
| 38 | - * For example |
|
| 39 | - * |
|
| 40 | - * when Object::$separatorChar = '.'; |
|
| 41 | - * |
|
| 42 | - * array('my.object'=>true) will result in |
|
| 43 | - * |
|
| 44 | - * array( |
|
| 45 | - * 'my'=>array('object'=>true) |
|
| 46 | - * ); |
|
| 47 | - */ |
|
| 48 | - public static $separatorChar = null; |
|
| 49 | - /** |
|
| 50 | - * @var bool set it to true when empty arrays, blank strings, null values |
|
| 51 | - * to be automatically removed from response |
|
| 52 | - */ |
|
| 53 | - public static $removeEmpty = false; |
|
| 54 | - /** |
|
| 55 | - * @var bool set it to true to remove all null values from the result |
|
| 56 | - */ |
|
| 57 | - public static $removeNull = false; |
|
| 18 | + /** |
|
| 19 | + * @var bool|string|callable |
|
| 20 | + */ |
|
| 21 | + public static $stringEncoderFunction = false; |
|
| 22 | + /** |
|
| 23 | + * @var bool|string|callable |
|
| 24 | + */ |
|
| 25 | + public static $numberEncoderFunction = false; |
|
| 26 | + /** |
|
| 27 | + * @var array key value pairs for fixing value types using functions. |
|
| 28 | + * For example |
|
| 29 | + * |
|
| 30 | + * 'id'=>'intval' will make sure all values of the id properties |
|
| 31 | + * will be converted to integers intval function |
|
| 32 | + * 'password'=> null will remove all the password entries |
|
| 33 | + */ |
|
| 34 | + public static $fix = array(); |
|
| 35 | + /** |
|
| 36 | + * @var string character that is used to identify sub objects |
|
| 37 | + * |
|
| 38 | + * For example |
|
| 39 | + * |
|
| 40 | + * when Object::$separatorChar = '.'; |
|
| 41 | + * |
|
| 42 | + * array('my.object'=>true) will result in |
|
| 43 | + * |
|
| 44 | + * array( |
|
| 45 | + * 'my'=>array('object'=>true) |
|
| 46 | + * ); |
|
| 47 | + */ |
|
| 48 | + public static $separatorChar = null; |
|
| 49 | + /** |
|
| 50 | + * @var bool set it to true when empty arrays, blank strings, null values |
|
| 51 | + * to be automatically removed from response |
|
| 52 | + */ |
|
| 53 | + public static $removeEmpty = false; |
|
| 54 | + /** |
|
| 55 | + * @var bool set it to true to remove all null values from the result |
|
| 56 | + */ |
|
| 57 | + public static $removeNull = false; |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Convenience function that converts the given object |
|
| 61 | - * in to associative array |
|
| 62 | - * |
|
| 63 | - * @static |
|
| 64 | - * |
|
| 65 | - * @param mixed $object that needs to be converted |
|
| 66 | - * |
|
| 67 | - * @param bool $forceObjectTypeWhenEmpty when set to true outputs |
|
| 68 | - * actual type (array or |
|
| 69 | - * object) rather than |
|
| 70 | - * always an array when the |
|
| 71 | - * array/object is empty |
|
| 72 | - * |
|
| 73 | - * @return array |
|
| 74 | - */ |
|
| 75 | - public static function toArray($object, |
|
| 76 | - $forceObjectTypeWhenEmpty = false) |
|
| 77 | - { |
|
| 78 | - //if ($object instanceof JsonSerializable) { //wont work on PHP < 5.4 |
|
| 79 | - if (is_object($object)) { |
|
| 80 | - if (method_exists($object, 'jsonSerialize')) { |
|
| 81 | - $object = $object->jsonSerialize(); |
|
| 82 | - } elseif (method_exists($object, '__sleep')) { |
|
| 83 | - $properties = $object->__sleep(); |
|
| 84 | - $array = array(); |
|
| 85 | - foreach ($properties as $key) { |
|
| 86 | - $value = self::toArray($object->{$key}, |
|
| 87 | - $forceObjectTypeWhenEmpty); |
|
| 88 | - if (self::$stringEncoderFunction && is_string($value)) { |
|
| 89 | - $value = self::$stringEncoderFunction ($value); |
|
| 90 | - } elseif (self::$numberEncoderFunction && is_numeric($value)) { |
|
| 91 | - $value = self::$numberEncoderFunction ($value); |
|
| 92 | - } |
|
| 93 | - $array [$key] = $value; |
|
| 94 | - } |
|
| 95 | - return $array; |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - if (is_array($object) || is_object($object)) { |
|
| 99 | - $count = 0; |
|
| 100 | - $array = array(); |
|
| 101 | - foreach ($object as $key => $value) { |
|
| 102 | - if ( |
|
| 103 | - is_string(self::$separatorChar) && |
|
| 104 | - false !== strpos($key, self::$separatorChar) |
|
| 105 | - ) { |
|
| 106 | - list($key, $obj) = explode(self::$separatorChar, $key, 2); |
|
| 107 | - $object[$key][$obj] = $value; |
|
| 108 | - $value = $object[$key]; |
|
| 109 | - } |
|
| 110 | - if (self::$removeEmpty && empty($value) && !is_numeric($value) && !is_bool($value)) { |
|
| 111 | - continue; |
|
| 112 | - } elseif (self::$removeNull && is_null($value)) { |
|
| 113 | - continue; |
|
| 114 | - } |
|
| 115 | - if (array_key_exists($key, self::$fix)) { |
|
| 116 | - if (isset(self::$fix[$key])) { |
|
| 117 | - $value = call_user_func(self::$fix[$key], $value); |
|
| 118 | - } else { |
|
| 119 | - continue; |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - $value = self::toArray($value, $forceObjectTypeWhenEmpty); |
|
| 123 | - if (self::$stringEncoderFunction && is_string($value)) { |
|
| 124 | - $value = self::$encoderFunctionName ($value); |
|
| 125 | - } elseif (self::$numberEncoderFunction && is_numeric($value)) { |
|
| 126 | - $value = self::$numberEncoderFunction ($value); |
|
| 127 | - } |
|
| 128 | - $array [$key] = $value; |
|
| 129 | - $count++; |
|
| 130 | - } |
|
| 131 | - return $forceObjectTypeWhenEmpty && $count == 0 ? $object : $array; |
|
| 132 | - } |
|
| 59 | + /** |
|
| 60 | + * Convenience function that converts the given object |
|
| 61 | + * in to associative array |
|
| 62 | + * |
|
| 63 | + * @static |
|
| 64 | + * |
|
| 65 | + * @param mixed $object that needs to be converted |
|
| 66 | + * |
|
| 67 | + * @param bool $forceObjectTypeWhenEmpty when set to true outputs |
|
| 68 | + * actual type (array or |
|
| 69 | + * object) rather than |
|
| 70 | + * always an array when the |
|
| 71 | + * array/object is empty |
|
| 72 | + * |
|
| 73 | + * @return array |
|
| 74 | + */ |
|
| 75 | + public static function toArray($object, |
|
| 76 | + $forceObjectTypeWhenEmpty = false) |
|
| 77 | + { |
|
| 78 | + //if ($object instanceof JsonSerializable) { //wont work on PHP < 5.4 |
|
| 79 | + if (is_object($object)) { |
|
| 80 | + if (method_exists($object, 'jsonSerialize')) { |
|
| 81 | + $object = $object->jsonSerialize(); |
|
| 82 | + } elseif (method_exists($object, '__sleep')) { |
|
| 83 | + $properties = $object->__sleep(); |
|
| 84 | + $array = array(); |
|
| 85 | + foreach ($properties as $key) { |
|
| 86 | + $value = self::toArray($object->{$key}, |
|
| 87 | + $forceObjectTypeWhenEmpty); |
|
| 88 | + if (self::$stringEncoderFunction && is_string($value)) { |
|
| 89 | + $value = self::$stringEncoderFunction ($value); |
|
| 90 | + } elseif (self::$numberEncoderFunction && is_numeric($value)) { |
|
| 91 | + $value = self::$numberEncoderFunction ($value); |
|
| 92 | + } |
|
| 93 | + $array [$key] = $value; |
|
| 94 | + } |
|
| 95 | + return $array; |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + if (is_array($object) || is_object($object)) { |
|
| 99 | + $count = 0; |
|
| 100 | + $array = array(); |
|
| 101 | + foreach ($object as $key => $value) { |
|
| 102 | + if ( |
|
| 103 | + is_string(self::$separatorChar) && |
|
| 104 | + false !== strpos($key, self::$separatorChar) |
|
| 105 | + ) { |
|
| 106 | + list($key, $obj) = explode(self::$separatorChar, $key, 2); |
|
| 107 | + $object[$key][$obj] = $value; |
|
| 108 | + $value = $object[$key]; |
|
| 109 | + } |
|
| 110 | + if (self::$removeEmpty && empty($value) && !is_numeric($value) && !is_bool($value)) { |
|
| 111 | + continue; |
|
| 112 | + } elseif (self::$removeNull && is_null($value)) { |
|
| 113 | + continue; |
|
| 114 | + } |
|
| 115 | + if (array_key_exists($key, self::$fix)) { |
|
| 116 | + if (isset(self::$fix[$key])) { |
|
| 117 | + $value = call_user_func(self::$fix[$key], $value); |
|
| 118 | + } else { |
|
| 119 | + continue; |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + $value = self::toArray($value, $forceObjectTypeWhenEmpty); |
|
| 123 | + if (self::$stringEncoderFunction && is_string($value)) { |
|
| 124 | + $value = self::$encoderFunctionName ($value); |
|
| 125 | + } elseif (self::$numberEncoderFunction && is_numeric($value)) { |
|
| 126 | + $value = self::$numberEncoderFunction ($value); |
|
| 127 | + } |
|
| 128 | + $array [$key] = $value; |
|
| 129 | + $count++; |
|
| 130 | + } |
|
| 131 | + return $forceObjectTypeWhenEmpty && $count == 0 ? $object : $array; |
|
| 132 | + } |
|
| 133 | 133 | |
| 134 | - return $object; |
|
| 135 | - } |
|
| 134 | + return $object; |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | - public function __get($name) |
|
| 138 | - { |
|
| 139 | - isset(self::$fix[$name]) ? self::$fix[$name] : null; |
|
| 140 | - } |
|
| 137 | + public function __get($name) |
|
| 138 | + { |
|
| 139 | + isset(self::$fix[$name]) ? self::$fix[$name] : null; |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - public function __set($name, $function) |
|
| 143 | - { |
|
| 144 | - self::$fix[$name] = $function; |
|
| 145 | - } |
|
| 142 | + public function __set($name, $function) |
|
| 143 | + { |
|
| 144 | + self::$fix[$name] = $function; |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - public function __isset($name) |
|
| 148 | - { |
|
| 149 | - return isset(self::$fix[$name]); |
|
| 150 | - } |
|
| 147 | + public function __isset($name) |
|
| 148 | + { |
|
| 149 | + return isset(self::$fix[$name]); |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - public function __unset($name) |
|
| 153 | - { |
|
| 154 | - unset(self::$fix[$name]); |
|
| 155 | - } |
|
| 152 | + public function __unset($name) |
|
| 153 | + { |
|
| 154 | + unset(self::$fix[$name]); |
|
| 155 | + } |
|
| 156 | 156 | } |
| 157 | 157 | |
@@ -86,9 +86,9 @@ discard block |
||
| 86 | 86 | $value = self::toArray($object->{$key}, |
| 87 | 87 | $forceObjectTypeWhenEmpty); |
| 88 | 88 | if (self::$stringEncoderFunction && is_string($value)) { |
| 89 | - $value = self::$stringEncoderFunction ($value); |
|
| 89 | + $value = self::$stringEncoderFunction($value); |
|
| 90 | 90 | } elseif (self::$numberEncoderFunction && is_numeric($value)) { |
| 91 | - $value = self::$numberEncoderFunction ($value); |
|
| 91 | + $value = self::$numberEncoderFunction($value); |
|
| 92 | 92 | } |
| 93 | 93 | $array [$key] = $value; |
| 94 | 94 | } |
@@ -121,9 +121,9 @@ discard block |
||
| 121 | 121 | } |
| 122 | 122 | $value = self::toArray($value, $forceObjectTypeWhenEmpty); |
| 123 | 123 | if (self::$stringEncoderFunction && is_string($value)) { |
| 124 | - $value = self::$encoderFunctionName ($value); |
|
| 124 | + $value = self::$encoderFunctionName($value); |
|
| 125 | 125 | } elseif (self::$numberEncoderFunction && is_numeric($value)) { |
| 126 | - $value = self::$numberEncoderFunction ($value); |
|
| 126 | + $value = self::$numberEncoderFunction($value); |
|
| 127 | 127 | } |
| 128 | 128 | $array [$key] = $value; |
| 129 | 129 | $count++; |
@@ -16,46 +16,46 @@ |
||
| 16 | 16 | class ValueObject implements iValueObject |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - public function __toString() |
|
| 20 | - { |
|
| 21 | - return ' new ' . get_called_class() . '() '; |
|
| 22 | - } |
|
| 19 | + public function __toString() |
|
| 20 | + { |
|
| 21 | + return ' new ' . get_called_class() . '() '; |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - public static function __set_state(array $properties) |
|
| 25 | - { |
|
| 26 | - $class = get_called_class(); |
|
| 27 | - $instance = new $class (); |
|
| 28 | - $vars = get_object_vars($instance); |
|
| 29 | - foreach ($properties as $property => $value) { |
|
| 30 | - if (property_exists($instance, $property)) { |
|
| 31 | - // see if the property is accessible |
|
| 32 | - if (array_key_exists($property, $vars)) { |
|
| 33 | - $instance->{$property} = $value; |
|
| 34 | - } else { |
|
| 35 | - $method = 'set' . ucfirst($property); |
|
| 36 | - if (method_exists($instance, $method)) { |
|
| 37 | - call_user_func(array( |
|
| 38 | - $instance, |
|
| 39 | - $method |
|
| 40 | - ), $value); |
|
| 41 | - } |
|
| 42 | - } |
|
| 43 | - } |
|
| 44 | - } |
|
| 45 | - return $instance; |
|
| 46 | - } |
|
| 24 | + public static function __set_state(array $properties) |
|
| 25 | + { |
|
| 26 | + $class = get_called_class(); |
|
| 27 | + $instance = new $class (); |
|
| 28 | + $vars = get_object_vars($instance); |
|
| 29 | + foreach ($properties as $property => $value) { |
|
| 30 | + if (property_exists($instance, $property)) { |
|
| 31 | + // see if the property is accessible |
|
| 32 | + if (array_key_exists($property, $vars)) { |
|
| 33 | + $instance->{$property} = $value; |
|
| 34 | + } else { |
|
| 35 | + $method = 'set' . ucfirst($property); |
|
| 36 | + if (method_exists($instance, $method)) { |
|
| 37 | + call_user_func(array( |
|
| 38 | + $instance, |
|
| 39 | + $method |
|
| 40 | + ), $value); |
|
| 41 | + } |
|
| 42 | + } |
|
| 43 | + } |
|
| 44 | + } |
|
| 45 | + return $instance; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - public function __toArray() |
|
| 49 | - { |
|
| 50 | - $r = get_object_vars($this); |
|
| 51 | - $methods = get_class_methods($this); |
|
| 52 | - foreach ($methods as $m) { |
|
| 53 | - if (substr($m, 0, 3) == 'get') { |
|
| 54 | - $r [lcfirst(substr($m, 3))] = @$this->{$m} (); |
|
| 55 | - } |
|
| 56 | - } |
|
| 57 | - return $r; |
|
| 58 | - } |
|
| 48 | + public function __toArray() |
|
| 49 | + { |
|
| 50 | + $r = get_object_vars($this); |
|
| 51 | + $methods = get_class_methods($this); |
|
| 52 | + foreach ($methods as $m) { |
|
| 53 | + if (substr($m, 0, 3) == 'get') { |
|
| 54 | + $r [lcfirst(substr($m, 3))] = @$this->{$m} (); |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | + return $r; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | 60 | } |
| 61 | 61 | |
@@ -18,13 +18,13 @@ discard block |
||
| 18 | 18 | |
| 19 | 19 | public function __toString() |
| 20 | 20 | { |
| 21 | - return ' new ' . get_called_class() . '() '; |
|
| 21 | + return ' new '.get_called_class().'() '; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | public static function __set_state(array $properties) |
| 25 | 25 | { |
| 26 | 26 | $class = get_called_class(); |
| 27 | - $instance = new $class (); |
|
| 27 | + $instance = new $class(); |
|
| 28 | 28 | $vars = get_object_vars($instance); |
| 29 | 29 | foreach ($properties as $property => $value) { |
| 30 | 30 | if (property_exists($instance, $property)) { |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | if (array_key_exists($property, $vars)) { |
| 33 | 33 | $instance->{$property} = $value; |
| 34 | 34 | } else { |
| 35 | - $method = 'set' . ucfirst($property); |
|
| 35 | + $method = 'set'.ucfirst($property); |
|
| 36 | 36 | if (method_exists($instance, $method)) { |
| 37 | 37 | call_user_func(array( |
| 38 | 38 | $instance, |
@@ -16,24 +16,24 @@ |
||
| 16 | 16 | interface iValueObject |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * This static method is called for creating an instance of the class by |
|
| 21 | - * passing the initiation values as an array. |
|
| 22 | - * |
|
| 23 | - * @static |
|
| 24 | - * @abstract |
|
| 25 | - * |
|
| 26 | - * @param array $properties |
|
| 27 | - * |
|
| 28 | - * @return iValueObject |
|
| 29 | - */ |
|
| 30 | - public static function __set_state(array $properties); |
|
| 19 | + /** |
|
| 20 | + * This static method is called for creating an instance of the class by |
|
| 21 | + * passing the initiation values as an array. |
|
| 22 | + * |
|
| 23 | + * @static |
|
| 24 | + * @abstract |
|
| 25 | + * |
|
| 26 | + * @param array $properties |
|
| 27 | + * |
|
| 28 | + * @return iValueObject |
|
| 29 | + */ |
|
| 30 | + public static function __set_state(array $properties); |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * This method provides a string representation for the instance |
|
| 34 | - * |
|
| 35 | - * @return string |
|
| 36 | - */ |
|
| 37 | - public function __toString(); |
|
| 32 | + /** |
|
| 33 | + * This method provides a string representation for the instance |
|
| 34 | + * |
|
| 35 | + * @return string |
|
| 36 | + */ |
|
| 37 | + public function __toString(); |
|
| 38 | 38 | } |
| 39 | 39 | |
@@ -15,41 +15,41 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class ApiMethodInfo extends ValueObject |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * @var string target url |
|
| 20 | - */ |
|
| 21 | - public $url; |
|
| 22 | - /** |
|
| 23 | - * @var string |
|
| 24 | - */ |
|
| 25 | - public $className; |
|
| 26 | - /** |
|
| 27 | - * @var string |
|
| 28 | - */ |
|
| 29 | - public $methodName; |
|
| 30 | - /** |
|
| 31 | - * @var array parameters to be passed to the api method |
|
| 32 | - */ |
|
| 33 | - public $parameters = array(); |
|
| 34 | - /** |
|
| 35 | - * @var array information on parameters in the form of array(name => index) |
|
| 36 | - */ |
|
| 37 | - public $arguments = array(); |
|
| 38 | - /** |
|
| 39 | - * @var array default values for parameters if any |
|
| 40 | - * in the form of array(index => value) |
|
| 41 | - */ |
|
| 42 | - public $defaults = array(); |
|
| 43 | - /** |
|
| 44 | - * @var array key => value pair of method meta information |
|
| 45 | - */ |
|
| 46 | - public $metadata = array(); |
|
| 47 | - /** |
|
| 48 | - * @var int access level |
|
| 49 | - * 0 - @public - available for all |
|
| 50 | - * 1 - @hybrid - both public and protected (enhanced info for authorized) |
|
| 51 | - * 2 - @protected comment - only for authenticated users |
|
| 52 | - * 3 - protected method - only for authenticated users |
|
| 53 | - */ |
|
| 54 | - public $accessLevel = 0; |
|
| 18 | + /** |
|
| 19 | + * @var string target url |
|
| 20 | + */ |
|
| 21 | + public $url; |
|
| 22 | + /** |
|
| 23 | + * @var string |
|
| 24 | + */ |
|
| 25 | + public $className; |
|
| 26 | + /** |
|
| 27 | + * @var string |
|
| 28 | + */ |
|
| 29 | + public $methodName; |
|
| 30 | + /** |
|
| 31 | + * @var array parameters to be passed to the api method |
|
| 32 | + */ |
|
| 33 | + public $parameters = array(); |
|
| 34 | + /** |
|
| 35 | + * @var array information on parameters in the form of array(name => index) |
|
| 36 | + */ |
|
| 37 | + public $arguments = array(); |
|
| 38 | + /** |
|
| 39 | + * @var array default values for parameters if any |
|
| 40 | + * in the form of array(index => value) |
|
| 41 | + */ |
|
| 42 | + public $defaults = array(); |
|
| 43 | + /** |
|
| 44 | + * @var array key => value pair of method meta information |
|
| 45 | + */ |
|
| 46 | + public $metadata = array(); |
|
| 47 | + /** |
|
| 48 | + * @var int access level |
|
| 49 | + * 0 - @public - available for all |
|
| 50 | + * 1 - @hybrid - both public and protected (enhanced info for authorized) |
|
| 51 | + * 2 - @protected comment - only for authenticated users |
|
| 52 | + * 3 - protected method - only for authenticated users |
|
| 53 | + */ |
|
| 54 | + public $accessLevel = 0; |
|
| 55 | 55 | } |
| 56 | 56 | \ No newline at end of file |