summaryrefslogtreecommitdiff
path: root/server/vendor/php-opencloud/common/src/Common/Transport/JsonSerializer.php
diff options
context:
space:
mode:
authorEole <EoleDev@outlook.fr>2016-04-27 16:42:28 +0200
committerEole <EoleDev@outlook.fr>2016-04-27 16:42:28 +0200
commit49f416dc5061032e0514ea0cfeceaca37d13e432 (patch)
tree1202ac2a6fa860b8929afdc886c94fc50bd0a1de /server/vendor/php-opencloud/common/src/Common/Transport/JsonSerializer.php
parentc7edd70b5e5b0f5159c78ce3d924d4e7f60db816 (diff)
parentc9202d9113210981ae47df40511645da2ee140df (diff)
Merge branch 'develop' into Eole_Graph
Conflicts: client/index.html client/js/controllers/home/home.js client/partials/home/home.html
Diffstat (limited to 'server/vendor/php-opencloud/common/src/Common/Transport/JsonSerializer.php')
-rw-r--r--server/vendor/php-opencloud/common/src/Common/Transport/JsonSerializer.php95
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 100644
index 11b31d3..0000000
--- a/server/vendor/php-opencloud/common/src/Common/Transport/JsonSerializer.php
+++ /dev/null
@@ -1,95 +0,0 @@
-<?php
-
-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, $json)
- {
- $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, $userValue)
- {
- $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, $userValue)
- {
- $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, $json)
- {
- if ($param->isArray()) {
- $userValue = $this->stockArrayJson($param, $userValue);
- } elseif ($param->isObject()) {
- $userValue = $this->stockObjectJson($param, $userValue);
- }
- // Populate the final value
- return $this->stockValue($param, $userValue, $json);
- }
-}