Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
ba894a4
PHPCS: few tweaks
jrfnl Aug 22, 2021
417c63d
Requests: move autoload functionality to separate class
jrfnl Aug 26, 2021
a382ab0
Update autoloading to allow for PSR-4 class names
jrfnl Aug 26, 2021
689c6f1
Requests: update all code samples using the custom autoloader
jrfnl Aug 23, 2021
15bd013
Tests: temporarily silence deprecation warnings
jrfnl Aug 13, 2021
9e4c7c5
Requests: move the real functionality to a namespaced Requests class
jrfnl Aug 13, 2021
b5b5c6d
Requests: update all references to the class
jrfnl Aug 26, 2021
a215268
Requests: deprecate the remaining class
jrfnl Aug 24, 2021
eb65203
Move certificates file to `src` directory
jrfnl Aug 22, 2021
3f213ae
Requests_Auth: change to namespaced interface
jrfnl Aug 13, 2021
b96313d
Requests_Hooker: change to namespaced interface
jrfnl Aug 13, 2021
77f194e
Requests_Proxy: change to namespaced interface
jrfnl Aug 13, 2021
94fad44
Requests_Transport: change to namespaced interface
jrfnl Aug 13, 2021
930e1d0
Requests_Cookie: change to namespaced class
jrfnl Aug 13, 2021
c198a68
Requests_Exception: change to namespaced class
jrfnl Aug 13, 2021
293ae01
Requests_Hooks: change to namespaced class
jrfnl Aug 13, 2021
db2619d
Requests_IDNAEncoder: change to namespaced class
jrfnl Aug 13, 2021
e34d7da
Requests_IPv6: change to namespaced class
jrfnl Aug 13, 2021
4a0fca6
Requests_IRI: change to namespaced class
jrfnl Aug 16, 2021
894c3d1
Requests_Response: change to namespaced class
jrfnl Aug 16, 2021
e06e605
Requests_Session: change to namespaced class
jrfnl Aug 16, 2021
bb5ea24
Requests_SSL: change to namespaced class
jrfnl Aug 16, 2021
53c9204
Requests_Auth_Basic: change to namespaced class
jrfnl Aug 16, 2021
d0b8c06
Requests_Cookie_Jar: change to namespaced class
jrfnl Aug 16, 2021
6b2d102
Requests_Proxy_HTTP: change to namespaced class
jrfnl Aug 16, 2021
e71c125
Requests_Response_Headers: change to namespaced class
jrfnl Aug 16, 2021
09becbc
Requests_Transport_cURL: change to namespaced class
jrfnl Aug 16, 2021
03ee83d
Requests_Transport_fsockopen: change to namespaced class
jrfnl Aug 16, 2021
5849311
Requests_Utility_CaseInsensitiveDictionary: change to namespaced class
jrfnl Aug 16, 2021
4006611
Requests_Utility_FilteredIterator: change to namespaced class
jrfnl Aug 16, 2021
b726ac6
Requests_Exception_HTTP: change to namespaced class
jrfnl Aug 18, 2021
d8eb589
Requests_Exception_InvalidArgument: change to namespaced class
jrfnl Aug 22, 2021
8225885
Requests_Exception_Transport: change to namespaced class
jrfnl Aug 19, 2021
c5479a2
Requests_Exception_Transport_cURL: change to namespaced class
jrfnl Aug 19, 2021
234e476
Requests_Exception_HTTP_*: change to namespaced classes
jrfnl Aug 19, 2021
7a2d2b3
Remove support for PSR-0 autoloading
jrfnl Aug 26, 2021
82c1cda
Tests: undo the temporarily silencing of deprecation warnings
jrfnl Aug 23, 2021
74fa786
Document the library directory
jrfnl Aug 22, 2021
8f8c4dc
Documentation: add page about upgrading to Requests 2.0
jrfnl Aug 23, 2021
6580293
Code coverage: update configuration
jrfnl Aug 27, 2021
449dfb1
README: update external class loader example code
jrfnl Aug 27, 2021
69494d1
Deprecated classes classmap file: wrap each class/interface declarati…
jrfnl Aug 30, 2021
aad891a
Tests: add minimal test to verify that deprecation notices are thrown
jrfnl Aug 30, 2021
84efc00
Tests: rename the namespace
jrfnl Sep 11, 2021
4e618f6
Deprecation notices: declare the constant if thrown
jrfnl Sep 17, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ coverage:
default:
threshold: 1%
paths:
- "library"
- "src"
patch:
default:
threshold: 3%
paths:
- "library"
- "src"

