diff --git a/src/Services/Client.php b/src/Services/Client.php new file mode 100644 index 0000000..2f3f7ed --- /dev/null +++ b/src/Services/Client.php @@ -0,0 +1,72 @@ + + */ + private static array $defaultOptions = [ + RequestOptions::STREAM => true, + RequestOptions::HEADERS => [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + ], + ]; + + /** + * The custom options. + */ + private static array $options = []; + + /** + * The Guzzle client instance. + */ + private static ?Guzzle $guzzle = null; + + /** + * Instantiate the class. + */ + private function __construct() + { + // disable the constructor + } + + /** + * Set the Guzzle client options. + */ + public static function configure(array $options): void + { + self::$options = array_replace_recursive(self::$options, $options); + } + + /** + * Retrieve the Guzzle client instance. + */ + public static function instance(): Guzzle + { + return self::$guzzle ??= new Guzzle( + array_replace_recursive(self::$defaultOptions, self::$options), + ); + } + + /** + * Clean up the static values. + */ + public static function reset(): void + { + self::$guzzle = null; + self::$options = []; + } +}