summaryrefslogtreecommitdiff
path: root/server/vendor/php-opencloud/common/src/Common/Transport/RequestSerializer.php
diff options
context:
space:
mode:
authorEoleDev <root@serverpc.home>2016-03-09 15:37:42 +0100
committerEoleDev <root@serverpc.home>2016-03-09 15:37:42 +0100
commit1d3ed3af6d57316640c143002ddf80d61e6c098a (patch)
tree97ac49bc7ff0f16150aefee821da3557dc0d0644 /server/vendor/php-opencloud/common/src/Common/Transport/RequestSerializer.php
parentd69adc4f9d1f6019927de235ef84885c68e6e508 (diff)
parent08ea5ef31abcc4e23a39a780cacb64fa27f19194 (diff)
Merge branch 'Evan' into develop
Diffstat (limited to 'server/vendor/php-opencloud/common/src/Common/Transport/RequestSerializer.php')
-rw-r--r--server/vendor/php-opencloud/common/src/Common/Transport/RequestSerializer.php85
1 files changed, 85 insertions, 0 deletions
diff --git a/server/vendor/php-opencloud/common/src/Common/Transport/RequestSerializer.php b/server/vendor/php-opencloud/common/src/Common/Transport/RequestSerializer.php
new file mode 100644
index 0000000..30f04af
--- /dev/null
+++ b/server/vendor/php-opencloud/common/src/Common/Transport/RequestSerializer.php
@@ -0,0 +1,85 @@
+<?php
+
+namespace OpenCloud\Common\Transport;
+
+use function GuzzleHttp\uri_template;
+use function GuzzleHttp\Psr7\build_query;
+use function GuzzleHttp\Psr7\modify_request;
+use OpenCloud\Common\Api\Operation;
+use OpenCloud\Common\Api\Parameter;
+
+class RequestSerializer
+{
+ private $jsonSerializer;
+
+ public function __construct(JsonSerializer $jsonSerializer = null)
+ {
+ $this->jsonSerializer = $jsonSerializer ?: new JsonSerializer();
+ }
+
+ public function serializeOptions(Operation $operation, array $userValues = [])
+ {
+ $options = ['headers' => []];
+
+ foreach ($userValues as $paramName => $paramValue) {
+ if (null === ($schema = $operation->getParam($paramName))) {
+ continue;
+ }
+
+ $method = sprintf('stock%s', ucfirst($schema->getLocation()));
+ $this->$method($schema, $paramValue, $options);
+ }
+
+ if (!empty($options['json'])) {
+ if ($key = $operation->getJsonKey()) {
+ $options['json'] = [$key => $options['json']];
+ }
+ if (strpos(json_encode($options['json']), '\/') !== false) {
+ $options['body'] = json_encode($options['json'], JSON_UNESCAPED_SLASHES);
+ $options['headers']['Content-Type'] = 'application/json';
+ unset($options['json']);
+ }
+ }
+
+ return $options;
+ }
+
+ private function stockUrl()
+ {
+ }
+
+ private function stockQuery(Parameter $schema, $paramValue, array &$options)
+ {
+ $options['query'][$schema->getName()] = $paramValue;
+ }
+
+ private function stockHeader(Parameter $schema, $paramValue, array &$options)
+ {
+ $paramName = $schema->getName();
+
+ if (stripos($paramName, 'metadata') !== false) {
+ return $this->stockMetadataHeader($schema, $paramValue, $options);
+ }
+
+ $options['headers'] += is_scalar($paramValue) ? [$schema->getPrefixedName() => $paramValue] : [];
+ }
+
+ private function stockMetadataHeader(Parameter $schema, $paramValue, array &$options)
+ {
+ foreach ($paramValue as $key => $keyVal) {
+ $schema = $schema->getItemSchema() ?: new Parameter(['prefix' => $schema->getPrefix(), 'name' => $key]);
+ $this->stockHeader($schema, $keyVal, $options);
+ }
+ }
+
+ private function stockJson(Parameter $schema, $paramValue, array &$options)
+ {
+ $json = isset($options['json']) ? $options['json'] : [];
+ $options['json'] = $this->jsonSerializer->stockJson($schema, $paramValue, $json);
+ }
+
+ private function stockRaw(Parameter $schema, $paramValue, array &$options)
+ {
+ $options['body'] = $paramValue;
+ }
+}