From 24bb5fefbdf93ce0969b7f56cc46c459ebb82a95 Mon Sep 17 00:00:00 2001 From: EoleDev Date: Thu, 14 Apr 2016 16:24:44 +0200 Subject: Mise a jour et nettoyage depot --- .../common/src/Common/Api/AbstractApi.php | 33 -- .../common/src/Common/Api/AbstractParams.php | 100 ------ .../common/src/Common/Api/ApiInterface.php | 20 -- .../common/src/Common/Api/Operation.php | 134 ------- .../common/src/Common/Api/Operator.php | 175 --------- .../common/src/Common/Api/OperatorInterface.php | 54 --- .../common/src/Common/Api/Parameter.php | 389 --------------------- 7 files changed, 905 deletions(-) delete mode 100644 server/vendor/php-opencloud/common/src/Common/Api/AbstractApi.php delete mode 100644 server/vendor/php-opencloud/common/src/Common/Api/AbstractParams.php delete mode 100644 server/vendor/php-opencloud/common/src/Common/Api/ApiInterface.php delete mode 100644 server/vendor/php-opencloud/common/src/Common/Api/Operation.php delete mode 100644 server/vendor/php-opencloud/common/src/Common/Api/Operator.php delete mode 100644 server/vendor/php-opencloud/common/src/Common/Api/OperatorInterface.php delete mode 100644 server/vendor/php-opencloud/common/src/Common/Api/Parameter.php (limited to 'server/vendor/php-opencloud/common/src/Common/Api') diff --git a/server/vendor/php-opencloud/common/src/Common/Api/AbstractApi.php b/server/vendor/php-opencloud/common/src/Common/Api/AbstractApi.php deleted file mode 100644 index 09988fd..0000000 --- a/server/vendor/php-opencloud/common/src/Common/Api/AbstractApi.php +++ /dev/null @@ -1,33 +0,0 @@ - true]); - } - - protected function notRequired(array $param): array - { - return array_merge($param, ['required' => false]); - } - - protected function query(array $param): array - { - return array_merge($param, ['location' => AbstractParams::QUERY]); - } - - protected function url(array $param): array - { - return array_merge($param, ['location' => AbstractParams::URL]); - } - - public function documented(array $param): array - { - return array_merge($param, ['required' => true]); - } -} diff --git a/server/vendor/php-opencloud/common/src/Common/Api/AbstractParams.php b/server/vendor/php-opencloud/common/src/Common/Api/AbstractParams.php deleted file mode 100644 index b21b3dd..0000000 --- a/server/vendor/php-opencloud/common/src/Common/Api/AbstractParams.php +++ /dev/null @@ -1,100 +0,0 @@ - self::INT_TYPE, - 'location' => 'query', - 'description' => << 'string', - 'location' => 'query', - 'description' => << sprintf("The unique ID, or identifier, for the %s", $type), - 'type' => self::STRING_TYPE, - 'location' => self::JSON, - ]; - } - - public function idPath(): array - { - return [ - 'type' => self::STRING_TYPE, - 'location' => self::URL, - 'description' => 'The unique ID of the resource', - ]; - } - - public function name(string $resource): array - { - return [ - 'description' => sprintf("The name of the %s", $resource), - 'type' => self::STRING_TYPE, - 'location' => self::JSON, - ]; - } - - - public function sortDir(): array - { - return [ - 'type' => self::STRING_TYPE, - 'location' => self::QUERY, - 'description' => "Sorts by one or more sets of attribute and sort direction combinations.", - 'enum' => ['asc', 'desc'] - ]; - } - - public function sortKey(): array - { - return [ - 'type' => self::STRING_TYPE, - 'location' => self::QUERY, - 'description' => "Sorts by one or more sets of attribute and sort direction combinations.", - ]; - } -} \ No newline at end of file diff --git a/server/vendor/php-opencloud/common/src/Common/Api/ApiInterface.php b/server/vendor/php-opencloud/common/src/Common/Api/ApiInterface.php deleted file mode 100644 index d4629dc..0000000 --- a/server/vendor/php-opencloud/common/src/Common/Api/ApiInterface.php +++ /dev/null @@ -1,20 +0,0 @@ -method = $definition['method']; - $this->path = $definition['path']; - - if (isset($definition['jsonKey'])) { - $this->jsonKey = $definition['jsonKey']; - } - - $this->params = self::toParamArray($definition['params']); - } - - /** - * @return string - */ - public function getPath(): string - { - return $this->path; - } - - /** - * @return string - */ - public function getMethod(): string - { - return $this->method; - } - - /** - * Indicates whether this operation supports a parameter. - * - * @param $key The name of a parameter - * - * @return bool - */ - public function hasParam(string $key): bool - { - return isset($this->params[$key]); - } - - /** - * @param $name - * - * @return Parameter - */ - public function getParam(string $name) - { - return isset($this->params[$name]) ? $this->params[$name] : null; - } - - /** - * @return string - */ - public function getJsonKey(): string - { - return $this->jsonKey ?: ''; - } - - /** - * A convenience method that will take a generic array of data and convert it into an array of - * {@see Parameter} objects. - * - * @param array $data A generic data array - * - * @return array - */ - public static function toParamArray(array $data): array - { - $params = []; - - foreach ($data as $name => $param) { - $params[$name] = new Parameter($param + ['name' => $name]); - } - - return $params; - } - - /** - * This method will validate all of the user-provided values and throw an exception if any - * failures are detected. This is useful for basic sanity-checking before a request is - * serialized and sent to the API. - * - * @param array $userValues The user-defined values - * - * @return bool TRUE if validation passes - * @throws \Exception If validate fails - */ - public function validate(array $userValues): bool - { - foreach ($this->params as $paramName => $param) { - if (array_key_exists($paramName, $userValues)) { - $param->validate($userValues[$paramName]); - } elseif ($param->isRequired()) { - throw new \Exception(sprintf('"%s" is a required option, but it was not provided', $paramName)); - } - } - - return true; - } -} \ No newline at end of file diff --git a/server/vendor/php-opencloud/common/src/Common/Api/Operator.php b/server/vendor/php-opencloud/common/src/Common/Api/Operator.php deleted file mode 100644 index 5698779..0000000 --- a/server/vendor/php-opencloud/common/src/Common/Api/Operator.php +++ /dev/null @@ -1,175 +0,0 @@ -client = $client; - $this->api = $api; - } - - /** - * Magic method for dictating how objects are rendered when var_dump is called. - * For the benefit of users, extremely verbose and heavy properties (such as HTTP clients) are - * removed to provide easier access to normal state, such as resource attributes. - * - * @codeCoverageIgnore - * @return array - */ - public function __debugInfo() - { - $excludedVars = ['client', 'errorBuilder', 'api']; - - $output = []; - - foreach (get_object_vars($this) as $key => $val) { - if (!in_array($key, $excludedVars)) { - $output[$key] = $val; - } - } - - return $output; - } - - /** - * Retrieves a populated Operation according to the definition and values provided. A - * HTTP client is also injected into the object to allow it to communicate with the remote API. - * - * @param array $definition The data that dictates how the operation works - * - * @return Operation - */ - public function getOperation(array $definition): Operation - { - return new Operation($definition); - } - - protected function sendRequest(Operation $operation, array $userValues = [], bool $async = false) - { - $operation->validate($userValues); - - $options = (new RequestSerializer)->serializeOptions($operation, $userValues); - $method = $async ? 'requestAsync' : 'request'; - $uri = uri_template($operation->getPath(), $userValues); - - return $this->client->$method($operation->getMethod(), $uri, $options); - } - - /** - * {@inheritDoc} - */ - public function execute(array $definition, array $userValues = []): ResponseInterface - { - return $this->sendRequest($this->getOperation($definition), $userValues); - } - - /** - * {@inheritDoc} - */ - public function executeAsync(array $definition, array $userValues = []): PromiseInterface - { - return $this->sendRequest($this->getOperation($definition), $userValues, true); - } - - /** - * {@inheritDoc} - */ - public function model(string $class, $data = null): ResourceInterface - { - $model = new $class($this->client, $this->api); - - // @codeCoverageIgnoreStart - if (!$model instanceof ResourceInterface) { - throw new \RuntimeException(sprintf('%s does not implement %s', $class, ResourceInterface::class)); - } - // @codeCoverageIgnoreEnd - - if ($data instanceof ResponseInterface) { - $model->populateFromResponse($data); - } elseif (is_array($data)) { - $model->populateFromArray($data); - } - - return $model; - } - - /** - * Will create a new instance of this class with the current HTTP client and API injected in. This - * is useful when enumerating over a collection since multiple copies of the same resource class - * are needed. - * - * @return static - */ - public function newInstance(): self - { - return new static($this->client, $this->api); - } - - /** - * @return \GuzzleHttp\Psr7\Uri:null - */ - protected function getHttpBaseUrl() - { - return $this->client->getConfig('base_uri'); - } - - /** - * Magic method which intercepts async calls, finds the sequential version, and wraps it in a - * {@see Promise} object. In order for this to happen, the called methods need to be in the - * following format: `createAsync`, where `create` is the sequential method being wrapped. - * - * @param $methodName The name of the method being invoked. - * @param $args The arguments to be passed to the sequential method. - * - * @throws \RuntimeException If method does not exist - * - * @return Promise - */ - public function __call($methodName, $args) - { - $e = function ($name) { - return new \RuntimeException(sprintf('%s::%s is not defined', get_class($this), $name)); - }; - - if (substr($methodName, -5) === 'Async') { - $realMethod = substr($methodName, 0, -5); - if (!method_exists($this, $realMethod)) { - throw $e($realMethod); - } - - $promise = new Promise( - function () use (&$promise, $realMethod, $args) { - $value = call_user_func_array([$this, $realMethod], $args); - $promise->resolve($value); - } - ); - - return $promise; - } - - throw $e($methodName); - } -} diff --git a/server/vendor/php-opencloud/common/src/Common/Api/OperatorInterface.php b/server/vendor/php-opencloud/common/src/Common/Api/OperatorInterface.php deleted file mode 100644 index 168518b..0000000 --- a/server/vendor/php-opencloud/common/src/Common/Api/OperatorInterface.php +++ /dev/null @@ -1,54 +0,0 @@ -hydrate($data); - - $this->required = (bool)$this->required; - - $this->stockLocation($data); - $this->stockItemSchema($data); - $this->stockProperties($data); - } - - private function stockLocation(array $data) - { - $this->location = isset($data['location']) ? $data['location'] : self::DEFAULT_LOCATION; - - if (!AbstractParams::isSupportedLocation($this->location)) { - throw new \RuntimeException(sprintf("%s is not a permitted location", $this->location)); - } - } - - private function stockItemSchema(array $data) - { - if (isset($data['items'])) { - $this->itemSchema = new Parameter($data['items']); - } - } - - private function stockProperties(array $data) - { - if (isset($data['properties'])) { - if ($this->name && stripos($this->name, 'metadata') !== false) { - $this->properties = new Parameter($data['properties']); - } else { - foreach ($data['properties'] as $name => $property) { - $this->properties[$name] = new Parameter($property + ['name' => $name]); - } - } - } - } - - /** - * Retrieve the name that will be used over the wire. - * - * @return string - */ - public function getName(): string - { - return $this->sentAs ?: $this->name; - } - - /** - * Indicates whether the user must provide a value for this parameter. - * - * @return bool - */ - public function isRequired(): bool - { - return $this->required === true; - } - - /** - * Validates a given user value and checks whether it passes basic sanity checking, such as types. - * - * @param $userValues The value provided by the user - * - * @return bool TRUE if the validation passes - * @throws \Exception If validation fails - */ - public function validate($userValues): bool - { - $this->validateEnums($userValues); - $this->validateType($userValues); - - if ($this->isArray()) { - $this->validateArray($userValues); - } elseif ($this->isObject()) { - $this->validateObject($userValues); - } - - return true; - } - - private function validateEnums($userValues) - { - if (!empty($this->enum) && $this->type == 'string' && !in_array($userValues, $this->enum)) { - throw new \Exception(sprintf( - 'The only permitted values are %s. You provided %s', implode(', ', $this->enum), print_r($userValues, true) - )); - } - } - - private function validateType($userValues) - { - if (!$this->hasCorrectType($userValues)) { - throw new \Exception(sprintf( - 'The key provided "%s" has the wrong value type. You provided %s (%s) but was expecting %s', - $this->name, print_r($userValues, true), gettype($userValues), $this->type - )); - } - } - - private function validateArray($userValues) - { - foreach ($userValues as $userValue) { - $this->itemSchema->validate($userValue); - } - } - - private function validateObject($userValues) - { - foreach ($userValues as $key => $userValue) { - $property = $this->getNestedProperty($key); - $property->validate($userValue); - } - } - - /** - * Internal method which retrieves a nested property for object parameters. - * - * @param $key The name of the child parameter - * - * @returns Parameter - * @throws \Exception - */ - private function getNestedProperty($key): Parameter - { - if ($this->name && stripos($this->name, 'metadata') !== false && $this->properties instanceof Parameter) { - return $this->properties; - } elseif (isset($this->properties[$key])) { - return $this->properties[$key]; - } else { - throw new \Exception(sprintf('The key provided "%s" is not defined', $key)); - } - } - - /** - * Internal method which indicates whether the user value is of the same type as the one expected - * by this parameter. - * - * @param $userValue The value being checked - * - * @return bool - */ - private function hasCorrectType($userValue): bool - { - // Helper fn to see whether an array is associative (i.e. a JSON object) - $isAssociative = function ($value) { - return is_array($value) && array_keys($value) !== range(0, count($value) - 1); - }; - - // For params defined as objects, we'll let the user get away with - // passing in an associative array - since it's effectively a hash - if ($this->type == 'object' && $isAssociative($userValue)) { - return true; - } - - if (class_exists($this->type) || interface_exists($this->type)) { - return is_a($userValue, $this->type); - } - - if (!$this->type) { - return true; - } - - return gettype($userValue) == $this->type; - } - - /** - * Indicates whether this parameter represents an array type - * - * @return bool - */ - public function isArray(): bool - { - return $this->type == 'array' && $this->itemSchema instanceof Parameter; - } - - /** - * Indicates whether this parameter represents an object type - * - * @return bool - */ - public function isObject(): bool - { - return $this->type == 'object' && !empty($this->properties); - } - - public function getLocation(): string - { - return $this->location; - } - - /** - * Verifies whether the given location matches the parameter's location. - * - * @param $value - * - * @return bool - */ - public function hasLocation($value): bool - { - return $this->location == $value; - } - - /** - * Retrieves the parameter's path. - * - * @return string|null - */ - public function getPath(): string - { - return $this->path; - } - - /** - * Retrieves the common schema that an array parameter applies to all its child elements. - * - * @return Parameter|null - */ - public function getItemSchema() - { - return $this->itemSchema; - } - - /** - * Sets the name of the parameter to a new value - * - * @param string $name - */ - public function setName(string $name) - { - $this->name = $name; - } - - /** - * Retrieves the child parameter for an object parameter. - * - * @param string $name The name of the child property - * - * @return null|Parameter - */ - public function getProperty(string $name) - { - if ($this->properties instanceof Parameter) { - $this->properties->setName($name); - return $this->properties; - } - - return isset($this->properties[$name]) ? $this->properties[$name] : null; - } - - /** - * Retrieves the prefix for a parameter, if any. - * - * @return string|null - */ - public function getPrefix(): string - { - return $this->prefix; - } - - public function getPrefixedName(): string - { - return $this->prefix . $this->getName(); - } -} -- cgit v1.2.3