v2: Updates

* Simplifies & beautifies everything
* Introduces a new Class system.
* Errors are defaulted to AWS's handler.
* New function names & more efficient handling.
* Should fix a majority of the errors.

Please read the README for more!
This commit is contained in:
Devang Srivastava 2020-09-28 15:32:51 +05:30
parent ad0726e41e
commit e6d7753dc8
1095 changed files with 45088 additions and 2911 deletions

View file

@ -1,6 +1,7 @@
<?php
namespace Aws;
use GuzzleHttp\Client;
use Psr\Http\Message\RequestInterface;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Promise\FulfilledPromise;
@ -141,8 +142,18 @@ function or_chain()
*/
function load_compiled_json($path)
{
if ($compiled = @include("$path.php")) {
return $compiled;
static $compiledList = [];
$compiledFilepath = "{$path}.php";
if (!isset($compiledList[$compiledFilepath])) {
if (is_readable($compiledFilepath)) {
$compiledList[$compiledFilepath] = include($compiledFilepath);
}
}
if (isset($compiledList[$compiledFilepath])) {
return $compiledList[$compiledFilepath];
}
if (!file_exists($path)) {
@ -262,14 +273,68 @@ function describe_type($input)
*/
function default_http_handler()
{
$version = (string) ClientInterface::VERSION;
if ($version[0] === '5') {
return new \Aws\Handler\GuzzleV5\GuzzleHandler();
} elseif ($version[0] === '6') {
$version = guzzle_major_version();
// If Guzzle 6 or 7 installed
if ($version === 6 || $version === 7) {
return new \Aws\Handler\GuzzleV6\GuzzleHandler();
} else {
throw new \RuntimeException('Unknown Guzzle version: ' . $version);
}
// If Guzzle 5 installed
if ($version === 5) {
return new \Aws\Handler\GuzzleV5\GuzzleHandler();
}
throw new \RuntimeException('Unknown Guzzle version: ' . $version);
}
/**
* Gets the default user agent string depending on the Guzzle version
*
* @return string
*/
function default_user_agent()
{
$version = guzzle_major_version();
// If Guzzle 6 or 7 installed
if ($version === 6 || $version === 7) {
return \GuzzleHttp\default_user_agent();
}
// If Guzzle 5 installed
if ($version === 5) {
return \GuzzleHttp\Client::getDefaultUserAgent();
}
throw new \RuntimeException('Unknown Guzzle version: ' . $version);
}
/**
* Get the major version of guzzle that is installed.
*
* @internal This function is internal and should not be used outside aws/aws-sdk-php.
* @return int
* @throws \RuntimeException
*/
function guzzle_major_version()
{
static $cache = null;
if (null !== $cache) {
return $cache;
}
if (defined('\GuzzleHttp\ClientInterface::VERSION')) {
$version = (string) ClientInterface::VERSION;
if ($version[0] === '6') {
return $cache = 6;
}
if ($version[0] === '5') {
return $cache = 5;
}
} elseif (defined('\GuzzleHttp\ClientInterface::MAJOR_VERSION')) {
return $cache = ClientInterface::MAJOR_VERSION;
}
throw new \RuntimeException('Unable to determine what Guzzle version is installed.');
}
/**
@ -323,7 +388,7 @@ function manifest($service = null)
static $manifest = [];
static $aliases = [];
if (empty($manifest)) {
$manifest = load_compiled_json(dirname(__FILE__) . '/data/manifest.json');
$manifest = load_compiled_json(__DIR__ . '/data/manifest.json');
foreach ($manifest as $endpoint => $info) {
$alias = strtolower($info['namespace']);
if ($alias !== $endpoint) {
@ -341,11 +406,116 @@ function manifest($service = null)
$service = strtolower($service);
if (isset($manifest[$service])) {
return $manifest[$service] + ['endpoint' => $service];
} elseif (isset($aliases[$service])) {
return manifest($aliases[$service]);
} else {
throw new \InvalidArgumentException(
"The service \"{$service}\" is not provided by the AWS SDK for PHP."
);
}
if (isset($aliases[$service])) {
return manifest($aliases[$service]);
}
throw new \InvalidArgumentException(
"The service \"{$service}\" is not provided by the AWS SDK for PHP."
);
}
/**
* Checks if supplied parameter is a valid hostname
*
* @param string $hostname
* @return bool
*/
function is_valid_hostname($hostname)
{
return (
preg_match("/^([a-z\d](-*[a-z\d])*)(\.([a-z\d](-*[a-z\d])*))*\.?$/i", $hostname)
&& preg_match("/^.{1,253}$/", $hostname)
&& preg_match("/^[^\.]{1,63}(\.[^\.]{0,63})*$/", $hostname)
);
}
/**
* Checks if supplied parameter is a valid host label
*
* @param $label
* @return bool
*/
function is_valid_hostlabel($label)
{
return preg_match("/^(?!-)[a-zA-Z0-9-]{1,63}(?<!-)$/", $label);
}
/**
* Ignores '#' full line comments, which parse_ini_file no longer does
* in PHP 7+.
*
* @param $filename
* @param bool $process_sections
* @param int $scanner_mode
* @return array|bool
*/
function parse_ini_file(
$filename,
$process_sections = false,
$scanner_mode = INI_SCANNER_NORMAL)
{
return parse_ini_string(
preg_replace('/^#.*\\n/m', "", file_get_contents($filename)),
$process_sections,
$scanner_mode
);
}
/**
* Outputs boolean value of input for a select range of possible values,
* null otherwise
*
* @param $input
* @return bool|null
*/
function boolean_value($input)
{
if (is_bool($input)) {
return $input;
}
if ($input === 0) {
return false;
}
if ($input === 1) {
return true;
}
if (is_string($input)) {
switch (strtolower($input)) {
case "true":
case "on":
case "1":
return true;
break;
case "false":
case "off":
case "0":
return false;
break;
}
}
return null;
}
/**
* Checks if an input is a valid epoch time
*
* @param $input
* @return bool
*/
function is_valid_epoch($input)
{
if (is_string($input) || is_numeric($input)) {
if (is_string($input) && !preg_match("/^-?[0-9]+\.?[0-9]*$/", $input)) {
return false;
}
return true;
}
return false;
}