diff options
| author | EoleDev <EoleDev@outlook.fr> | 2016-03-23 15:30:47 +0100 |
|---|---|---|
| committer | EoleDev <EoleDev@outlook.fr> | 2016-03-23 15:30:47 +0100 |
| commit | 54ec6723deb44e325782afd366eeec01ee29ac55 (patch) | |
| tree | 5431400d307754a02e6c40b35a40e6761d7dac0c /server/vendor/php-opencloud/common/src/Common/Service/Builder.php | |
| parent | 0dc17aa9efb987dcdf6f864f4110450bcc0c9003 (diff) | |
Maj Library
Diffstat (limited to 'server/vendor/php-opencloud/common/src/Common/Service/Builder.php')
| -rw-r--r-- | server/vendor/php-opencloud/common/src/Common/Service/Builder.php | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/server/vendor/php-opencloud/common/src/Common/Service/Builder.php b/server/vendor/php-opencloud/common/src/Common/Service/Builder.php index 0035070..9ccd90d 100644 --- a/server/vendor/php-opencloud/common/src/Common/Service/Builder.php +++ b/server/vendor/php-opencloud/common/src/Common/Service/Builder.php @@ -1,15 +1,15 @@ -<?php +<?php declare(strict_types = 1); namespace OpenCloud\Common\Service; use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; use GuzzleHttp\Middleware as GuzzleMiddleware; +use OpenCloud\Common\Auth\IdentityService; use OpenCloud\Common\Auth\Token; use OpenCloud\Common\Transport\HandlerStack; use OpenCloud\Common\Transport\Middleware; use OpenCloud\Common\Transport\Utils; -use OpenCloud\Identity\v3\Service; /** * A Builder for easily creating OpenCloud services. @@ -54,7 +54,7 @@ class Builder * * @return array */ - private function getClasses($serviceName, $serviceVersion) + private function getClasses(string $serviceName, int $serviceVersion) { $rootNamespace = sprintf("%s\\%s\\v%d", $this->rootNamespace, $serviceName, $serviceVersion); @@ -70,19 +70,18 @@ class Builder * directly - this setup includes the configuration of the HTTP client's base URL, and the * attachment of an authentication handler. * - * @param $serviceName The name of the service as it appears in the OpenCloud\* namespace - * @param $serviceVersion The major version of the service - * @param array $serviceOptions The service-specific options to use + * @param string $serviceName The name of the service as it appears in the OpenCloud\* namespace + * @param int $serviceVersion The major version of the service + * @param array $serviceOptions The service-specific options to use * * @return \OpenCloud\Common\Service\ServiceInterface * * @throws \Exception */ - public function createService($serviceName, $serviceVersion, array $serviceOptions = []) + public function createService(string $serviceName, int $serviceVersion, array $serviceOptions = []): ServiceInterface { $options = $this->mergeOptions($serviceOptions); - $this->stockIdentityService($options); $this->stockAuthHandler($options); $this->stockHttpClient($options, $serviceName); @@ -91,7 +90,7 @@ class Builder return new $serviceClass($options['httpClient'], new $apiClass()); } - private function stockHttpClient(array &$options, $serviceName) + private function stockHttpClient(array &$options, string $serviceName) { if (!isset($options['httpClient']) || !($options['httpClient'] instanceof ClientInterface)) { if (strcasecmp($serviceName, 'identity') === 0) { @@ -121,16 +120,9 @@ class Builder } } - private function stockIdentityService(array &$options) - { - if (!isset($options['identityService'])) { - $httpClient = $this->httpClient($options['authUrl'], HandlerStack::create()); - $options['identityService'] = Service::factory($httpClient); - } - } - /** * @param array $options + * * @codeCoverageIgnore */ private function stockAuthHandler(array &$options) @@ -142,14 +134,14 @@ class Builder } } - private function getStack(callable $authHandler, Token $token = null) + private function getStack(callable $authHandler, Token $token = null): HandlerStack { $stack = HandlerStack::create(); $stack->push(Middleware::authHandler($authHandler, $token)); return $stack; } - private function httpClient($baseUrl, HandlerStack $stack) + private function httpClient(string $baseUrl, HandlerStack $stack): ClientInterface { return new Client([ 'base_uri' => Utils::normalizeUrl($baseUrl), @@ -157,7 +149,7 @@ class Builder ]); } - private function mergeOptions(array $serviceOptions) + private function mergeOptions(array $serviceOptions): array { $options = array_merge($this->defaults, $this->globalOptions, $serviceOptions); @@ -165,6 +157,12 @@ class Builder throw new \InvalidArgumentException('"authUrl" is a required option'); } + if (!isset($options['identityService']) || !($options['identityService'] instanceof IdentityService)) { + throw new \InvalidArgumentException(sprintf( + '"identityService" must be specified and implement %s', IdentityService::class + )); + } + return $options; } -} +}
\ No newline at end of file |
