← All changes
|
includes/sdk/google/google/gax/src/RequestBuilder.php
+24
-24
1.2.6
→
1.4.2
View file →
| @@ -29,16 +29,16 @@ | ||
| 29 | 29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 30 | 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 31 | 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 32 | 32 | */ |
| 33 | -namespace Dudlewebs\WPMCS\Google\ApiCore; | |
| 33 | +namespace Dudlewebs\WPMCS\GCP\Google\ApiCore; | |
| 34 | 34 | |
| 35 | -use Dudlewebs\WPMCS\Google\ApiCore\ResourceTemplate\AbsoluteResourceTemplate; | |
| 36 | -use Dudlewebs\WPMCS\Google\Protobuf\Internal\Message; | |
| 37 | -use Dudlewebs\WPMCS\GuzzleHttp\Psr7\Request; | |
| 38 | -use Dudlewebs\WPMCS\GuzzleHttp\Psr7\Utils; | |
| 39 | -use Dudlewebs\WPMCS\Psr\Http\Message\RequestInterface; | |
| 40 | -use Dudlewebs\WPMCS\Psr\Http\Message\UriInterface; | |
| 35 | +use Dudlewebs\WPMCS\GCP\Google\ApiCore\ResourceTemplate\AbsoluteResourceTemplate; | |
| 36 | +use Dudlewebs\WPMCS\GCP\Google\Protobuf\Internal\Message; | |
| 37 | +use Dudlewebs\WPMCS\GCP\GuzzleHttp\Psr7\Request; | |
| 38 | +use Dudlewebs\WPMCS\GCP\GuzzleHttp\Psr7\Utils; | |
| 39 | +use Dudlewebs\WPMCS\GCP\Psr\Http\Message\RequestInterface; | |
| 40 | +use Dudlewebs\WPMCS\GCP\Psr\Http\Message\UriInterface; | |
| 41 | 41 | /** |
| 42 | 42 | * Builds a PSR-7 request from a set of request information. |
| 43 | 43 | * |
| 44 | 44 | * @internal |
| @@ -47,9 +47,9 @@ | ||
| 47 | 47 | { |
| 48 | 48 | use ArrayTrait; |
| 49 | 49 | use UriTrait; |
| 50 | 50 | use ValidationTrait; |
| 51 | - private $baseUri; | |
| 51 | + protected $baseUri; | |
| 52 | 52 | private $restConfig; |
| 53 | 53 | /** |
| 54 | 54 | * @param string $baseUri |
| 55 | 55 | * @param string $restConfigPath |
| @@ -58,9 +58,9 @@ | ||
| 58 | 58 | public function __construct(string $baseUri, string $restConfigPath) |
| 59 | 59 | { |
| 60 | 60 | self::validateFileExists($restConfigPath); |
| 61 | 61 | $this->baseUri = $baseUri; |
| 62 | - $this->restConfig = require $restConfigPath; | |
| 62 | + $this->restConfig = (require $restConfigPath); | |
| 63 | 63 | } |
| 64 | 64 | /** |
| 65 | 65 | * @param string $path |
| 66 | 66 | * @return bool |
| @@ -66,9 +66,9 @@ | ||
| 66 | 66 | * @return bool |
| 67 | 67 | */ |
| 68 | 68 | public function pathExists(string $path) |
| 69 | 69 | { |
| 70 | - list($interface, $method) = explode('/', $path); | |
| 70 | + list($interface, $method) = \explode('/', $path); | |
| 71 | 71 | return isset($this->restConfig['interfaces'][$interface][$method]); |
| 72 | 72 | } |
| 73 | 73 | /** |
| 74 | 74 | * @param string $path |
| @@ -78,9 +78,9 @@ | ||
| 78 | 78 | * @throws ValidationException |
| 79 | 79 | */ |
| 80 | 80 | public function build(string $path, Message $message, array $headers = []) |
| 81 | 81 | { |
| 82 | - list($interface, $method) = explode('/', $path); | |
| 82 | + list($interface, $method) = \explode('/', $path); | |
| 83 | 83 | if (!isset($this->restConfig['interfaces'][$interface][$method])) { |
| 84 | 84 | throw new ValidationException("Failed to build request, as the provided path ({$path}) was not found in the configuration."); |
| 85 | 85 | } |
| 86 | 86 | $numericEnums = isset($this->restConfig['numericEnums']) && $this->restConfig['numericEnums']; |
| @@ -93,9 +93,9 @@ | ||
| 93 | 93 | // We found a valid uriTemplate - now build and return the Request |
| 94 | 94 | list($body, $queryParams) = $this->constructBodyAndQueryParameters($message, $config); |
| 95 | 95 | // Request enum fields will be encoded as numbers rather than strings (in the response). |
| 96 | 96 | if ($numericEnums) { |
| 97 | - $queryParams['$alt'] = "json;enum-encoding=int"; | |
| 97 | + $queryParams['$alt'] = 'json;enum-encoding=int'; | |
| 98 | 98 | } |
| 99 | 99 | $uri = $this->buildUri($pathTemplate, $queryParams); |
| 100 | 100 | return new Request($config['method'], $uri, ['Content-Type' => 'application/json'] + $headers, $body); |
| 101 | 101 | } |
| @@ -104,9 +104,9 @@ | ||
| 104 | 104 | $uriTemplates = []; |
| 105 | 105 | foreach ($uriTemplateConfigs as $config) { |
| 106 | 106 | $uriTemplates[] = $config['uriTemplate']; |
| 107 | 107 | } |
| 108 | - throw new ValidationException("Could not map bindings for {$path} to any Uri template.\n" . "Bindings: " . print_r($bindings, \true) . "UriTemplates: " . print_r($uriTemplates, \true)); | |
| 108 | + throw new ValidationException("Could not map bindings for {$path} to any Uri template.\n" . 'Bindings: ' . \print_r($bindings, \true) . 'UriTemplates: ' . \print_r($uriTemplates, \true)); | |
| 109 | 109 | } |
| 110 | 110 | /** |
| 111 | 111 | * Create a list of all possible configs using the additionalBindings |
| 112 | 112 | * |
| @@ -135,11 +135,11 @@ | ||
| 135 | 135 | return [$messageDataJson, []]; |
| 136 | 136 | } |
| 137 | 137 | $body = null; |
| 138 | 138 | $queryParams = []; |
| 139 | - $messageData = json_decode($messageDataJson, \true); | |
| 139 | + $messageData = \json_decode($messageDataJson, \true); | |
| 140 | 140 | foreach ($messageData as $name => $value) { |
| 141 | - if (array_key_exists($name, $config['placeholders'])) { | |
| 141 | + if (\array_key_exists($name, $config['placeholders'])) { | |
| 142 | 142 | continue; |
| 143 | 143 | } |
| 144 | 144 | if (Serializer::toSnakeCase($name) === $config['body']) { |
| 145 | 145 | if (($bodyMessage = $message->{"get{$name}"}()) instanceof Message) { |
| @@ -144,13 +144,13 @@ | ||
| 144 | 144 | if (Serializer::toSnakeCase($name) === $config['body']) { |
| 145 | 145 | if (($bodyMessage = $message->{"get{$name}"}()) instanceof Message) { |
| 146 | 146 | $body = $bodyMessage->serializeToJsonString(); |
| 147 | 147 | } else { |
| 148 | - $body = json_encode($value); | |
| 148 | + $body = \json_encode($value); | |
| 149 | 149 | } |
| 150 | 150 | continue; |
| 151 | 151 | } |
| 152 | - if (is_array($value) && $this->isAssoc($value)) { | |
| 152 | + if (\is_array($value) && $this->isAssoc($value)) { | |
| 153 | 153 | foreach ($value as $key => $value2) { |
| 154 | 154 | $queryParams[$name . '.' . $key] = $value2; |
| 155 | 155 | } |
| 156 | 156 | } else { |
| @@ -161,16 +161,16 @@ | ||
| 161 | 161 | // over the wire. |
| 162 | 162 | if (isset($config['queryParams'])) { |
| 163 | 163 | foreach ($config['queryParams'] as $requiredQueryParam) { |
| 164 | 164 | $requiredQueryParam = Serializer::toCamelCase($requiredQueryParam); |
| 165 | - if (!array_key_exists($requiredQueryParam, $queryParams)) { | |
| 165 | + if (!\array_key_exists($requiredQueryParam, $queryParams)) { | |
| 166 | 166 | $getter = Serializer::getGetter($requiredQueryParam); |
| 167 | 167 | $queryParamValue = $message->{$getter}(); |
| 168 | 168 | if ($queryParamValue instanceof Message) { |
| 169 | 169 | // Decode message for the query parameter. |
| 170 | - $queryParamValue = json_decode($queryParamValue->serializeToJsonString(), \true); | |
| 170 | + $queryParamValue = \json_decode($queryParamValue->serializeToJsonString(), \true); | |
| 171 | 171 | } |
| 172 | - if (is_array($queryParamValue)) { | |
| 172 | + if (\is_array($queryParamValue)) { | |
| 173 | 173 | // If the message has properties, add them as nested querystring values. |
| 174 | 174 | // NOTE: This only supports nesting at one level of depth. |
| 175 | 175 | foreach ($queryParamValue as $key => $value) { |
| 176 | 176 | $queryParams[$requiredQueryParam . '.' . $key] = $value; |
| @@ -191,10 +191,10 @@ | ||
| 191 | 191 | private function buildBindings(array $placeholders, Message $message) |
| 192 | 192 | { |
| 193 | 193 | $bindings = []; |
| 194 | 194 | foreach ($placeholders as $placeholder => $metadata) { |
| 195 | - $value = array_reduce($metadata['getters'], function (Message $result = null, $getter) { | |
| 196 | - if ($result) { | |
| 195 | + $value = \array_reduce($metadata['getters'], function (?Message $result = null, $getter = null) { | |
| 196 | + if ($result && $getter) { | |
| 197 | 197 | return $result->{$getter}(); |
| 198 | 198 | } |
| 199 | 199 | }, $message); |
| 200 | 200 | $bindings[$placeholder] = $value; |
| @@ -222,11 +222,11 @@ | ||
| 222 | 222 | * @param string $path |
| 223 | 223 | * @param array $queryParams |
| 224 | 224 | * @return UriInterface |
| 225 | 225 | */ |
| 226 | - private function buildUri(string $path, array $queryParams) | |
| 226 | + protected function buildUri(string $path, array $queryParams) | |
| 227 | 227 | { |
| 228 | - $uri = Utils::uriFor(sprintf('https://%s%s', $this->baseUri, $path)); | |
| 228 | + $uri = Utils::uriFor(\sprintf('https://%s%s', $this->baseUri, $path)); | |
| 229 | 229 | if ($queryParams) { |
| 230 | 230 | $uri = $this->buildUriWithQuery($uri, $queryParams); |
| 231 | 231 | } |
| 232 | 232 | return $uri; |