| @@ -22,8 +22,10 @@ | ||
| 22 | 22 | /** @var array */ |
| 23 | 23 | private $waiters = null; |
| 24 | 24 | /** @var boolean */ |
| 25 | 25 | private $modifiedModel = \false; |
| 26 | + /** @var string */ | |
| 27 | + private $protocol; | |
| 26 | 28 | /** |
| 27 | 29 | * @param array $definition |
| 28 | 30 | * @param callable $provider |
| 29 | 31 | * |
| @@ -45,8 +47,9 @@ | ||
| 45 | 47 | $this->apiVersion = $this->getApiVersion(); |
| 46 | 48 | if (isset($definition['clientContextParams'])) { |
| 47 | 49 | $this->clientContextParams = $definition['clientContextParams']; |
| 48 | 50 | } |
| 51 | + $this->protocol = $this->selectProtocol($definition); | |
| 49 | 52 | } |
| 50 | 53 | /** |
| 51 | 54 | * Creates a request serializer for the provided API object. |
| 52 | 55 | * |
| @@ -77,9 +80,9 @@ | ||
| 77 | 80 | * |
| 78 | 81 | * @return callable |
| 79 | 82 | * @throws \UnexpectedValueException |
| 80 | 83 | */ |
| 81 | - public static function createErrorParser($protocol, Service $api = null) | |
| 84 | + public static function createErrorParser($protocol, ?Service $api = null) | |
| 82 | 85 | { |
| 83 | 86 | static $mapping = ['json' => ErrorParser\JsonRpcErrorParser::class, 'query' => ErrorParser\XmlErrorParser::class, 'rest-json' => ErrorParser\RestJsonErrorParser::class, 'rest-xml' => ErrorParser\XmlErrorParser::class, 'ec2' => ErrorParser\XmlErrorParser::class]; |
| 84 | 87 | if (isset($mapping[$protocol])) { |
| 85 | 88 | return new $mapping[$protocol]($api); |
| @@ -156,9 +159,9 @@ | ||
| 156 | 159 | * @return string |
| 157 | 160 | */ |
| 158 | 161 | public function getServiceName() |
| 159 | 162 | { |
| 160 | - return $this->definition['metadata']['serviceIdentifier']; | |
| 163 | + return $this->definition['metadata']['serviceIdentifier'] ?? null; | |
| 161 | 164 | } |
| 162 | 165 | /** |
| 163 | 166 | * Get the default signature version of the service. |
| 164 | 167 | * |
| @@ -176,9 +179,9 @@ | ||
| 176 | 179 | * @return string |
| 177 | 180 | */ |
| 178 | 181 | public function getProtocol() |
| 179 | 182 | { |
| 180 | - return $this->definition['metadata']['protocol']; | |
| 183 | + return $this->protocol; | |
| 181 | 184 | } |
| 182 | 185 | /** |
| 183 | 186 | * Get the uid string used by the service |
| 184 | 187 | * |
| @@ -411,6 +414,27 @@ | ||
| 411 | 414 | */ |
| 412 | 415 | public function isModifiedModel() |
| 413 | 416 | { |
| 414 | 417 | return $this->modifiedModel; |
| 418 | + } | |
| 419 | + /** | |
| 420 | + * Accepts a list of protocols derived from the service model. | |
| 421 | + * Returns the highest priority compatible auth scheme if the `protocols` trait is present. | |
| 422 | + * Otherwise, returns the value of the `protocol` field, if set, or null. | |
| 423 | + * | |
| 424 | + * @param array $definition | |
| 425 | + * | |
| 426 | + * @return string|null | |
| 427 | + */ | |
| 428 | + private function selectProtocol(array $definition) : string|null | |
| 429 | + { | |
| 430 | + $modeledProtocols = $definition['metadata']['protocols'] ?? null; | |
| 431 | + if (!empty($modeledProtocols)) { | |
| 432 | + foreach (SupportedProtocols::cases() as $protocol) { | |
| 433 | + if (\in_array($protocol->value, $modeledProtocols)) { | |
| 434 | + return $protocol->value; | |
| 435 | + } | |
| 436 | + } | |
| 437 | + } | |
| 438 | + return $definition['metadata']['protocol'] ?? null; | |
| 415 | 439 | } |
| 416 | 440 | } |