From 1eef2f9740964eb274d2f4ea02cdad055e3de271 Mon Sep 17 00:00:00 2001 From: Taras Sharkadi Date: Mon, 6 Dec 2021 12:45:57 +0200 Subject: [PATCH 1/2] Implement connection interface --- src/Bigcommerce/Api/Client.php | 4 +- src/Bigcommerce/Api/Connection.php | 2 +- src/Bigcommerce/Api/ConnectionInterface.php | 119 ++++++++++++++++++++ 3 files changed, 122 insertions(+), 3 deletions(-) create mode 100644 src/Bigcommerce/Api/ConnectionInterface.php diff --git a/src/Bigcommerce/Api/Client.php b/src/Bigcommerce/Api/Client.php index 00eb60fa..a31a0487 100644 --- a/src/Bigcommerce/Api/Client.php +++ b/src/Bigcommerce/Api/Client.php @@ -242,9 +242,9 @@ public static function getConnection() /** * Set the HTTP connection object. DANGER: This can screw up your Client! * - * @param Connection $connection The connection to use + * @param ConnectionInterface $connection The connection to use */ - public static function setConnection(Connection $connection = null) + public static function setConnection(ConnectionInterface $connection = null) { self::$connection = $connection; } diff --git a/src/Bigcommerce/Api/Connection.php b/src/Bigcommerce/Api/Connection.php index c333d677..08b5eada 100644 --- a/src/Bigcommerce/Api/Connection.php +++ b/src/Bigcommerce/Api/Connection.php @@ -5,7 +5,7 @@ /** * HTTP connection. */ -class Connection +class Connection implements ConnectionInterface { /** * XML media type. diff --git a/src/Bigcommerce/Api/ConnectionInterface.php b/src/Bigcommerce/Api/ConnectionInterface.php new file mode 100644 index 00000000..add80b8a --- /dev/null +++ b/src/Bigcommerce/Api/ConnectionInterface.php @@ -0,0 +1,119 @@ +An error condition is considered to be:

+ * + * + * + *

Note that this doesn't use the builtin CURL_FAILONERROR option, + * as this fails fast, making the HTTP body and headers inaccessible.

+ * + * @param bool $option the new state of this feature + */ + public function failOnError($option); + + /** + * Controls whether requests and responses should be treated + * as XML. Defaults to false (using JSON). + * + * @param bool $option the new state of this feature + */ + public function useXml($option); + + /** + * @param boolean + */ + public function verifyPeer($option); + + /** + * Add a custom header to the request. + * + * @param string $header + * @param string $value + */ + public function addHeader($header, $value); + + /** + * Remove a header from the request. + * + * @param string $header + */ + public function removeHeader($header); + + /** + * Return an representation of an error returned by the last request, or false + * if the last request was not an error. + */ + public function getLastError(); + + /** + * Make an HTTP GET request to the specified endpoint. + * + * @param string $url URL to retrieve + * @param array|bool $query Optional array of query string parameters + * + * @return mixed + */ + public function get($url, $query); + + /** + * Make an HTTP POST request to the specified endpoint. + * + * @param string $url URL to which we send the request + * @param mixed $body Data payload (JSON string or raw data) + * + * @return mixed + */ + public function post($url, $body); + + /** + * Make an HTTP HEAD request to the specified endpoint. + * + * @param string $url URL to which we send the request + * @return mixed + */ + public function head($url); + + /** + * Make an HTTP PUT request to the specified endpoint. + * + * Requires a tmpfile() handle to be opened on the system, as the cURL + * API requires it to send data. + * + * @param string $url URL to which we send the request + * @param mixed $body Data payload (JSON string or raw data) + * @return mixed + */ + public function put($url, $body); + + /** + * Make an HTTP DELETE request to the specified endpoint. + * + * @param string $url URL to which we send the request + * @return mixed + */ + public function delete($url); + + /** + * Access given header from the response. + * + * @param string $header Header name to retrieve + * + * @return string|void + */ + public function getHeader($header); + + /** + * Return the full list of response headers + */ + public function getHeaders(); +} \ No newline at end of file From 2dee0e2a0be74b2d71b2a0bcff2b27711af2376d Mon Sep 17 00:00:00 2001 From: Taras Sharkadi Date: Mon, 6 Dec 2021 13:00:13 +0200 Subject: [PATCH 2/2] Add newline --- src/Bigcommerce/Api/ConnectionInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bigcommerce/Api/ConnectionInterface.php b/src/Bigcommerce/Api/ConnectionInterface.php index add80b8a..dfaa2e02 100644 --- a/src/Bigcommerce/Api/ConnectionInterface.php +++ b/src/Bigcommerce/Api/ConnectionInterface.php @@ -116,4 +116,4 @@ public function getHeader($header); * Return the full list of response headers */ public function getHeaders(); -} \ No newline at end of file +}