diff options
| author | EoleDev <EoleDev@outlook.fr> | 2016-04-14 16:28:25 +0200 |
|---|---|---|
| committer | EoleDev <EoleDev@outlook.fr> | 2016-04-14 16:28:25 +0200 |
| commit | 31d2d0c158ad4daa3dde7a905f3c2e312c194f2e (patch) | |
| tree | 43d761d2aec8265a22c0fdedcc365bacc10dc814 /server/vendor/php-opencloud/common/src/Common/Transport/JsonSerializer.php | |
| parent | 27730911d8c9253a4f5aa90450c57cdeca9d5d26 (diff) | |
| parent | b348dbc2266a3e8070a3951fb0bd8c19b852ec47 (diff) | |
Merge branch 'compute'
Conflicts:
server/core/LibOverride/genTokenOptions.php
Diffstat (limited to 'server/vendor/php-opencloud/common/src/Common/Transport/JsonSerializer.php')
| -rwxr-xr-x | server/vendor/php-opencloud/common/src/Common/Transport/JsonSerializer.php | 95 |
1 files changed, 0 insertions, 95 deletions
diff --git a/server/vendor/php-opencloud/common/src/Common/Transport/JsonSerializer.php b/server/vendor/php-opencloud/common/src/Common/Transport/JsonSerializer.php deleted file mode 100755 index 4d0b2e4..0000000 --- a/server/vendor/php-opencloud/common/src/Common/Transport/JsonSerializer.php +++ /dev/null @@ -1,95 +0,0 @@ -<?php declare(strict_types=1); - -namespace OpenCloud\Common\Transport; - -use OpenCloud\Common\Api\Parameter; -use OpenCloud\Common\JsonPath; - -/** - * Class responsible for populating the JSON body of a {@see GuzzleHttp\Message\Request} object. - * - * @package OpenCloud\Common\Transport - */ -class JsonSerializer -{ - /** - * Populates the actual value into a JSON field, i.e. it has reached the end of the line and no - * further nesting is required. - * - * @param Parameter $param The schema that defines how the JSON field is being populated - * @param mixed $userValue The user value that is populating a JSON field - * @param array $json The existing JSON structure that will be populated - * - * @return array|mixed - */ - private function stockValue(Parameter $param, $userValue, array $json): array - { - $name = $param->getName(); - if ($path = $param->getPath()) { - $jsonPath = new JsonPath($json); - $jsonPath->set(sprintf("%s.%s", $path, $name), $userValue); - $json = $jsonPath->getStructure(); - } elseif ($name) { - $json[$name] = $userValue; - } else { - $json[] = $userValue; - } - - return $json; - } - - /** - * Populates a value into an array-like structure. - * - * @param Parameter $param The schema that defines how the JSON field is being populated - * @param mixed $userValue The user value that is populating a JSON field - * - * @return array|mixed - */ - private function stockArrayJson(Parameter $param, array $userValue): array - { - $elems = []; - foreach ($userValue as $item) { - $elems = $this->stockJson($param->getItemSchema(), $item, $elems); - } - return $elems; - } - - /** - * Populates a value into an object-like structure. - * - * @param Parameter $param The schema that defines how the JSON field is being populated - * @param mixed $userValue The user value that is populating a JSON field - * - * @return array - */ - private function stockObjectJson(Parameter $param, \stdClass $userValue): array - { - $object = []; - foreach ($userValue as $key => $val) { - $object = $this->stockJson($param->getProperty($key), $val, $object); - } - return $object; - } - - /** - * A generic method that will populate a JSON structure with a value according to a schema. It - * supports multiple types and will delegate accordingly. - * - * @param Parameter $param The schema that defines how the JSON field is being populated - * @param mixed $userValue The user value that is populating a JSON field - * @param array $json The existing JSON structure that will be populated - * - * @return array - */ - public function stockJson(Parameter $param, $userValue, array $json): array - { - if ($param->isArray()) { - $userValue = $this->stockArrayJson($param, $userValue); - } elseif ($param->isObject()) { - $userValue = $this->stockObjectJson($param, (object) $userValue); - } - // Populate the final value - return $this->stockValue($param, $userValue, $json); - } -} |
