diff options
Diffstat (limited to 'server/vendor/php-opencloud/common/src/Common/Transport')
5 files changed, 0 insertions, 383 deletions
diff --git a/server/vendor/php-opencloud/common/src/Common/Transport/HandlerStack.php b/server/vendor/php-opencloud/common/src/Common/Transport/HandlerStack.php deleted file mode 100755 index 8e7b8db..0000000 --- a/server/vendor/php-opencloud/common/src/Common/Transport/HandlerStack.php +++ /dev/null @@ -1,19 +0,0 @@ -<?php declare(strict_types=1); - -namespace OpenCloud\Common\Transport; - -use function GuzzleHttp\choose_handler; -use GuzzleHttp\HandlerStack as GuzzleStack; - -class HandlerStack extends GuzzleStack -{ - public static function create(callable $handler = null): self - { - $stack = new self($handler ?: choose_handler()); - - $stack->push(Middleware::httpErrors()); - $stack->push(Middleware::prepareBody()); - - return $stack; - } -} 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); - } -} diff --git a/server/vendor/php-opencloud/common/src/Common/Transport/Middleware.php b/server/vendor/php-opencloud/common/src/Common/Transport/Middleware.php deleted file mode 100755 index 2b407a4..0000000 --- a/server/vendor/php-opencloud/common/src/Common/Transport/Middleware.php +++ /dev/null @@ -1,96 +0,0 @@ -<?php declare(strict_types=1); - -namespace OpenCloud\Common\Transport; - -use function GuzzleHttp\Psr7\modify_request; -use GuzzleHttp\MessageFormatter; -use GuzzleHttp\Middleware as GuzzleMiddleware; -use OpenCloud\Common\Auth\AuthHandler; -use OpenCloud\Common\Auth\Token; -use OpenCloud\Common\Error\Builder; -use Psr\Http\Message\ResponseInterface; -use Psr\Log\LoggerInterface; -use Psr\Log\LogLevel; - -final class Middleware -{ - /** - * @return callable - */ - public static function httpErrors(): callable - { - return function (callable $handler) { - return function ($request, array $options) use ($handler) { - return $handler($request, $options)->then( - function (ResponseInterface $response) use ($request, $handler) { - if ($response->getStatusCode() < 400) { - return $response; - } - throw (new Builder())->httpError($request, $response); - } - ); - }; - }; - } - - /** - * @param callable $tokenGenerator - * @param Token $token - * - * @return callable - */ - public static function authHandler(callable $tokenGenerator, Token $token = null): callable - { - return function (callable $handler) use ($tokenGenerator, $token) { - return new AuthHandler($handler, $tokenGenerator, $token); - }; - } - - /** - * @codeCoverageIgnore - */ - public static function history(array &$container): callable - { - return GuzzleMiddleware::history($container); - } - - /** - * @codeCoverageIgnore - */ - public static function retry(callable $decider, callable $delay = null): callable - { - return GuzzleMiddleware::retry($decider, $delay); - } - - /** - * @codeCoverageIgnore - */ - public static function log(LoggerInterface $logger, MessageFormatter $formatter, $logLevel = LogLevel::INFO): callable - { - return GuzzleMiddleware::log($logger, $formatter, $logLevel); - } - - /** - * @codeCoverageIgnore - */ - public static function prepareBody(): callable - { - return GuzzleMiddleware::prepareBody(); - } - - /** - * @codeCoverageIgnore - */ - public static function mapRequest(callable $fn): callable - { - return GuzzleMiddleware::mapRequest($fn); - } - - /** - * @codeCoverageIgnore - */ - public static function mapResponse(callable $fn): callable - { - return GuzzleMiddleware::mapResponse($fn); - } -} diff --git a/server/vendor/php-opencloud/common/src/Common/Transport/RequestSerializer.php b/server/vendor/php-opencloud/common/src/Common/Transport/RequestSerializer.php deleted file mode 100755 index 61533fb..0000000 --- a/server/vendor/php-opencloud/common/src/Common/Transport/RequestSerializer.php +++ /dev/null @@ -1,85 +0,0 @@ -<?php declare(strict_types=1); - -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 = []): array - { - $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; - } -} diff --git a/server/vendor/php-opencloud/common/src/Common/Transport/Utils.php b/server/vendor/php-opencloud/common/src/Common/Transport/Utils.php deleted file mode 100755 index ffac9ce..0000000 --- a/server/vendor/php-opencloud/common/src/Common/Transport/Utils.php +++ /dev/null @@ -1,88 +0,0 @@ -<?php declare(strict_types=1); - -namespace OpenCloud\Common\Transport; - -use function GuzzleHttp\Psr7\uri_for; -use Psr\Http\Message\ResponseInterface; -use Psr\Http\Message\UriInterface; - -class Utils -{ - public static function jsonDecode(ResponseInterface $response, bool $assoc = true) - { - $jsonErrors = [ - JSON_ERROR_DEPTH => 'JSON_ERROR_DEPTH - Maximum stack depth exceeded', - JSON_ERROR_STATE_MISMATCH => 'JSON_ERROR_STATE_MISMATCH - Underflow or the modes mismatch', - JSON_ERROR_CTRL_CHAR => 'JSON_ERROR_CTRL_CHAR - Unexpected control character found', - JSON_ERROR_SYNTAX => 'JSON_ERROR_SYNTAX - Syntax error, malformed JSON', - JSON_ERROR_UTF8 => 'JSON_ERROR_UTF8 - Malformed UTF-8 characters, possibly incorrectly encoded' - ]; - - $responseBody = (string) $response->getBody(); - - if (strlen($responseBody) === 0) { - return $responseBody; - } - - $data = json_decode($responseBody, $assoc); - - if (JSON_ERROR_NONE !== json_last_error()) { - $last = json_last_error(); - throw new \InvalidArgumentException( - 'Unable to parse JSON data: ' . (isset($jsonErrors[$last]) ? $jsonErrors[$last] : 'Unknown error') - ); - } - - return $data; - } - - /** - * Method for flattening a nested array. - * - * @param array $data The nested array - * @param string $key The key to extract - * - * @return array - */ - public static function flattenJson($data, string $key = null) - { - return (!empty($data) && $key && isset($data[$key])) ? $data[$key] : $data; - } - - /** - * Method for normalize an URL string. - * - * Append the http:// prefix if not present, and add a - * closing url separator when missing. - * - * @param string $url The url representation. - * - * @return string - */ - public static function normalizeUrl(string $url): string - { - if (strpos($url, 'http') === false) { - $url = 'http://' . $url; - } - - return rtrim($url, '/') . '/'; - } - - /** - * Add an unlimited list of paths to a given URI. - * - * @param UriInterface $uri - * @param ...$paths - * - * @return UriInterface - */ - public static function addPaths(UriInterface $uri, ...$paths): UriInterface - { - return uri_for(rtrim((string) $uri, '/') . '/' . implode('/', $paths)); - } - - public static function appendPath(UriInterface $uri, $path): UriInterface - { - return uri_for(rtrim((string) $uri, '/') . '/' . $path); - } -} |