comment: false
4 changes: 2 additions & 2 deletions .github/release-checklist.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Template to use for release PRs from `develop` to `stable`

PR for tracking changes for the x.x.x release. Target release date: **DOW MONTH DAY YEAR**.
- [ ] Check if any dependencies need updating.
- [ ] Check if the `cacert.pem` file needs updating.
- [ ] Update the version constant in `library/Requests.php`.
- [ ] Check if the `src/Transports/cacert.pem` file needs updating.
- [ ] Update the version constant in `src/Requests.php`.
- [ ] Add changelog for the release - PR #xxx
- [ ] Merge this PR.
- [ ] Make sure all CI builds are green.
Expand Down
16 changes: 10 additions & 6 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<file>.</file>

<!-- Third party files and build files don't need to comply with these coding standards. -->
<exclude-pattern>*/library/Requests/IRI\.php$</exclude-pattern>
<exclude-pattern>*/tests/IRITest\.php$</exclude-pattern>
<exclude-pattern>*/src/Iri\.php$</exclude-pattern>
<exclude-pattern>*/tests/IriTest\.php$</exclude-pattern>
<exclude-pattern>*/vendor/*</exclude-pattern>
<exclude-pattern>*/tests/coverage/</exclude-pattern>

Expand Down Expand Up @@ -186,11 +186,12 @@
<properties>
<property name="prefixes" type="array">
<element value="Requests"/>
<element value="WpOrg\Requests"/>
</property>
</properties>

<!-- Only code within the actual distributed package needs to be prefixed. -->
<include-pattern>/library/*\.php$</include-pattern>
<exclude-pattern>*/examples/*\.php$</exclude-pattern>
<exclude-pattern>*/tests/bootstrap\.php$</exclude-pattern>
</rule>

<!-- Simplify alignment rules for multiline arrays. -->
Expand Down Expand Up @@ -219,8 +220,11 @@

<!-- Don't rename existing classes to prevent a BC break. -->
<rule ref="PEAR.NamingConventions.ValidClassName.Invalid">
<exclude-pattern>*/Transport/cURL\.php$</exclude-pattern>
<exclude-pattern>*/Transport/fsockopen\.php$</exclude-pattern>
<exclude-pattern>*/library/Deprecated\.php$</exclude-pattern>
</rule>

<rule ref="Generic.Files.OneObjectStructurePerFile.MultipleFound">
<exclude-pattern>*/library/Deprecated\.php$</exclude-pattern>
</rule>

<!-- ==========================================================================
Expand Down
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ We all have better things to do. That's why Requests was born.
```php
$headers = array('Accept' => 'application/json');
$options = array('auth' => array('user', 'pass'));
$request = Requests::get('https://api.github.com/gists', $headers, $options);
$request = WpOrg\Requests\Requests::get('https://api.github.com/gists', $headers, $options);

var_dump($request->status_code);
// int(200)
Expand Down Expand Up @@ -79,14 +79,14 @@ To install the source code:
$ git clone git://github.com/WordPress/Requests.git
```

And include it in your scripts:
Next, include the autoloader in your scripts:
```php
require_once '/path/to/Requests/library/Requests.php';
require_once '/path/to/Requests/src/Autoload.php';
```

You'll probably also want to register an autoloader:
You'll probably also want to register the autoloader:
```php
Requests::register_autoloader();
WpOrg\Requests\Autoload::register();
```

### Install source from zip/tarball
Expand All @@ -104,13 +104,15 @@ $ wget https://github.com/WordPress/Requests/tarball/stable -O - | tar xzv

