Skip to content

Commit

Permalink
Requests_Transport: change to namespaced interface
Browse files Browse the repository at this point in the history
Includes:
* Moving the namespaced version of the interface to the `src` directory.
* [Custom autoload] Adding the interface to the `$deprecated_classes` array in the `WpOrg\Requests\Autoload` class.
* [Composer autoload] Adding the interface to the `Deprecated.php` file.
* Updating all references to the interface.
  • Loading branch information
jrfnl committed Sep 17, 2021
1 parent 77f194e commit 94fad44
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 15 deletions.
1 change: 1 addition & 0 deletions library/Deprecated.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@
interface Requests_Auth extends WpOrg\Requests\Auth {}
interface Requests_Hooker extends WpOrg\Requests\Hooker {}
interface Requests_Proxy extends WpOrg\Requests\Proxy {}
interface Requests_Transport extends WpOrg\Requests\Transport {}
3 changes: 2 additions & 1 deletion library/Requests/Transport/cURL.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
*/

use WpOrg\Requests\Requests;
use WpOrg\Requests\Transport;

/**
* cURL HTTP transport
*
* @package Requests
* @subpackage Transport
*/
class Requests_Transport_cURL implements Requests_Transport {
class Requests_Transport_cURL implements Transport {
const CURL_7_10_5 = 0x070A05;
const CURL_7_16_2 = 0x071002;

Expand Down
5 changes: 3 additions & 2 deletions library/Requests/Transport/fsockopen.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
*/

use WpOrg\Requests\Requests;
use WpOrg\Requests\Transport;

/**
* fsockopen HTTP transport
*
* @package Requests
* @subpackage Transport
*/
class Requests_Transport_fsockopen implements Requests_Transport {
class Requests_Transport_fsockopen implements Transport {
/**
* Second to microsecond conversion
*
Expand Down Expand Up @@ -327,7 +328,7 @@ public function request($url, $headers = array(), $data = array(), $options = ar
/**
* Send multiple requests simultaneously
*
* @param array $requests Request data (array of 'url', 'headers', 'data', 'options') as per {@see Requests_Transport::request}
* @param array $requests Request data (array of 'url', 'headers', 'data', 'options') as per {@see \WpOrg\Requests\Transport::request}
* @param array $options Global options, see {@see \WpOrg\Requests\Requests::response()} for documentation
* @return array Array of Requests_Response objects (may contain Requests_Exception or string responses as well)
*/
Expand Down
7 changes: 4 additions & 3 deletions src/Autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ class Autoload {
*/
private static $deprecated_classes = array(
// Interfaces.
'requests_auth' => '\WpOrg\Requests\Auth',
'requests_hooker' => '\WpOrg\Requests\Hooker',
'requests_proxy' => '\WpOrg\Requests\Proxy',
'requests_auth' => '\WpOrg\Requests\Auth',
'requests_hooker' => '\WpOrg\Requests\Hooker',
'requests_proxy' => '\WpOrg\Requests\Proxy',
'requests_transport' => '\WpOrg\Requests\Transport',
);

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Requests.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private function __construct() {}
/**
* Register a transport
*
* @param string $transport Transport class to add, must support the Requests_Transport interface
* @param string $transport Transport class to add, must support the \WpOrg\Requests\Transport interface
*/
public static function add_transport($transport) {
if (empty(self::$transports)) {
Expand All @@ -156,7 +156,7 @@ public static function add_transport($transport) {
* Get a working transport
*
* @throws Requests_Exception If no valid transport is found (`notransport`)
* @return Requests_Transport
* @return \WpOrg\Requests\Transport
*/
protected static function get_transport($capabilities = array()) {
// Caching code, don't bother testing coverage
Expand Down Expand Up @@ -313,7 +313,7 @@ public static function patch($url, $headers, $data = array(), $options = array()
* - `transport`: Custom transport. Either a class name, or a
* transport object. Defaults to the first working transport from
* {@see getTransport()}
* (string|Requests_Transport, default: {@see getTransport()})
* (string|\WpOrg\Requests\Transport, default: {@see getTransport()})
* - `hooks`: Hooks handler.
* (\WpOrg\Requests\Hooker, default: new Requests_Hooks())
* - `verify`: Should we verify SSL certificates? Allows passing in a custom
Expand Down
6 changes: 4 additions & 2 deletions library/Requests/Transport.php → src/Transport.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
* @subpackage Transport
*/

namespace WpOrg\Requests;

/**
* Base HTTP transport
*
* @package Requests
* @subpackage Transport
*/
interface Requests_Transport {
interface Transport {
/**
* Perform a request
*
Expand All @@ -27,7 +29,7 @@ public function request($url, $headers = array(), $data = array(), $options = ar
/**
* Send multiple requests simultaneously
*
* @param array $requests Request data (array of 'url', 'headers', 'data', 'options') as per {@see Requests_Transport::request}
* @param array $requests Request data (array of 'url', 'headers', 'data', 'options') as per {@see \WpOrg\Requests\Transport::request}
* @param array $options Global options, see {@see \WpOrg\Requests\Requests::response()} for documentation
* @return array Array of Requests_Response objects (may contain Requests_Exception or string responses as well)
*/
Expand Down
4 changes: 2 additions & 2 deletions tests/Mock/RawTransportMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Requests\Tests\Mock;

use Requests_Transport;
use WpOrg\Requests\Transport;

class RawTransportMock implements Requests_Transport {
class RawTransportMock implements Transport {
public $data = '';
public function request($url, $headers = array(), $data = array(), $options = array()) {
return $this->data;
Expand Down
4 changes: 2 additions & 2 deletions tests/Mock/TransportMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Requests\Tests\Mock;

use Requests_Transport;
use WpOrg\Requests\Transport;

class TransportMock implements Requests_Transport {
class TransportMock implements Transport {
public $code = 200;
public $chunked = false;
public $body = 'Test Body';
Expand Down

0 comments on commit 94fad44

Please sign in to comment.