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 --- .../src/Common/Resource/AbstractResource.php | 245 --------------------- .../common/src/Common/Resource/Creatable.php | 19 -- .../common/src/Common/Resource/Deletable.php | 18 -- .../common/src/Common/Resource/HasMetadata.php | 67 ------ .../common/src/Common/Resource/HasWaiterTrait.php | 124 ----------- .../common/src/Common/Resource/Iterator.php | 97 -------- .../common/src/Common/Resource/Listable.php | 28 --- .../src/Common/Resource/ResourceInterface.php | 29 --- .../common/src/Common/Resource/Retrievable.php | 18 -- .../common/src/Common/Resource/Updateable.php | 18 -- 10 files changed, 663 deletions(-) delete mode 100644 server/vendor/php-opencloud/common/src/Common/Resource/AbstractResource.php delete mode 100644 server/vendor/php-opencloud/common/src/Common/Resource/Creatable.php delete mode 100644 server/vendor/php-opencloud/common/src/Common/Resource/Deletable.php delete mode 100644 server/vendor/php-opencloud/common/src/Common/Resource/HasMetadata.php delete mode 100644 server/vendor/php-opencloud/common/src/Common/Resource/HasWaiterTrait.php delete mode 100644 server/vendor/php-opencloud/common/src/Common/Resource/Iterator.php delete mode 100644 server/vendor/php-opencloud/common/src/Common/Resource/Listable.php delete mode 100644 server/vendor/php-opencloud/common/src/Common/Resource/ResourceInterface.php delete mode 100644 server/vendor/php-opencloud/common/src/Common/Resource/Retrievable.php delete mode 100644 server/vendor/php-opencloud/common/src/Common/Resource/Updateable.php (limited to 'server/vendor/php-opencloud/common/src/Common/Resource') diff --git a/server/vendor/php-opencloud/common/src/Common/Resource/AbstractResource.php b/server/vendor/php-opencloud/common/src/Common/Resource/AbstractResource.php deleted file mode 100644 index 989fde7..0000000 --- a/server/vendor/php-opencloud/common/src/Common/Resource/AbstractResource.php +++ /dev/null @@ -1,245 +0,0 @@ - 'fooBar' - * - * will extract FOO_BAR from the response, and save it as 'fooBar' in the resource. - * - * @var array - */ - protected $aliases = []; - - /** - * Populates the current resource from a response object. - * - * @param ResponseInterface $response - * - * @return $this|ResourceInterface - */ - public function populateFromResponse(ResponseInterface $response): self - { - if (strpos($response->getHeaderLine('Content-Type'), 'application/json') === 0) { - $json = Utils::jsonDecode($response); - if (!empty($json)) { - $this->populateFromArray(Utils::flattenJson($json, $this->resourceKey)); - } - } - - return $this; - } - - /** - * Populates the current resource from a data array. - * - * @param array $array - * - * @return mixed|void - */ - public function populateFromArray(array $array): self - { - $reflClass = new \ReflectionClass($this); - - foreach ($array as $key => $val) { - $propertyName = (string) (isset($this->aliases[$key]) ? $this->aliases[$key] : $key); - - if (property_exists($this, $propertyName)) { - if ($type = $this->extractTypeFromDocBlock($reflClass, $propertyName)) { - $val = $this->parseDocBlockValue($type, $val); - } - - $this->$propertyName = $val; - } - } - - return $this; - } - - private function parseDocBlockValue(string $type, $val) - { - if (strpos($type, '[]') === 0 && is_array($val)) { - $array = []; - foreach ($val as $subVal) { - $array[] = $this->model($this->normalizeModelClass(substr($type, 2)), $subVal); - } - $val = $array; - } elseif (strcasecmp($type, '\datetimeimmutable') === 0) { - $val = new \DateTimeImmutable($val); - } elseif ($this->isNotNativeType($type)) { - $val = $this->model($this->normalizeModelClass($type), $val); - } - - return $val; - } - - private function isNotNativeType(string $type): bool - { - return !in_array($type, [ - 'string', 'bool', 'boolean', 'double', 'null', 'array', 'object', 'int', 'integer', 'float', 'numeric', - 'mixed' - ]); - } - - private function normalizeModelClass(string $class): string - { - if (strpos($class, '\\') === false) { - $currentNamespace = (new \ReflectionClass($this))->getNamespaceName(); - $class = sprintf("%s\\%s", $currentNamespace, $class); - } - - return $class; - } - - private function extractTypeFromDocBlock(\ReflectionClass $reflClass, string $propertyName) - { - $docComment = $reflClass->getProperty($propertyName)->getDocComment(); - - if (!$docComment) { - return false; - } - - $matches = []; - preg_match('#@var ((\[\])?[\w|\\\]+)#', $docComment, $matches); - return isset($matches[1]) ? $matches[1] : null; - } - - /** - * Internal method which retrieves the values of provided keys. - * - * @param array $keys - * - * @return array - */ - protected function getAttrs(array $keys) - { - $output = []; - - foreach ($keys as $key) { - if (property_exists($this, $key) && $this->$key !== null) { - $output[$key] = $this->$key; - } - } - - return $output; - } - - /** - * @param array $definition - * - * @return mixed - */ - public function executeWithState(array $definition) - { - return $this->execute($definition, $this->getAttrs(array_keys($definition['params']))); - } - - private function getResourcesKey(): string - { - $resourcesKey = $this->resourcesKey; - - if (!$resourcesKey) { - $class = substr(static::class, strrpos(static::class, '\\') + 1); - $resourcesKey = strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $class)) . 's'; - } - - return $resourcesKey; - } - - /** - * {@inheritDoc} - */ - public function enumerate(array $def, array $userVals = [], callable $mapFn = null): \Generator - { - $operation = $this->getOperation($def); - - $requestFn = function ($marker) use ($operation, $userVals) { - if ($marker) { - $userVals['marker'] = $marker; - } - return $this->sendRequest($operation, $userVals); - }; - - $resourceFn = function (array $data) { - $resource = $this->newInstance(); - $resource->populateFromArray($data); - return $resource; - }; - - $opts = [ - 'limit' => isset($userVals['limit']) ? $userVals['limit'] : null, - 'resourcesKey' => $this->getResourcesKey(), - 'markerKey' => $this->markerKey, - 'mapFn' => $mapFn, - ]; - - $iterator = new Iterator($opts, $requestFn, $resourceFn); - return $iterator(); - } - - public function extractMultipleInstances(ResponseInterface $response, string $key = null): array - { - $key = $key ?: $this->getResourcesKey(); - $resourcesData = Utils::jsonDecode($response)[$key]; - - $resources = []; - - foreach ($resourcesData as $resourceData) { - $resource = $this->newInstance(); - $resource->populateFromArray($resourceData); - $resources[] = $resource; - } - - return $resources; - } - - protected function getService() - { - $class = static::class; - $service = substr($class, 0, strpos($class, 'Models') - 1) . '\\Service'; - - return new $service($this->client, $this->api); - } -} diff --git a/server/vendor/php-opencloud/common/src/Common/Resource/Creatable.php b/server/vendor/php-opencloud/common/src/Common/Resource/Creatable.php deleted file mode 100644 index 5f16bfa..0000000 --- a/server/vendor/php-opencloud/common/src/Common/Resource/Creatable.php +++ /dev/null @@ -1,19 +0,0 @@ - 'val3', 'Baz' => 'val4']); is called, then the resource will have the following - * metadata: - * - * Foo: val3 - * Bar: val2 - * Baz: val4 - * - * You will notice that any metadata items which are not specified in the call are preserved. - * - * @param array $metadata The new metadata items - * - * @return void - */ - public function mergeMetadata(array $metadata); - - /** - * Replaces all of the existing metadata items for a resource with a new set of values. Any metadata items which - * are not provided in the call are removed from the resource. For example, if the resource has this metadata - * already set: - * - * Foo: val1 - * Bar: val2 - * - * and resetMetadata(['Foo' => 'val3', 'Baz' => 'val4']); is called, then the resource will have the following - * metadata: - * - * Foo: val3 - * Baz: val4 - * - * @param array $metadata The new metadata items - * - * @return void - */ - public function resetMetadata(array $metadata); - - /** - * Extracts metadata from a response object and returns it in the form of an associative array. - * - * @param ResponseInterface $response - * - * @return array - */ - public function parseMetadata(ResponseInterface $response): array; -} diff --git a/server/vendor/php-opencloud/common/src/Common/Resource/HasWaiterTrait.php b/server/vendor/php-opencloud/common/src/Common/Resource/HasWaiterTrait.php deleted file mode 100644 index ddc4bef..0000000 --- a/server/vendor/php-opencloud/common/src/Common/Resource/HasWaiterTrait.php +++ /dev/null @@ -1,124 +0,0 @@ -retrieve(); - - if ($this->status == $status || $this->shouldHalt($timeout, $startTime)) { - break; - } - - sleep($sleepPeriod); - } - } - - /** - * Provides a blocking operation until the resource has reached a particular state. The method - * will enter a loop, executing the callback until TRUE is returned. This provides great - * flexibility. - * - * @param callable $fn An anonymous function that will be executed on every iteration. You can - * encapsulate your own logic to determine whether the resource has - * successfully transitioned. When TRUE is returned by the callback, - * the loop will end. - * @param int|bool $timeout The maximum timeout in seconds. If the total time taken by the waiter has reached - * or exceed this timeout, the blocking operation will immediately cease. If FALSE - * is provided, the timeout will never be considered. - * @param int $sleepPeriod The amount of time to pause between each HTTP request. - */ - public function waitWithCallback(callable $fn, $timeout = 60, int $sleepPeriod = 1) - { - $startTime = time(); - - while (true) { - $this->retrieve(); - - $response = call_user_func_array($fn, [$this]); - - if ($response === true || $this->shouldHalt($timeout, $startTime)) { - break; - } - - sleep($sleepPeriod); - } - } - - /** - * Internal method used to identify whether a timeout has been exceeded. - * - * @param bool|int $timeout - * @param int $startTime - * - * @return bool - */ - private function shouldHalt($timeout, int $startTime) - { - if ($timeout === false) { - return false; - } - - return time() - $startTime >= $timeout; - } - - /** - * Convenience method providing a blocking operation until the resource transitions to an - * ``ACTIVE`` status. - * - * @param int|bool $timeout The maximum timeout in seconds. If the total time taken by the waiter has reached - * or exceed this timeout, the blocking operation will immediately cease. If FALSE - * is provided, the timeout will never be considered. - */ - public function waitUntilActive($timeout = false) - { - $this->waitUntil('ACTIVE', $timeout); - } - - public function waitUntilDeleted($timeout = 60, int $sleepPeriod = 1) - { - $startTime = time(); - - while (true) { - try { - $this->retrieve(); - } catch (BadResponseError $e) { - if ($e->getResponse()->getStatusCode() === 404) { - break; - } - throw $e; - } - - if ($this->shouldHalt($timeout, $startTime)) { - break; - } - - sleep($sleepPeriod); - } - } -} diff --git a/server/vendor/php-opencloud/common/src/Common/Resource/Iterator.php b/server/vendor/php-opencloud/common/src/Common/Resource/Iterator.php deleted file mode 100644 index 05507f0..0000000 --- a/server/vendor/php-opencloud/common/src/Common/Resource/Iterator.php +++ /dev/null @@ -1,97 +0,0 @@ -limit = isset($options['limit']) ? $options['limit'] : false; - $this->count = 0; - - if (isset($options['resourcesKey'])) { - $this->resourcesKey = $options['resourcesKey']; - } - - if (isset($options['markerKey'])) { - $this->markerKey = $options['markerKey']; - } - - if (isset($options['mapFn']) && is_callable($options['mapFn'])) { - $this->mapFn = $options['mapFn']; - } - - $this->requestFn = $requestFn; - $this->resourceFn = $resourceFn; - } - - private function fetchResources() - { - if ($this->shouldNotSendAnotherRequest()) { - return false; - } - - $response = call_user_func($this->requestFn, $this->currentMarker); - - $json = Utils::flattenJson(Utils::jsonDecode($response), $this->resourcesKey); - - if ($response->getStatusCode() === 204 || empty($json)) { - return false; - } - - return $json; - } - - private function assembleResource(array $data) - { - $resource = call_user_func($this->resourceFn, $data); - - // Invoke user-provided fn if provided - if ($this->mapFn) { - call_user_func_array($this->mapFn, [&$resource]); - } - - // Update marker if operation supports it - if ($this->markerKey) { - $this->currentMarker = $resource->{$this->markerKey}; - } - - return $resource; - } - - private function totalReached() - { - return $this->limit && $this->count >= $this->limit; - } - - private function shouldNotSendAnotherRequest() - { - return $this->totalReached() || ($this->count > 0 && !$this->markerKey); - } - - public function __invoke() - { - while ($resources = $this->fetchResources()) { - foreach ($resources as $resourceData) { - if ($this->totalReached()) { - break; - } - - $this->count++; - - yield $this->assembleResource($resourceData); - } - } - } -} diff --git a/server/vendor/php-opencloud/common/src/Common/Resource/Listable.php b/server/vendor/php-opencloud/common/src/Common/Resource/Listable.php deleted file mode 100644 index c3041d5..0000000 --- a/server/vendor/php-opencloud/common/src/Common/Resource/Listable.php +++ /dev/null @@ -1,28 +0,0 @@ -