diff options
author | Francesco Rovelli <francesco.rovelli@gmail.com> | 2016-04-26 15:58:15 +0200 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2016-05-24 12:22:30 +0200 |
commit | c1583f03ab4eec08e66b7d5a9066ffd3bdf507b7 (patch) | |
tree | 4645be6f8c4935b632baa40cf70f097838bd8b60 /apps/files_external/3rdparty/google-api-php-client/src/Google/Model.php | |
parent | 4ffc936624d7a26271862a794fd472b1678de644 (diff) | |
download | nextcloud-server-c1583f03ab4eec08e66b7d5a9066ffd3bdf507b7.tar.gz nextcloud-server-c1583f03ab4eec08e66b7d5a9066ffd3bdf507b7.zip |
Update google-api-php-client from 1.0.6-beta to 1.1.7
Diffstat (limited to 'apps/files_external/3rdparty/google-api-php-client/src/Google/Model.php')
-rw-r--r-- | apps/files_external/3rdparty/google-api-php-client/src/Google/Model.php | 44 |
1 files changed, 37 insertions, 7 deletions
diff --git a/apps/files_external/3rdparty/google-api-php-client/src/Google/Model.php b/apps/files_external/3rdparty/google-api-php-client/src/Google/Model.php index 2bb9a333d66..df8216a80ed 100644 --- a/apps/files_external/3rdparty/google-api-php-client/src/Google/Model.php +++ b/apps/files_external/3rdparty/google-api-php-client/src/Google/Model.php @@ -20,11 +20,14 @@ * from a given json schema. * http://tools.ietf.org/html/draft-zyp-json-schema-03#section-5 * - * @author Chirag Shah <chirags@google.com> - * */ class Google_Model implements ArrayAccess { + /** + * If you need to specify a NULL JSON value, use Google_Model::NULL_VALUE + * instead - it will be replaced when converting to JSON with a real null. + */ + const NULL_VALUE = "{}gapi-php-null"; protected $internal_gapi_mappings = array(); protected $modelData = array(); protected $processed = array(); @@ -33,15 +36,21 @@ class Google_Model implements ArrayAccess * Polymorphic - accepts a variable number of arguments dependent * on the type of the model subclass. */ - public function __construct() + final public function __construct() { if (func_num_args() == 1 && is_array(func_get_arg(0))) { // Initialize the model with the array's contents. $array = func_get_arg(0); $this->mapTypes($array); } + $this->gapiInit(); } + /** + * Getter that handles passthrough access to the data array, and lazy object creation. + * @param string $key Property name. + * @return mixed The value if any, or null. + */ public function __get($key) { $keyTypeName = $this->keyType($key); @@ -87,7 +96,7 @@ class Google_Model implements ArrayAccess */ protected function mapTypes($array) { - // Hard initilise simple types, lazy load more complex ones. + // Hard initialise simple types, lazy load more complex ones. foreach ($array as $key => $val) { if ( !property_exists($this, $this->keyType($key)) && property_exists($this, $key)) { @@ -103,6 +112,16 @@ class Google_Model implements ArrayAccess } /** + * Blank initialiser to be used in subclasses to do post-construction initialisation - this + * avoids the need for subclasses to have to implement the variadics handling in their + * constructors. + */ + protected function gapiInit() + { + return; + } + + /** * Create a simplified object suitable for straightforward * conversion to JSON. This is relatively expensive * due to the usage of reflection, but shouldn't be called @@ -116,7 +135,7 @@ class Google_Model implements ArrayAccess foreach ($this->modelData as $key => $val) { $result = $this->getSimpleValue($val); if ($result !== null) { - $object->$key = $result; + $object->$key = $this->nullPlaceholderCheck($result); } } @@ -128,7 +147,7 @@ class Google_Model implements ArrayAccess $result = $this->getSimpleValue($this->$name); if ($result !== null) { $name = $this->getMappedName($name); - $object->$name = $result; + $object->$name = $this->nullPlaceholderCheck($result); } } @@ -149,13 +168,24 @@ class Google_Model implements ArrayAccess $a_value = $this->getSimpleValue($a_value); if ($a_value !== null) { $key = $this->getMappedName($key); - $return[$key] = $a_value; + $return[$key] = $this->nullPlaceholderCheck($a_value); } } return $return; } return $value; } + + /** + * Check whether the value is the null placeholder and return true null. + */ + private function nullPlaceholderCheck($value) + { + if ($value === self::NULL_VALUE) { + return null; + } + return $value; + } /** * If there is an internal name mapping, use that. |