### Using a Class Loader
If you're using a class loader (e.g., [Symfony Class Loader][]) for
[PSR-0][]-style class loading:
[PSR-4][]-style class loading:
```php
$loader->registerPrefix('Requests', 'path/to/vendor/Requests/library');
$loader = new Psr4ClassLoader();
$loader->addPrefix('WpOrg\\Requests\\', 'path/to/vendor/Requests/src');
$loader->register();
```

[Symfony Class Loader]: https://github.com/symfony/ClassLoader
[PSR-0]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md
[PSR-4]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4.md


Documentation
Expand All @@ -119,7 +121,7 @@ The best place to start is our [prose-based documentation][], which will guide
you through using Requests.

After that, take a look at [the documentation for
`Requests::request()`][request_method], where all the parameters are fully
`\WpOrg\Requests\Requests::request()`][request_method], where all the parameters are fully
documented.

Requests is [100% documented with PHPDoc](https://requests.ryanmccue.info/api/).
Expand Down
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@
},
"type": "library",
"autoload": {
"psr-0": {
"Requests": "library/"
}
"psr-4": {
"WpOrg\\Requests\\": "src/"
},
"classmap": ["library/Deprecated.php", "library/Requests.php"]
},
"autoload-dev": {
"psr-4": {
"Requests\\Tests\\": "tests/"
"WpOrg\\Requests\\Tests\\": "tests/"
}
},
"scripts": {
Expand Down
2 changes: 2 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ here are prose; you might also want to check out the [API documentation][].
* [Custom authentication][authentication-custom]
* [Requests through proxy][proxy]
* [Hooking system][hooks]
* [Upgrading to Requests 2.0][upgrading]

[goals]: goals.md
[why-requests]: why-requests.md
Expand All @@ -26,3 +27,4 @@ here are prose; you might also want to check out the [API documentation][].
[authentication-custom]: authentication-custom.md
[hooks]: hooks.md
[proxy]: proxy.md
[upgrading]: upgrading.md
8 changes: 4 additions & 4 deletions docs/authentication-custom.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Custom Authentication
=====================
Custom authentication handlers are designed to be straight-forward to write.
In order to write a handler, you'll need to implement the `Requests_Auth`
In order to write a handler, you'll need to implement the `WpOrg\Requests\Auth`
interface.

An instance of this handler can then be passed to Requests via the `auth`
Expand All @@ -12,14 +12,14 @@ authenticates the call if said header is set to `Yummy`. (I don't know of any
services that do this; perhaps this is a market waiting to be tapped?)

```php
class MySoftware_Auth_Hotdog implements Requests_Auth {
class MySoftware_Auth_Hotdog implements WpOrg\Requests\Auth {
protected $password;

public function __construct($password) {
$this->password = $password;
}

public function register(Requests_Hooks &$hooks) {
public function register(WpOrg\Requests\Hooks &$hooks) {
$hooks->register('requests.before_request', array($this, 'before_request'));
}

Expand All @@ -35,7 +35,7 @@ We then use this in our request calls like this:
$options = array(
'auth' => new MySoftware_Auth_Hotdog('yummy')
);
$response = Requests::get('http://hotdogbin.org/admin', array(), $options);
$response = WpOrg\Requests\Requests::get('http://hotdogbin.org/admin', array(), $options);
```

For more information on how to register and use hooks, see the [hooking
Expand Down
8 changes: 4 additions & 4 deletions docs/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ A Basic authenticated call can be made like this:

```php
$options = array(
'auth' => new Requests_Auth_Basic(array('user', 'password'))
'auth' => new WpOrg\Requests\Auth\Basic(array('user', 'password'))
);
Requests::get('https://httpbin.org/basic-auth/user/password', array(), $options);
WpOrg\Requests\Requests::get('https://httpbin.org/basic-auth/user/password', array(), $options);
```

As Basic authentication is usually what you want when you specify a username
Expand All @@ -20,14 +20,14 @@ and password, you can also just pass in an array as a shorthand:
$options = array(
'auth' => array('user', 'password')
);
Requests::get('https://httpbin.org/basic-auth/user/password', array(), $options);
WpOrg\Requests\Requests::get('https://httpbin.org/basic-auth/user/password', array(), $options);
```

Note that `POST`/`PUT` requests take a `$data` parameter, so you need to pass that
before `$options`:

```php
Requests::post('https://httpbin.org/basic-auth/user/password', array(), null, $options);
WpOrg\Requests\Requests::post('https://httpbin.org/basic-auth/user/password', array(), null, $options);
```

***
Expand Down
12 changes: 7 additions & 5 deletions docs/hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Hooks
Requests has a hook system that you can use to manipulate parts of the request
process along with internal transport hooks.

Check out the [API documentation for `Requests_Hooks`][requests_hooks] for more
Check out the [API documentation for `WpOrg\Requests\Hooks`][requests_hooks] for more
information on how to use the hook system.

[requests_hooks]: {{ '/api/class-Requests_Hooks.html' | prepend: site.baseurl }}
Expand All @@ -28,7 +28,7 @@ Available Hooks

Alter the response object before it is returned to the user.

Parameters: `Requests_Response &$return`
Parameters: `WpOrg\Requests\Response &$return`

* **`curl.before_request`**

Expand Down Expand Up @@ -88,16 +88,18 @@ Authentication guide][authentication-custom] instead.

[authentication-custom]: authentication-custom.md

In order to register your own hooks, you need to instantiate `Requests_Hooks`
In order to register your own hooks, you need to instantiate `WpOrg\Requests\Hooks`
and pass the object in via the `'hooks'` option.

```php
$hooks = new Requests_Hooks();
$hooks = new WpOrg\Requests\Hooks();
$hooks->register('requests.after_request', 'mycallback');

$request = Requests::get('https://httpbin.org/get', array(), array('hooks' => $hooks));
$request = WpOrg\Requests\Requests::get('https://httpbin.org/get', array(), array('hooks' => $hooks));
```

***

Previous: [Requests through proxy](proxy.md)

Next: [Upgrading to Requests 2.0](upgrading.md)
4 changes: 2 additions & 2 deletions docs/proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ To make requests through an open proxy, specify the following options:
$options = array(
'proxy' => '127.0.0.1:3128'
);
Requests::get('https://httpbin.org/ip', array(), $options);
WpOrg\Requests\Requests::get('https://httpbin.org/ip', array(), $options);
```

If your proxy needs you to authenticate, the option will become an array like
Expand All @@ -19,7 +19,7 @@ in the following example:
$options = array(
'proxy' => array( '127.0.0.1:3128', 'my_username', 'my_password' )
);
Requests::get('https://httpbin.org/ip', array(), $options);
WpOrg\Requests\Requests::get('https://httpbin.org/ip', array(), $options);
```

***
Expand Down
110 changes: 110 additions & 0 deletions docs/upgrading.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
Upgrading to Requests 2.0
=========================

Autoloading the Requests library
--------------------------------

In Requests 1.x, both a custom autoloader native to Requests, as well as autoloading
via the Composer `vendor/autoload.php` file was supported.

The same applies to Requests 2.x, though the way to initiate the Requests native
custom autoloader has changed.

If you were autoloading the Requests library via the Composer autoload file,
no changes are needed.

```php
// OLD: Using the custom autoloader in Requests 1.x.
require_once 'path/to/Requests/library/Requests.php';
Requests::register_autoloader();

// NEW: Using the custom autoloader in Requests 2.x.
require_once 'path/to/Requests/src/Autoload.php';
WpOrg\Requests\Autoload::register();
```

For backward compatibility reasons, the Requests 1.x manner to call the autoloader
will still be supported for the time being, but it is recommended to update
your code to use the new autoloader.


New namespaced names
--------------------

As of Requests 2.0.0, all code in the Requests library is namespaced and
class/interface names have been normalized to CamelCaps.

We recommend for all users to upgrade their code to use the new namespaced
class names.

| Type | Request 1.x name | Requests >= 2.0 name |
|-----------|----------------------------------------------|-------------------------------------------------------------------------|
| class | `Requests` | `WpOrg\Requests\Requests` <strong><sup>1</sup></strong> |
| interface | `Requests_Auth` | `WpOrg\Requests\Auth` |
| interface | `Requests_Hooker` | `WpOrg\Requests\Hooker` |
| interface | `Requests_Transport` | `WpOrg\Requests\Transport` |
| interface | `Requests_Proxy` | `WpOrg\Requests\Proxy` |
| class | `Requests_Cookie` | `WpOrg\Requests\Cookie` |
| class | `Requests_Exception` | `WpOrg\Requests\Exception` |
| class | `Requests_Hooks` | `WpOrg\Requests\Hooks` |
| class | `Requests_IDNAEncoder` | `WpOrg\Requests\IdnaEncoder` |
| class | `Requests_IPv6` | `WpOrg\Requests\Ipv6` |
| class | `Requests_IRI` | `WpOrg\Requests\Iri` |
| class | `Requests_Response` | `WpOrg\Requests\Response` |
| class | `Requests_Session` | `WpOrg\Requests\Session` |
| class | `Requests_SSL` | `WpOrg\Requests\Ssl` |
| class | `Requests_Auth_Basic` | `WpOrg\Requests\Auth\Basic` |
| class | `Requests_Cookie_Jar` | `WpOrg\Requests\Cookie\Jar` |
| class | `Requests_Proxy_HTTP` | `WpOrg\Requests\Proxy\Http` |
| class | `Requests_Response_Headers` | `WpOrg\Requests\Response\Headers` |
| class | `Requests_Transport_cURL` | `WpOrg\Requests\Transport\Curl` |
| class | `Requests_Transport_fsockopen` | `WpOrg\Requests\Transport\Fsockopen` |
| class | `Requests_Utility_CaseInsensitiveDictionary` | `WpOrg\Requests\Utility\CaseInsensitiveDictionary` |
| class | `Requests_Utility_FilteredIterator` | `WpOrg\Requests\Utility\FilteredIterator` |
| class | `Requests_Exception_HTTP` | `WpOrg\Requests\Exception\Http` |
| class | `Requests_Exception_Transport` | `WpOrg\Requests\Exception\Transport` |
| class | `Requests_Exception_Transport_cURL` | `WpOrg\Requests\Exception\Transport\Curl` |
| class | `Requests_Exception_HTTP_###` | `WpOrg\Requests\Exception\Http\Status###` <strong><sup>2</sup></strong> |
| class | `Requests_Exception_HTTP_Unknown` | `WpOrg\Requests\Exception\Http\StatusUnknown` |


**Notes**:

<sup>1</sup> The original `Requests` class has been split into two classes:
* `WpOrg\Requests\Requests` contains the actual functionality;
* `WpOrg\Requests\Autoload` contains the custom autoloader.
* The original non-namespaced `Requests` class remains for backward-compatibility
reasons and extends `WpOrg\Requests\Requests` and uses `WpOrg\Requests\Autoload`
in the old autoload functions, `Requests::autoloader()` and
`Requests::register_autoloader()`.

<sup>2</sup> The `###` in the HTTP Exception classes represents a three character,
numeric HTTP status code.
Exception classes are available for HTTP status 304 - 306, 400 - 418,
428, 429, 431, 500 - 505 and 511.


Backward compatibility layer
----------------------------

If for some reason, you can not yet upgrade or have to support both Requests 1.x
as well as Requests >= 2.0, a backward compatibility layer is provided.
This backward compatibility layer will work with both the Requests native
custom autoloader, as well as when using the Composer `vendor/autoload.php` file.

Using the old PSR-0 names will still work, but a deprecation notice will be
thrown the first time during a page load when a PSR-0 class name is referenced.

For the lifetime of Requests 2.x, the deprecation notices can be disabled by
defining a global `REQUESTS_SILENCE_PSR0_DEPRECATIONS` constant and
setting the value of this constant to `true`.
The constant needs to be defined before the first PSR-0 class name is requested.

As of Requests 3.0, support for the constant will be removed and
the deprecation notice will always be thrown.

As of Requests 4.0, the backward compatibility layer will be removed.

***

Previous: [Hooks](hooks.md)
Loading