From d2a15a7bf4056e6249081dfcfaf4d76b4bda6e89 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 14 Jul 2020 15:09:11 +0200 Subject: [PATCH] Add HttpFactory --- .../files/lib/system/io/HttpFactory.class.php | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 wcfsetup/install/files/lib/system/io/HttpFactory.class.php diff --git a/wcfsetup/install/files/lib/system/io/HttpFactory.class.php b/wcfsetup/install/files/lib/system/io/HttpFactory.class.php new file mode 100644 index 0000000000..98b13efdcb --- /dev/null +++ b/wcfsetup/install/files/lib/system/io/HttpFactory.class.php @@ -0,0 +1,52 @@ + + * @package WoltLabSuite\Core\System\Io + * @since 5.3 + */ +final class HttpFactory { + /** + * @var Client + */ + private $defaultClient; + + /** + * Returns a reference to the default HTTP client. + * + * @return ClientInterface + */ + public static function getDefaultClient() { + if (self::$defaultClient === null) { + self::$defaultClient = static::makeClient(); + } + + return self::$defaultClient; + } + + /** + * Creates a new HTTP client. + * + * The HTTP proxy will automatically be enabled, unless + * specifically removed by passing appropriate options. + * + * @return ClientInterface + * @see Client + */ + public static function makeClient(array $options = []) { + return new Client(array_merge([ + 'proxy' => PROXY_SERVER_HTTP, + ], $options)); + } +} -- 2.20.1