| @@ -1,11 +1,10 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace Dudlewebs\WPMCS\s3\Aws; |
| 4 | 4 | |
| 5 | -use Dudlewebs\WPMCS\s3\GuzzleHttp\Client; | |
| 5 | +use Dudlewebs\WPMCS\s3\GuzzleHttp\Utils; | |
| 6 | 6 | use Dudlewebs\WPMCS\s3\Psr\Http\Message\RequestInterface; |
| 7 | -use Dudlewebs\WPMCS\s3\GuzzleHttp\ClientInterface; | |
| 8 | 7 | use Dudlewebs\WPMCS\s3\GuzzleHttp\Promise\FulfilledPromise; |
| 9 | 8 | //----------------------------------------------------------------------------- |
| 10 | 9 | // Functional functions |
| 11 | 10 | //----------------------------------------------------------------------------- |
| @@ -248,18 +247,9 @@ | ||
| 248 | 247 | * @return callable |
| 249 | 248 | */ |
| 250 | 249 | function default_http_handler() |
| 251 | 250 | { |
| 252 | - $version = guzzle_major_version(); | |
| 253 | - // If Guzzle 6 or 7 installed | |
| 254 | - if ($version === 6 || $version === 7) { | |
| 255 | - return new \Dudlewebs\WPMCS\s3\Aws\Handler\GuzzleV6\GuzzleHandler(); | |
| 256 | - } | |
| 257 | - // If Guzzle 5 installed | |
| 258 | - if ($version === 5) { | |
| 259 | - return new \Dudlewebs\WPMCS\s3\Aws\Handler\GuzzleV5\GuzzleHandler(); | |
| 260 | - } | |
| 261 | - throw new \RuntimeException('Unknown Guzzle version: ' . $version); | |
| 251 | + return new \Dudlewebs\WPMCS\s3\Aws\Handler\Guzzle\GuzzleHandler(); | |
| 262 | 252 | } |
| 263 | 253 | /** |
| 264 | 254 | * Gets the default user agent string depending on the Guzzle version |
| 265 | 255 | * |
| @@ -266,46 +256,11 @@ | ||
| 266 | 256 | * @return string |
| 267 | 257 | */ |
| 268 | 258 | function default_user_agent() |
| 269 | 259 | { |
| 270 | - $version = guzzle_major_version(); | |
| 271 | - // If Guzzle 6 or 7 installed | |
| 272 | - if ($version === 6 || $version === 7) { | |
| 273 | - return \Dudlewebs\WPMCS\s3\GuzzleHttp\default_user_agent(); | |
| 274 | - } | |
| 275 | - // If Guzzle 5 installed | |
| 276 | - if ($version === 5) { | |
| 277 | - return \Dudlewebs\WPMCS\s3\GuzzleHttp\Client::getDefaultUserAgent(); | |
| 278 | - } | |
| 279 | - throw new \RuntimeException('Unknown Guzzle version: ' . $version); | |
| 260 | + return Utils::defaultUserAgent(); | |
| 280 | 261 | } |
| 281 | 262 | /** |
| 282 | - * Get the major version of guzzle that is installed. | |
| 283 | - * | |
| 284 | - * @internal This function is internal and should not be used outside aws/aws-sdk-php. | |
| 285 | - * @return int | |
| 286 | - * @throws \RuntimeException | |
| 287 | - */ | |
| 288 | -function guzzle_major_version() | |
| 289 | -{ | |
| 290 | - static $cache = null; | |
| 291 | - if (null !== $cache) { | |
| 292 | - return $cache; | |
| 293 | - } | |
| 294 | - if (\defined('Dudlewebs\\WPMCS\\s3\\GuzzleHttp\\ClientInterface::VERSION')) { | |
| 295 | - $version = (string) ClientInterface::VERSION; | |
| 296 | - if ($version[0] === '6') { | |
| 297 | - return $cache = 6; | |
| 298 | - } | |
| 299 | - if ($version[0] === '5') { | |
| 300 | - return $cache = 5; | |
| 301 | - } | |
| 302 | - } elseif (\defined('Dudlewebs\\WPMCS\\s3\\GuzzleHttp\\ClientInterface::MAJOR_VERSION')) { | |
| 303 | - return $cache = ClientInterface::MAJOR_VERSION; | |
| 304 | - } | |
| 305 | - throw new \RuntimeException('Unable to determine what Guzzle version is installed.'); | |
| 306 | -} | |
| 307 | -/** | |
| 308 | 263 | * Serialize a request for a command but do not send it. |
| 309 | 264 | * |
| 310 | 265 | * Returns a promise that is fulfilled with the serialized request. |
| 311 | 266 | * |
| @@ -436,8 +391,56 @@ | ||
| 436 | 391 | } |
| 437 | 392 | return null; |
| 438 | 393 | } |
| 439 | 394 | /** |
| 395 | + * Parses ini sections with subsections (i.e. the service section) | |
| 396 | + * | |
| 397 | + * @param $filename | |
| 398 | + * @param $filename | |
| 399 | + * @return array | |
| 400 | + */ | |
| 401 | +function parse_ini_section_with_subsections($filename, $section_name) | |
| 402 | +{ | |
| 403 | + $config = []; | |
| 404 | + $stream = \fopen($filename, 'r'); | |
| 405 | + if (!$stream) { | |
| 406 | + return $config; | |
| 407 | + } | |
| 408 | + $current_subsection = ''; | |
| 409 | + while (!\feof($stream)) { | |
| 410 | + $line = \trim(\fgets($stream)); | |
| 411 | + if (empty($line) || \in_array($line[0], [';', '#'])) { | |
| 412 | + continue; | |
| 413 | + } | |
| 414 | + if (\preg_match('/^\\[.*\\]$/', $line) && \trim($line, '[]') === $section_name) { | |
| 415 | + while (!\feof($stream)) { | |
| 416 | + $line = \trim(\fgets($stream)); | |
| 417 | + if (empty($line) || \in_array($line[0], [';', '#'])) { | |
| 418 | + continue; | |
| 419 | + } | |
| 420 | + if (\preg_match('/^\\[.*\\]$/', $line) && \trim($line, '[]') === $section_name) { | |
| 421 | + continue; | |
| 422 | + } elseif (\strpos($line, '[') === 0) { | |
| 423 | + break; | |
| 424 | + } | |
| 425 | + if (\strpos($line, ' = ') !== \false) { | |
| 426 | + list($key, $value) = \explode(' = ', $line, 2); | |
| 427 | + if (empty($current_subsection)) { | |
| 428 | + $config[$key] = $value; | |
| 429 | + } else { | |
| 430 | + $config[$current_subsection][$key] = $value; | |
| 431 | + } | |
| 432 | + } else { | |
| 433 | + $current_subsection = \trim(\str_replace('=', '', $line)); | |
| 434 | + $config[$current_subsection] = []; | |
| 435 | + } | |
| 436 | + } | |
| 437 | + } | |
| 438 | + } | |
| 439 | + \fclose($stream); | |
| 440 | + return $config; | |
| 441 | +} | |
| 442 | +/** | |
| 440 | 443 | * Checks if an input is a valid epoch time |
| 441 | 444 | * |
| 442 | 445 | * @param $input |
| 443 | 446 | * @return bool |
| @@ -470,5 +473,19 @@ | ||
| 470 | 473 | */ |
| 471 | 474 | function strip_fips_pseudo_regions($region) |
| 472 | 475 | { |
| 473 | 476 | return \str_replace(['fips-', '-fips'], ['', ''], $region); |
| 477 | +} | |
| 478 | +/** | |
| 479 | + * Checks if an array is associative | |
| 480 | + * | |
| 481 | + * @param array $array | |
| 482 | + * | |
| 483 | + * @return bool | |
| 484 | + */ | |
| 485 | +function is_associative(array $array) : bool | |
| 486 | +{ | |
| 487 | + if (empty($array)) { | |
| 488 | + return \false; | |
| 489 | + } | |
| 490 | + return !\array_is_list($array); | |
| 474 | 491 | } |