summaryrefslogtreecommitdiff
path: root/vendor/aws/aws-crt-php/src/AWS
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2022-11-23 21:14:33 +0300
committerAndrew Dolgov <[email protected]>2022-11-23 21:14:33 +0300
commit0c8af4992cb0f7589dcafaad65ada12753c64594 (patch)
tree18e83d068c3e7dd2499331de977782b382279396 /vendor/aws/aws-crt-php/src/AWS
initial
Diffstat (limited to 'vendor/aws/aws-crt-php/src/AWS')
-rw-r--r--vendor/aws/aws-crt-php/src/AWS/CRT/Auth/AwsCredentials.php69
-rw-r--r--vendor/aws/aws-crt-php/src/AWS/CRT/Auth/CredentialsProvider.php23
-rw-r--r--vendor/aws/aws-crt-php/src/AWS/CRT/Auth/Signable.php43
-rw-r--r--vendor/aws/aws-crt-php/src/AWS/CRT/Auth/SignatureType.php15
-rw-r--r--vendor/aws/aws-crt-php/src/AWS/CRT/Auth/SignedBodyHeaderType.php11
-rw-r--r--vendor/aws/aws-crt-php/src/AWS/CRT/Auth/Signing.php22
-rw-r--r--vendor/aws/aws-crt-php/src/AWS/CRT/Auth/SigningAlgorithm.php11
-rw-r--r--vendor/aws/aws-crt-php/src/AWS/CRT/Auth/SigningConfigAWS.php75
-rw-r--r--vendor/aws/aws-crt-php/src/AWS/CRT/Auth/SigningResult.php33
-rw-r--r--vendor/aws/aws-crt-php/src/AWS/CRT/Auth/StaticCredentialsProvider.php35
-rw-r--r--vendor/aws/aws-crt-php/src/AWS/CRT/CRT.php358
-rw-r--r--vendor/aws/aws-crt-php/src/AWS/CRT/HTTP/Headers.php50
-rw-r--r--vendor/aws/aws-crt-php/src/AWS/CRT/HTTP/Message.php95
-rw-r--r--vendor/aws/aws-crt-php/src/AWS/CRT/HTTP/Request.php32
-rw-r--r--vendor/aws/aws-crt-php/src/AWS/CRT/HTTP/Response.php27
-rw-r--r--vendor/aws/aws-crt-php/src/AWS/CRT/IO/EventLoopGroup.php39
-rw-r--r--vendor/aws/aws-crt-php/src/AWS/CRT/IO/InputStream.php49
-rw-r--r--vendor/aws/aws-crt-php/src/AWS/CRT/Internal/Encoding.php37
-rw-r--r--vendor/aws/aws-crt-php/src/AWS/CRT/Internal/Extension.php29
-rw-r--r--vendor/aws/aws-crt-php/src/AWS/CRT/Log.php47
-rw-r--r--vendor/aws/aws-crt-php/src/AWS/CRT/NativeResource.php42
-rw-r--r--vendor/aws/aws-crt-php/src/AWS/CRT/Options.php77
22 files changed, 1219 insertions, 0 deletions
diff --git a/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/AwsCredentials.php b/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/AwsCredentials.php
new file mode 100644
index 0000000..6f6acee
--- /dev/null
+++ b/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/AwsCredentials.php
@@ -0,0 +1,69 @@
+<?php
+/**
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0.
+ */
+namespace AWS\CRT\Auth;
+
+use AWS\CRT\NativeResource as NativeResource;
+use AWS\CRT\Options as Options;
+
+/**
+ * Represents a set of AWS credentials
+ *
+ * @param array options:
+ * - string access_key_id - AWS Access Key Id
+ * - string secret_access_key - AWS Secret Access Key
+ * - string session_token - Optional STS session token
+ * - int expiration_timepoint_seconds - Optional time to expire these credentials
+ */
+final class AwsCredentials extends NativeResource {
+
+ static function defaults() {
+ return [
+ 'access_key_id' => '',
+ 'secret_access_key' => '',
+ 'session_token' => '',
+ 'expiration_timepoint_seconds' => 0,
+ ];
+ }
+
+ private $access_key_id;
+ private $secret_access_key;
+ private $session_token;
+ private $expiration_timepoint_seconds = 0;
+
+ public function __get($name) {
+ return $this->$name;
+ }
+
+ function __construct(array $options = []) {
+ parent::__construct();
+
+ $options = new Options($options, self::defaults());
+ $this->access_key_id = $options->access_key_id->asString();
+ $this->secret_access_key = $options->secret_access_key->asString();
+ $this->session_token = $options->session_token ? $options->session_token->asString() : null;
+ $this->expiration_timepoint_seconds = $options->expiration_timepoint_seconds->asInt();
+
+ if (strlen($this->access_key_id) == 0) {
+ throw new \InvalidArgumentException("access_key_id must be provided");
+ }
+ if (strlen($this->secret_access_key) == 0) {
+ throw new \InvalidArgumentException("secret_access_key must be provided");
+ }
+
+ $creds_options = self::$crt->aws_credentials_options_new();
+ self::$crt->aws_credentials_options_set_access_key_id($creds_options, $this->access_key_id);
+ self::$crt->aws_credentials_options_set_secret_access_key($creds_options, $this->secret_access_key);
+ self::$crt->aws_credentials_options_set_session_token($creds_options, $this->session_token);
+ self::$crt->aws_credentials_options_set_expiration_timepoint_seconds($creds_options, $this->expiration_timepoint_seconds);
+ $this->acquire(self::$crt->aws_credentials_new($creds_options));
+ self::$crt->aws_credentials_options_release($creds_options);
+ }
+
+ function __destruct() {
+ self::$crt->aws_credentials_release($this->release());
+ parent::__destruct();
+ }
+}
diff --git a/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/CredentialsProvider.php b/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/CredentialsProvider.php
new file mode 100644
index 0000000..e9d3588
--- /dev/null
+++ b/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/CredentialsProvider.php
@@ -0,0 +1,23 @@
+<?php
+/**
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0.
+ */
+namespace AWS\CRT\Auth;
+
+use AWS\CRT\NativeResource as NativeResource;
+
+/**
+ * Base class for credentials providers
+ */
+abstract class CredentialsProvider extends NativeResource {
+
+ function __construct(array $options = []) {
+ parent::__construct();
+ }
+
+ function __destruct() {
+ self::$crt->credentials_provider_release($this->release());
+ parent::__destruct();
+ }
+}
diff --git a/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/Signable.php b/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/Signable.php
new file mode 100644
index 0000000..100b56a
--- /dev/null
+++ b/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/Signable.php
@@ -0,0 +1,43 @@
+<?php
+/**
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0.
+ */
+namespace AWS\CRT\Auth;
+
+use AWS\CRT\IO\InputStream;
+use AWS\CRT\NativeResource as NativeResource;
+
+class Signable extends NativeResource {
+
+ public static function fromHttpRequest($http_message) {
+ return new Signable(function() use ($http_message) {
+ return self::$crt->signable_new_from_http_request($http_message->native);
+ });
+ }
+
+ public static function fromChunk($chunk_stream, $previous_signature="") {
+ if (!($chunk_stream instanceof InputStream)) {
+ $chunk_stream = new InputStream($chunk_stream);
+ }
+ return new Signable(function() use($chunk_stream, $previous_signature) {
+ return self::$crt->signable_new_from_chunk($chunk_stream->native, $previous_signature);
+ });
+ }
+
+ public static function fromCanonicalRequest($canonical_request) {
+ return new Signable(function() use($canonical_request) {
+ return self::$crt->signable_new_from_canonical_request($canonical_request);
+ });
+ }
+
+ protected function __construct($ctor) {
+ parent::__construct();
+ $this->acquire($ctor());
+ }
+
+ function __destruct() {
+ self::$crt->signable_release($this->release());
+ parent::__destruct();
+ }
+} \ No newline at end of file
diff --git a/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/SignatureType.php b/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/SignatureType.php
new file mode 100644
index 0000000..3d3b99f
--- /dev/null
+++ b/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/SignatureType.php
@@ -0,0 +1,15 @@
+<?php
+/**
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0.
+ */
+namespace AWS\CRT\Auth;
+
+class SignatureType {
+ const HTTP_REQUEST_HEADERS = 0;
+ const HTTP_REQUEST_QUERY_PARAMS = 1;
+ const HTTP_REQUEST_CHUNK = 2;
+ const HTTP_REQUEST_EVENT = 3;
+ const CANONICAL_REQUEST_HEADERS = 4;
+ const CANONICAL_REQUEST_QUERY_PARAMS = 5;
+} \ No newline at end of file
diff --git a/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/SignedBodyHeaderType.php b/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/SignedBodyHeaderType.php
new file mode 100644
index 0000000..cb3d438
--- /dev/null
+++ b/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/SignedBodyHeaderType.php
@@ -0,0 +1,11 @@
+<?php
+/**
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0.
+ */
+namespace AWS\CRT\Auth;
+
+class SignedBodyHeaderType {
+ const NONE = 0;
+ const X_AMZ_CONTENT_SHA256 = 1;
+} \ No newline at end of file
diff --git a/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/Signing.php b/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/Signing.php
new file mode 100644
index 0000000..d979db9
--- /dev/null
+++ b/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/Signing.php
@@ -0,0 +1,22 @@
+<?php
+/**
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0.
+ */
+namespace AWS\CRT\Auth;
+
+use AWS\CRT\NativeResource;
+
+abstract class Signing extends NativeResource {
+ static function signRequestAws($signable, $signing_config, $on_complete) {
+ return self::$crt->sign_request_aws($signable->native, $signing_config->native,
+ function($result, $error_code) use ($on_complete) {
+ $signing_result = SigningResult::fromNative($result);
+ $on_complete($signing_result, $error_code);
+ }, null);
+ }
+
+ static function testVerifySigV4ASigning($signable, $signing_config, $expected_canonical_request, $signature, $ecc_key_pub_x, $ecc_key_pub_y) {
+ return self::$crt->test_verify_sigv4a_signing($signable, $signing_config, $expected_canonical_request, $signature, $ecc_key_pub_x, $ecc_key_pub_y);
+ }
+}
diff --git a/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/SigningAlgorithm.php b/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/SigningAlgorithm.php
new file mode 100644
index 0000000..dd11059
--- /dev/null
+++ b/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/SigningAlgorithm.php
@@ -0,0 +1,11 @@
+<?php
+/**
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0.
+ */
+namespace AWS\CRT\Auth;
+
+class SigningAlgorithm {
+ const SIGv4 = 0;
+ const SIGv4_ASYMMETRIC = 1;
+}
diff --git a/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/SigningConfigAWS.php b/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/SigningConfigAWS.php
new file mode 100644
index 0000000..8a73df9
--- /dev/null
+++ b/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/SigningConfigAWS.php
@@ -0,0 +1,75 @@
+<?php
+/**
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0.
+ */
+namespace AWS\CRT\Auth;
+
+use AWS\CRT\NativeResource as NativeResource;
+use AWS\CRT\Options as Options;
+
+class SigningConfigAWS extends NativeResource {
+
+ public static function defaults() {
+ return [
+ 'algorithm' => SigningAlgorithm::SIGv4,
+ 'signature_type' => SignatureType::HTTP_REQUEST_HEADERS,
+ 'credentials_provider' => null,
+ 'region' => null,
+ 'service' => null,
+ 'use_double_uri_encode' => false,
+ 'should_normalize_uri_path' => false,
+ 'omit_session_token' => false,
+ 'signed_body_value' => null,
+ 'signed_body_header_type' => SignedBodyHeaderType::NONE,
+ 'expiration_in_seconds' => 0,
+ 'date' => time(),
+ 'should_sign_header' => null,
+ ];
+ }
+
+ private $options;
+
+ public function __construct(array $options = []) {
+ parent::__construct();
+ $this->options = $options = new Options($options, self::defaults());
+ $sc = $this->acquire(self::$crt->signing_config_aws_new());
+ self::$crt->signing_config_aws_set_algorithm($sc, $options->algorithm->asInt());
+ self::$crt->signing_config_aws_set_signature_type($sc, $options->signature_type->asInt());
+ if ($credentials_provider = $options->credentials_provider->asObject()) {
+ self::$crt->signing_config_aws_set_credentials_provider(
+ $sc,
+ $credentials_provider->native);
+ }
+ self::$crt->signing_config_aws_set_region(
+ $sc, $options->region->asString());
+ self::$crt->signing_config_aws_set_service(
+ $sc, $options->service->asString());
+ self::$crt->signing_config_aws_set_use_double_uri_encode(
+ $sc, $options->use_double_uri_encode->asBool());
+ self::$crt->signing_config_aws_set_should_normalize_uri_path(
+ $sc, $options->should_normalize_uri_path->asBool());
+ self::$crt->signing_config_aws_set_omit_session_token(
+ $sc, $options->omit_session_token->asBool());
+ self::$crt->signing_config_aws_set_signed_body_value(
+ $sc, $options->signed_body_value->asString());
+ self::$crt->signing_config_aws_set_signed_body_header_type(
+ $sc, $options->signed_body_header_type->asInt());
+ self::$crt->signing_config_aws_set_expiration_in_seconds(
+ $sc, $options->expiration_in_seconds->asInt());
+ self::$crt->signing_config_aws_set_date($sc, $options->date->asInt());
+ if ($should_sign_header = $options->should_sign_header->asCallable()) {
+ self::$crt->signing_config_aws_set_should_sign_header_fn($sc, $should_sign_header);
+ }
+ }
+
+ function __destruct()
+ {
+ self::$crt->signing_config_aws_release($this->release());
+ parent::__destruct();
+ }
+
+ public function __get($name) {
+ return $this->options->get($name);
+ }
+} \ No newline at end of file
diff --git a/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/SigningResult.php b/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/SigningResult.php
new file mode 100644
index 0000000..b8a4ab5
--- /dev/null
+++ b/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/SigningResult.php
@@ -0,0 +1,33 @@
+<?php
+/**
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0.
+ */
+namespace AWS\CRT\Auth;
+
+use AWS\CRT\NativeResource;
+use AWS\CRT\HTTP\Request;
+
+class SigningResult extends NativeResource {
+ protected function __construct($native) {
+ parent::__construct();
+
+ $this->acquire($native);
+ }
+
+ function __destruct() {
+ // No destruction necessary, SigningResults are transient, just release
+ $this->release();
+ parent::__destruct();
+ }
+
+ public static function fromNative($ptr) {
+ return new SigningResult($ptr);
+ }
+
+ public function applyToHttpRequest(&$http_request) {
+ self::$crt->signing_result_apply_to_http_request($this->native, $http_request->native);
+ // Update http_request from native
+ $http_request = Request::unmarshall($http_request->toBlob());
+ }
+} \ No newline at end of file
diff --git a/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/StaticCredentialsProvider.php b/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/StaticCredentialsProvider.php
new file mode 100644
index 0000000..8dc6249
--- /dev/null
+++ b/vendor/aws/aws-crt-php/src/AWS/CRT/Auth/StaticCredentialsProvider.php
@@ -0,0 +1,35 @@
+<?php
+/**
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0.
+ */
+namespace AWS\CRT\Auth;
+
+/**
+ * Provides a static set of AWS credentials
+ *
+ * @param array options:
+ * - string access_key_id - AWS Access Key Id
+ * - string secret_access_key - AWS Secret Access Key
+ * - string session_token - Optional STS session token
+ */
+final class StaticCredentialsProvider extends CredentialsProvider {
+
+ private $credentials;
+
+ public function __get($name) {
+ return $this->$name;
+ }
+
+ function __construct(array $options = []) {
+ parent::__construct();
+ $this->credentials = new AwsCredentials($options);
+
+ $provider_options = self::$crt->credentials_provider_static_options_new();
+ self::$crt->credentials_provider_static_options_set_access_key_id($provider_options, $this->credentials->access_key_id);
+ self::$crt->credentials_provider_static_options_set_secret_access_key($provider_options, $this->credentials->secret_access_key);
+ self::$crt->credentials_provider_static_options_set_session_token($provider_options, $this->credentials->session_token);
+ $this->acquire(self::$crt->credentials_provider_static_new($provider_options));
+ self::$crt->credentials_provider_static_options_release($provider_options);
+ }
+}
diff --git a/vendor/aws/aws-crt-php/src/AWS/CRT/CRT.php b/vendor/aws/aws-crt-php/src/AWS/CRT/CRT.php
new file mode 100644
index 0000000..d196a47
--- /dev/null
+++ b/vendor/aws/aws-crt-php/src/AWS/CRT/CRT.php
@@ -0,0 +1,358 @@
+<?php
+/**
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0.
+ */
+namespace AWS\CRT;
+
+use AWS\CRT\Internal\Extension;
+
+use \RuntimeException;
+
+/**
+ * Wrapper for the interface to the CRT. There only ever needs to be one of these, but
+ * additional instances won't cost anything other than their memory.
+ * Creating an instance of any NativeResource will activate the CRT binding. User code
+ * should only need to create one of these if they are only accessing CRT:: static functions.
+ */
+final class CRT {
+
+ private static $impl = null;
+ private static $refcount = 0;
+
+ function __construct() {
+ if (is_null(self::$impl)) {
+ try {
+ self::$impl = new Extension();
+ } catch (RuntimeException $rex) {
+ throw new RuntimeException("Unable to initialize AWS CRT via awscrt extension: \n$rex", -1);
+ }
+ }
+ ++self::$refcount;
+ }
+
+ function __destruct() {
+ if (--self::$refcount == 0) {
+ self::$impl = null;
+ }
+ }
+
+ /**
+ * @return bool whether or not the CRT is currently loaded
+ */
+ public static function isLoaded() {
+ return !is_null(self::$impl);
+ }
+
+ /**
+ * @return bool whether or not the CRT is available via one of the possible backends
+ */
+ public static function isAvailable() {
+ try {
+ new CRT();
+ return true;
+ } catch (RuntimeException $ex) {
+ return false;
+ }
+ }
+
+ /**
+ * @return integer last error code reported within the CRT
+ */
+ public static function last_error() {
+ return self::$impl->aws_crt_last_error();
+ }
+
+ /**
+ * @param integer $error Error code from the CRT, usually delivered via callback or {@see last_error}
+ * @return string Human-readable description of the provided error code
+ */
+ public static function error_str($error) {
+ return self::$impl->aws_crt_error_str((int) $error);
+ }
+
+ /**
+ * @param integer $error Error code from the CRT, usually delivered via callback or {@see last_error}
+ * @return string Name/enum identifier for the provided error code
+ */
+ public static function error_name($error) {
+ return self::$impl->aws_crt_error_name((int) $error);
+ }
+
+ public static function log_to_stdout() {
+ return self::$impl->aws_crt_log_to_stdout();
+ }
+
+ public static function log_to_stderr() {
+ return self::$impl->aws_crt_log_to_stderr();
+ }
+
+ public static function log_to_file($filename) {
+ return self::$impl->aws_crt_log_to_file($filename);
+ }
+
+ public static function log_to_stream($stream) {
+ return self::$impl->aws_crt_log_to_stream($stream);
+ }
+
+ public static function log_set_level($level) {
+ return self::$impl->aws_crt_log_set_level($level);
+ }
+
+ public static function log_stop() {
+ return self::$impl->aws_crt_log_stop();
+ }
+
+ public static function log_message($level, $message) {
+ return self::$impl->aws_crt_log_message($level, $message);
+ }
+
+ /**
+ * @return object Pointer to native event_loop_group_options
+ */
+ function event_loop_group_options_new() {
+ return self::$impl->aws_crt_event_loop_group_options_new();
+ }
+
+ /**
+ * @param object $elg_options Pointer to native event_loop_group_options
+ */
+ function event_loop_group_options_release($elg_options) {
+ self::$impl->aws_crt_event_loop_group_options_release($elg_options);
+ }
+
+ /**
+ * @param object $elg_options Pointer to native event_loop_group_options
+ * @param integer $max_threads Maximum number of threads to allow the event loop group to use, default: 0/1 per CPU core
+ */
+ function event_loop_group_options_set_max_threads($elg_options, $max_threads) {
+ self::$impl->aws_crt_event_loop_group_options_set_max_threads($elg_options, (int)$max_threads);
+ }
+
+ /**
+ * @param object Pointer to event_loop_group_options, {@see event_loop_group_options_new}
+ * @return object Pointer to the new event loop group
+ */
+ function event_loop_group_new($options) {
+ return self::$impl->aws_crt_event_loop_group_new($options);
+ }
+
+ /**
+ * @param object $elg Pointer to the event loop group to release
+ */
+ function event_loop_group_release($elg) {
+ self::$impl->aws_crt_event_loop_group_release($elg);
+ }
+
+ /**
+ * return object Pointer to native AWS credentials options
+ */
+ function aws_credentials_options_new() {
+ return self::$impl->aws_crt_credentials_options_new();
+ }
+
+ function aws_credentials_options_release($options) {
+ self::$impl->aws_crt_credentials_options_release($options);
+ }
+
+ function aws_credentials_options_set_access_key_id($options, $access_key_id) {
+ self::$impl->aws_crt_credentials_options_set_access_key_id($options, $access_key_id);
+ }
+
+ function aws_credentials_options_set_secret_access_key($options, $secret_access_key) {
+ self::$impl->aws_crt_credentials_options_set_secret_access_key($options, $secret_access_key);
+ }
+
+ function aws_credentials_options_set_session_token($options, $session_token) {
+ self::$impl->aws_crt_credentials_options_set_session_token($options, $session_token);
+ }
+
+ function aws_credentials_options_set_expiration_timepoint_seconds($options, $expiration_timepoint_seconds) {
+ self::$impl->aws_crt_credentials_options_set_expiration_timepoint_seconds($options, $expiration_timepoint_seconds);
+ }
+
+ function aws_credentials_new($options) {
+ return self::$impl->aws_crt_credentials_new($options);
+ }
+
+ function aws_credentials_release($credentials) {
+ self::$impl->aws_crt_credentials_release($credentials);
+ }
+
+ function credentials_provider_release($provider) {
+ self::$impl->aws_crt_credentials_provider_release($provider);
+ }
+
+ function credentials_provider_static_options_new() {
+ return self::$impl->aws_crt_credentials_provider_static_options_new();
+ }
+
+ function credentials_provider_static_options_release($options) {
+ self::$impl->aws_crt_credentials_provider_static_options_release($options);
+ }
+
+ function credentials_provider_static_options_set_access_key_id($options, $access_key_id) {
+ self::$impl->aws_crt_credentials_provider_static_options_set_access_key_id($options, $access_key_id);
+ }
+
+ function credentials_provider_static_options_set_secret_access_key($options, $secret_access_key) {
+ self::$impl->aws_crt_credentials_provider_static_options_set_secret_access_key($options, $secret_access_key);
+ }
+
+ function credentials_provider_static_options_set_session_token($options, $session_token) {
+ self::$impl->aws_crt_credentials_provider_static_options_set_session_token($options, $session_token);
+ }
+
+ function credentials_provider_static_new($options) {
+ return self::$impl->aws_crt_credentials_provider_static_new($options);
+ }
+
+ function input_stream_options_new() {
+ return self::$impl->aws_crt_input_stream_options_new();
+ }
+
+ function input_stream_options_release($options) {
+ self::$impl->aws_crt_input_stream_options_release($options);
+ }
+
+ function input_stream_options_set_user_data($options, $user_data) {
+ self::$impl->aws_crt_input_stream_options_set_user_data($options, $user_data);
+ }
+
+ function input_stream_new($options) {
+ return self::$impl->aws_crt_input_stream_new($options);
+ }
+
+ function input_stream_release($stream) {
+ self::$impl->aws_crt_input_stream_release($stream);
+ }
+
+ function input_stream_seek($stream, $offset, $basis) {
+ return self::$impl->aws_crt_input_stream_seek($stream, $offset, $basis);
+ }
+
+ function input_stream_read($stream, $length) {
+ return self::$impl->aws_crt_input_stream_read($stream, $length);
+ }
+
+ function input_stream_eof($stream) {
+ return self::$impl->aws_crt_input_stream_eof($stream);
+ }
+
+ function input_stream_get_length($stream) {
+ return self::$impl->aws_crt_input_stream_get_length($stream);
+ }
+
+ function http_message_new_from_blob($blob) {
+ return self::$impl->aws_crt_http_message_new_from_blob($blob);
+ }
+
+ function http_message_to_blob($message) {
+ return self::$impl->aws_crt_http_message_to_blob($message);
+ }
+
+ function http_message_release($message) {
+ self::$impl->aws_crt_http_message_release($message);
+ }
+
+ function signing_config_aws_new() {
+ return self::$impl->aws_crt_signing_config_aws_new();
+ }
+
+ function signing_config_aws_release($signing_config) {
+ return self::$impl->aws_crt_signing_config_aws_release($signing_config);
+ }
+
+ function signing_config_aws_set_algorithm($signing_config, $algorithm) {
+ self::$impl->aws_crt_signing_config_aws_set_algorithm($signing_config, (int)$algorithm);
+ }
+
+ function signing_config_aws_set_signature_type($signing_config, $signature_type) {
+ self::$impl->aws_crt_signing_config_aws_set_signature_type($signing_config, (int)$signature_type);
+ }
+
+ function signing_config_aws_set_credentials_provider($signing_config, $credentials_provider) {
+ self::$impl->aws_crt_signing_config_aws_set_credentials_provider($signing_config, $credentials_provider);
+ }
+
+ function signing_config_aws_set_region($signing_config, $region) {
+ self::$impl->aws_crt_signing_config_aws_set_region($signing_config, $region);
+ }
+
+ function signing_config_aws_set_service($signing_config, $service) {
+ self::$impl->aws_crt_signing_config_aws_set_service($signing_config, $service);
+ }
+
+ function signing_config_aws_set_use_double_uri_encode($signing_config, $use_double_uri_encode) {
+ self::$impl->aws_crt_signing_config_aws_set_use_double_uri_encode($signing_config, $use_double_uri_encode);
+ }
+
+ function signing_config_aws_set_should_normalize_uri_path($signing_config, $should_normalize_uri_path) {
+ self::$impl->aws_crt_signing_config_aws_set_should_normalize_uri_path($signing_config, $should_normalize_uri_path);
+ }
+
+ function signing_config_aws_set_omit_session_token($signing_config, $omit_session_token) {
+ self::$impl->aws_crt_signing_config_aws_set_omit_session_token($signing_config, $omit_session_token);
+ }
+
+ function signing_config_aws_set_signed_body_value($signing_config, $signed_body_value) {
+ self::$impl->aws_crt_signing_config_aws_set_signed_body_value($signing_config, $signed_body_value);
+ }
+
+ function signing_config_aws_set_signed_body_header_type($signing_config, $signed_body_header_type) {
+ self::$impl->aws_crt_signing_config_aws_set_signed_body_header_type($signing_config, $signed_body_header_type);
+ }
+
+ function signing_config_aws_set_expiration_in_seconds($signing_config, $expiration_in_seconds) {
+ self::$impl->aws_crt_signing_config_aws_set_expiration_in_seconds($signing_config, $expiration_in_seconds);
+ }
+
+ function signing_config_aws_set_date($signing_config, $timestamp) {
+ self::$impl->aws_crt_signing_config_aws_set_date($signing_config, $timestamp);
+ }
+
+ function signing_config_aws_set_should_sign_header_fn($signing_config, $should_sign_header_fn) {
+ self::$impl->aws_crt_signing_config_aws_set_should_sign_header_fn($signing_config, $should_sign_header_fn);
+ }
+
+ function signable_new_from_http_request($http_message) {
+ return self::$impl->aws_crt_signable_new_from_http_request($http_message);
+ }
+
+ function signable_new_from_chunk($chunk_stream, $previous_signature) {
+ return self::$impl->aws_crt_signable_new_from_chunk($chunk_stream, $previous_signature);
+ }
+
+ function signable_new_from_canonical_request($canonical_request) {
+ return self::$impl->aws_crt_signable_new_from_canonical_request($canonical_request);
+ }
+
+ function signable_release($signable) {
+ self::$impl->aws_crt_signable_release($signable);
+ }
+
+ function signing_result_release($signing_result) {
+ self::$impl->aws_crt_signing_result_release($signing_result);
+ }
+
+ function signing_result_apply_to_http_request($signing_result, $http_message) {
+ return self::$impl->aws_crt_signing_result_apply_to_http_request(
+ $signing_result, $http_message);
+ }
+
+ function sign_request_aws($signable, $signing_config, $on_complete, $user_data) {
+ return self::$impl->aws_crt_sign_request_aws($signable, $signing_config, $on_complete, $user_data);
+ }
+
+ function test_verify_sigv4a_signing($signable, $signing_config, $expected_canonical_request, $signature, $ecc_key_pub_x, $ecc_key_pub_y) {
+ return self::$impl->aws_crt_test_verify_sigv4a_signing($signable, $signing_config, $expected_canonical_request, $signature, $ecc_key_pub_x, $ecc_key_pub_y);
+ }
+
+ public static function crc32($input, $previous = 0) {
+ return self::$impl->aws_crt_crc32($input, $previous);
+ }
+
+ public static function crc32c($input, $previous = 0) {
+ return self::$impl->aws_crt_crc32c($input, $previous);
+ }
+}
diff --git a/vendor/aws/aws-crt-php/src/AWS/CRT/HTTP/Headers.php b/vendor/aws/aws-crt-php/src/AWS/CRT/HTTP/Headers.php
new file mode 100644
index 0000000..8d1457c
--- /dev/null
+++ b/vendor/aws/aws-crt-php/src/AWS/CRT/HTTP/Headers.php
@@ -0,0 +1,50 @@
+<?php
+/**
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0.
+ */
+namespace AWS\CRT\HTTP;
+
+use AWS\CRT\Internal\Encoding;
+
+final class Headers {
+ private $headers;
+
+ public function __construct($headers = []) {
+ $this->headers = $headers;
+ }
+
+ public static function marshall($headers) {
+ $buf = "";
+ foreach ($headers->headers as $header => $value) {
+ $buf .= Encoding::encodeString($header);
+ $buf .= Encoding::encodeString($value);
+ }
+ return $buf;
+ }
+
+ public static function unmarshall($buf) {
+ $strings = Encoding::readStrings($buf);
+ $headers = [];
+ for ($idx = 0; $idx < count($strings);) {
+ $headers[$strings[$idx++]] = $strings[$idx++];
+ }
+ return new Headers($headers);
+ }
+
+ public function count() {
+ return count($this->headers);
+ }
+
+ public function get($header) {
+ return isset($this->headers[$header]) ? $this->headers[$header] : null;
+ }
+
+ public function set($header, $value) {
+ $this->headers[$header] = $value;
+ }
+
+ public function toArray() {
+ return $this->headers;
+ }
+}
diff --git a/vendor/aws/aws-crt-php/src/AWS/CRT/HTTP/Message.php b/vendor/aws/aws-crt-php/src/AWS/CRT/HTTP/Message.php
new file mode 100644
index 0000000..a8c151f
--- /dev/null
+++ b/vendor/aws/aws-crt-php/src/AWS/CRT/HTTP/Message.php
@@ -0,0 +1,95 @@
+<?php
+/**
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0.
+ */
+namespace AWS\CRT\HTTP;
+
+use AWS\CRT\NativeResource;
+use AWS\CRT\Internal\Encoding;
+
+abstract class Message extends NativeResource {
+ private $method;
+ private $path;
+ private $query;
+ private $headers;
+
+ public function __construct($method, $path, $query = [], $headers = []) {
+ parent::__construct();
+ $this->method = $method;
+ $this->path = $path;
+ $this->query = $query;
+ $this->headers = new Headers($headers);
+ $this->acquire(self::$crt->http_message_new_from_blob(self::marshall($this)));
+ }
+
+ public function __destruct() {
+ self::$crt->http_message_release($this->release());
+ parent::__destruct();
+ }
+
+ public function toBlob() {
+ return self::$crt->http_message_to_blob($this->native);
+ }
+
+ protected static function marshall($msg) {
+ $buf = "";
+ $buf .= Encoding::encodeString($msg->method);
+ $buf .= Encoding::encodeString($msg->pathAndQuery());
+ $buf .= Headers::marshall($msg->headers);
+ return $buf;
+ }
+
+ protected static function _unmarshall($buf, $class=Message::class) {
+ $method = Encoding::readString($buf);
+ $path_and_query = Encoding::readString($buf);
+ $parts = explode("?", $path_and_query, 2);
+ $path = isset($parts[0]) ? $parts[0] : "";
+ $query = isset($parts[1]) ? $parts[1] : "";
+ $headers = Headers::unmarshall($buf);
+
+ // Turn query params back into a dictionary
+ if (strlen($query)) {
+ $query = rawurldecode($query);
+ $query = explode("&", $query);
+ $query = array_reduce($query, function($params, $pair) {
+ list($param, $value) = explode("=", $pair, 2);
+ $params[$param] = $value;
+ return $params;
+ }, []);
+ } else {
+ $query = [];
+ }
+
+ return new $class($method, $path, $query, $headers->toArray());
+ }
+
+ public function pathAndQuery() {
+ $path = $this->path;
+ $queries = [];
+ foreach ($this->query as $param => $value) {
+ $queries []= urlencode($param) . "=" . urlencode($value);
+ }
+ $query = implode("&", $queries);
+ if (strlen($query)) {
+ $path = implode("?", [$path, $query]);
+ }
+ return $path;
+ }
+
+ public function method() {
+ return $this->method;
+ }
+
+ public function path() {
+ return $this->path;
+ }
+
+ public function query() {
+ return $this->query;
+ }
+
+ public function headers() {
+ return $this->headers;
+ }
+}
diff --git a/vendor/aws/aws-crt-php/src/AWS/CRT/HTTP/Request.php b/vendor/aws/aws-crt-php/src/AWS/CRT/HTTP/Request.php
new file mode 100644
index 0000000..9b4f07c
--- /dev/null
+++ b/vendor/aws/aws-crt-php/src/AWS/CRT/HTTP/Request.php
@@ -0,0 +1,32 @@
+<?php
+/**
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0.
+ */
+namespace AWS\CRT\HTTP;
+
+use AWS\CRT\IO\InputStream;
+
+class Request extends Message {
+ private $body_stream = null;
+
+ public function __construct($method, $path, $query = [], $headers = [], $body_stream = null) {
+ parent::__construct($method, $path, $query, $headers);
+ if (!is_null($body_stream) && !($body_stream instanceof InputStream)) {
+ throw InvalidArgumentException('body_stream must be an instance of ' . InputStream::class);
+ }
+ $this->body_stream = $body_stream;
+ }
+
+ public static function marshall($request) {
+ return parent::marshall($request);
+ }
+
+ public static function unmarshall($buf) {
+ return parent::_unmarshall($buf, Request::class);
+ }
+
+ public function body_stream() {
+ return $this->body_stream;
+ }
+}
diff --git a/vendor/aws/aws-crt-php/src/AWS/CRT/HTTP/Response.php b/vendor/aws/aws-crt-php/src/AWS/CRT/HTTP/Response.php
new file mode 100644
index 0000000..526edc3
--- /dev/null
+++ b/vendor/aws/aws-crt-php/src/AWS/CRT/HTTP/Response.php
@@ -0,0 +1,27 @@
+<?php
+/**
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0.
+ */
+namespace AWS\CRT\HTTP;
+
+class Response extends Message {
+ private $status_code;
+
+ public function __construct($method, $path, $query, $headers, $status_code) {
+ parent::__construct($method, $path, $query, $headers);
+ $this->status_code = $status_code;
+ }
+
+ public static function marshall($response) {
+ return parent::marshall($response);
+ }
+
+ public static function unmarshall($buf) {
+ return parent::_unmarshall($buf, Response::class);
+ }
+
+ public function status_code() {
+ return $this->status_code;
+ }
+}
diff --git a/vendor/aws/aws-crt-php/src/AWS/CRT/IO/EventLoopGroup.php b/vendor/aws/aws-crt-php/src/AWS/CRT/IO/EventLoopGroup.php
new file mode 100644
index 0000000..7e989e7
--- /dev/null
+++ b/vendor/aws/aws-crt-php/src/AWS/CRT/IO/EventLoopGroup.php
@@ -0,0 +1,39 @@
+<?php
+/**
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0.
+ */
+namespace AWS\CRT\IO;
+
+use AWS\CRT\NativeResource as NativeResource;
+use AWS\CRT\Options as Options;
+
+/**
+ * Represents 1 or more event loops (1 per thread) for doing I/O and background tasks.
+ * Typically, every application has one EventLoopGroup.
+ *
+ * @param array options:
+ * - int num_threads - Number of worker threads in the EventLoopGroup. Defaults to 0/1 per logical core.
+ */
+final class EventLoopGroup extends NativeResource {
+
+ static function defaults() {
+ return [
+ 'max_threads' => 0,
+ ];
+ }
+
+ function __construct(array $options = []) {
+ parent::__construct();
+ $options = new Options($options, self::defaults());
+ $elg_options = self::$crt->event_loop_group_options_new();
+ self::$crt->event_loop_group_options_set_max_threads($elg_options, $options->getInt('max_threads'));
+ $this->acquire(self::$crt->event_loop_group_new($elg_options));
+ self::$crt->event_loop_group_options_release($elg_options);
+ }
+
+ function __destruct() {
+ self::$crt->event_loop_group_release($this->release());
+ parent::__destruct();
+ }
+}
diff --git a/vendor/aws/aws-crt-php/src/AWS/CRT/IO/InputStream.php b/vendor/aws/aws-crt-php/src/AWS/CRT/IO/InputStream.php
new file mode 100644
index 0000000..ae5fd46
--- /dev/null
+++ b/vendor/aws/aws-crt-php/src/AWS/CRT/IO/InputStream.php
@@ -0,0 +1,49 @@
+<?php
+/**
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0.
+ */
+namespace AWS\CRT\IO;
+
+use AWS\CRT\NativeResource as NativeResource;
+
+final class InputStream extends NativeResource {
+ private $stream = null;
+
+ const SEEK_BEGIN = 0;
+ const SEEK_END = 2;
+
+ public function __construct($stream) {
+ $this->stream = $stream;
+ $options = self::$crt->input_stream_options_new();
+ // The stream implementation in native just converts the PHP stream into
+ // a native php_stream* and executes operations entirely in native
+ self::$crt->input_stream_options_set_user_data($options, $stream);
+ $this->acquire(self::$crt->input_stream_new($options));
+ self::$crt->input_stream_options_release($options);
+ }
+
+ public function __destruct() {
+ self::$crt->input_stream_release($this->release());
+ parent::__destruct();
+ }
+
+ public function eof() {
+ return self::$crt->input_stream_eof($this->native);
+ }
+
+ public function length() {
+ return self::$crt->input_stream_get_length($this->native);
+ }
+
+ public function read($length = 0) {
+ if ($length == 0) {
+ $length = $this->length();
+ }
+ return self::$crt->input_stream_read($this->native, $length);
+ }
+
+ public function seek($offset, $basis) {
+ return self::$crt->input_stream_seek($this->native, $offset, $basis);
+ }
+}
diff --git a/vendor/aws/aws-crt-php/src/AWS/CRT/Internal/Encoding.php b/vendor/aws/aws-crt-php/src/AWS/CRT/Internal/Encoding.php
new file mode 100644
index 0000000..75446fc
--- /dev/null
+++ b/vendor/aws/aws-crt-php/src/AWS/CRT/Internal/Encoding.php
@@ -0,0 +1,37 @@
+<?php
+/**
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0.
+ */
+namespace AWS\CRT\Internal;
+
+final class Encoding {
+ public static function readString(&$buffer) {
+ list($len, $str) = self::decodeString($buffer);
+ // Advance by sizeof(length) + strlen(str)
+ $buffer = substr($buffer, 4 + $len);
+ return $str;
+ }
+
+ public static function readStrings($buffer) {
+ $strings = [];
+ while (strlen($buffer)) {
+ $strings []= self::readString($buffer);
+ }
+ return $strings;
+ }
+
+ public static function decodeString($buffer) {
+ $len = unpack("N", $buffer)[1];
+ $buffer = substr($buffer, 4);
+ $str = unpack("a${len}", $buffer)[1];
+ return [$len, $str];
+ }
+
+ public static function encodeString($str) {
+ if (is_array($str)) {
+ $str = $str[0];
+ }
+ return pack("Na*", strlen($str), $str);
+ }
+}
diff --git a/vendor/aws/aws-crt-php/src/AWS/CRT/Internal/Extension.php b/vendor/aws/aws-crt-php/src/AWS/CRT/Internal/Extension.php
new file mode 100644
index 0000000..7801788
--- /dev/null
+++ b/vendor/aws/aws-crt-php/src/AWS/CRT/Internal/Extension.php
@@ -0,0 +1,29 @@
+<?php
+/**
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0.
+ */
+namespace AWS\CRT\Internal;
+
+use \RuntimeException;
+
+/**
+ * @internal
+ * Forwards calls on to awscrt PHP extension functions
+ */
+final class Extension {
+ function __construct() {
+ if (!extension_loaded('awscrt')) {
+ throw new RuntimeException('awscrt extension is not loaded');
+ }
+ }
+
+ /**
+ * Forwards any call made on this object to the extension function of the
+ * same name with the supplied arguments. Argument type hinting and checking
+ * occurs at the CRT wrapper.
+ */
+ function __call($name, $args) {
+ return call_user_func_array($name, $args);
+ }
+}
diff --git a/vendor/aws/aws-crt-php/src/AWS/CRT/Log.php b/vendor/aws/aws-crt-php/src/AWS/CRT/Log.php
new file mode 100644
index 0000000..de042f3
--- /dev/null
+++ b/vendor/aws/aws-crt-php/src/AWS/CRT/Log.php
@@ -0,0 +1,47 @@
+<?php
+/**
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0.
+ */
+namespace AWS\CRT;
+use AWS\CRT\CRT;
+
+final class Log {
+ const NONE = 0;
+ const FATAL = 1;
+ const ERROR = 2;
+ const WARN = 3;
+ const INFO = 4;
+ const DEBUG = 5;
+ const TRACE = 6;
+
+ public static function toStdout() {
+ CRT::log_to_stdout();
+ }
+
+ public static function toStderr() {
+ CRT::log_to_stderr();
+ }
+
+ public static function toFile($filename) {
+ CRT::log_to_file($filename);
+ }
+
+ public static function toStream($stream) {
+ assert(get_resource_type($stream) == "stream");
+ CRT::log_to_stream($stream);
+ }
+
+ public static function stop() {
+ CRT::log_stop();
+ }
+
+ public static function setLogLevel($level) {
+ assert($level >= self::NONE && $level <= self::TRACE);
+ CRT::log_set_level($level);
+ }
+
+ public static function log($level, $message) {
+ CRT::log_message($level, $message);
+ }
+}
diff --git a/vendor/aws/aws-crt-php/src/AWS/CRT/NativeResource.php b/vendor/aws/aws-crt-php/src/AWS/CRT/NativeResource.php
new file mode 100644
index 0000000..528df75
--- /dev/null
+++ b/vendor/aws/aws-crt-php/src/AWS/CRT/NativeResource.php
@@ -0,0 +1,42 @@
+<?php
+/**
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0.
+ */
+namespace AWS\CRT;
+
+use AWS\CRT\CRT as CRT;
+
+/**
+ * Base class for all native resources, tracks all outstanding resources
+ * and provides basic leak checking
+ */
+abstract class NativeResource {
+ protected static $crt = null;
+ protected static $resources = [];
+ protected $native = null;
+
+ protected function __construct() {
+ if (is_null(self::$crt)) {
+ self::$crt = new CRT();
+ }
+
+ self::$resources[spl_object_hash($this)] = 1;
+ }
+
+ protected function acquire($handle) {
+ return $this->native = $handle;
+ }
+
+ protected function release() {
+ $native = $this->native;
+ $this->native = null;
+ return $native;
+ }
+
+ function __destruct() {
+ // Should have been destroyed and released by derived resource
+ assert($this->native == null);
+ unset(self::$resources[spl_object_hash($this)]);
+ }
+}
diff --git a/vendor/aws/aws-crt-php/src/AWS/CRT/Options.php b/vendor/aws/aws-crt-php/src/AWS/CRT/Options.php
new file mode 100644
index 0000000..363a396
--- /dev/null
+++ b/vendor/aws/aws-crt-php/src/AWS/CRT/Options.php
@@ -0,0 +1,77 @@
+<?php
+/**
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0.
+ */
+namespace AWS\CRT;
+
+final class OptionValue {
+ private $value;
+ function __construct($value) {
+ $this->value = $value;
+ }
+
+ public function asObject() {
+ return $this->value;
+ }
+
+ public function asMixed() {
+ return $this->value;
+ }
+
+ public function asInt() {
+ return empty($this->value) ? 0 : (int)$this->value;
+ }
+
+ public function asBool() {
+ return boolval($this->value);
+ }
+
+ public function asString() {
+ return !empty($this->value) ? strval($this->value) : "";
+ }
+
+ public function asArray() {
+ return is_array($this->value) ? $this->value : (!empty($this->value) ? [$this->value] : []);
+ }
+
+ public function asCallable() {
+ return is_callable($this->value) ? $this->value : null;
+ }
+}
+
+final class Options {
+ private $options;
+
+ public function __construct($opts = [], $defaults = []) {
+ $this->options = array_replace($defaults, empty($opts) ? [] : $opts);
+ }
+
+ public function __get($name) {
+ return $this->get($name);
+ }
+
+ public function asArray() {
+ return $this->options;
+ }
+
+ public function toArray() {
+ return array_merge_recursive([], $this->options);
+ }
+
+ public function get($name) {
+ return new OptionValue($this->options[$name]);
+ }
+
+ public function getInt($name) {
+ return $this->get($name)->asInt();
+ }
+
+ public function getString($name) {
+ return $this->get($name)->asString();
+ }
+
+ public function getBool($name) {
+ return $this->get($name)->asBool();
+ }
+}