WpOrgRequestsAutoload
PSR-4 autoloader for the Requests library with PSR-0 backward compatibility.
Source: wp-includes/Requests/src/Autoload.php
Namespace: WpOrgRequests
Package: Requests
Since: 2.0.0
Modifier: final
Overview
Provides autoloading for the Requests library. Supports PSR-4 namespaced classes (WpOrgRequests*) in a case-sensitive manner, and provides backward compatibility for the deprecated PSR-0 class names (Requests_*) via class_alias() with deprecation notices.
The entire class definition is wrapped in if (class_exists('WpOrgRequestsAutoload') === false) to prevent "Class already declared" fatal errors when the file is required multiple times.
Properties
$deprecated_classes
private static array $deprecated_classesMaps old PSR-0 class names (lowercase) to their PSR-4 equivalents. Contains mappings for all interfaces, classes, and exception classes in the library. Examples:
| PSR-0 Key (lowercase) | PSR-4 Value |
|---|---|
requests_auth | WpOrgRequestsAuth |
requests_hooker | WpOrgRequestsHookManager |
requests_ssl | WpOrgRequestsSsl |
requests_exception_http_404 | WpOrgRequestsExceptionHttpStatus404 |
requests_exception_http_unknown | WpOrgRequestsExceptionHttpStatusUnknown |
(Full list contains 50+ mappings for all library classes.)
Methods
register()
Register the autoloader with spl_autoload_register().
public static function register(): voidThe autoloader is prepended to the autoload queue to take precedence over any Requests 1.x autoloader. Uses the REQUESTS_AUTOLOAD_REGISTERED global constant as a guard against double-registration.
load()
Autoloader callback. Attempts to load a class by name.
public static function load( string $class_name ): bool| Parameter | Type | Description |
|---|---|---|
$class_name | string | Fully qualified class name |
Returns: bool — Whether a class was loaded.
Loading strategy:
- If the class doesn’t start with
Requests(PSR-0) orWpOrgRequests(PSR-4), returnfalse. - If the class is exactly
Requests(case-insensitive), loadlibrary/Requests.php. - If PSR-4 prefixed (
WpOrgRequests), compute file path by replacingwith/after stripping the prefix, relative tosrc/. - If the file exists,
includeit and returntrue. - If the lowercased class name is in
$deprecated_classes:- Emit
E_USER_DEPRECATEDnotice (unlessREQUESTS_SILENCE_PSR0_DEPRECATIONSistrue). - Call
class_alias()to map the old name to the PSR-4 name, triggering recursive autoloading.
- Emit
- Return
falseif nothing matched.
Deprecation Behavior
When a PSR-0 class name is requested:
Requests_Exception_Http_404
│
├─ Not found as PSR-4
├─ Lowercased: "requests_exception_http_404"
├─ Found in $deprecated_classes → WpOrgRequestsExceptionHttpStatus404
├─ Emit E_USER_DEPRECATED (first time only)
│ "The PSR-0 `Requests_...` class names in the Requests library are deprecated.
│ Switch to the PSR-4 `WpOrgRequests...` class names at your earliest convenience."
├─ Define REQUESTS_SILENCE_PSR0_DEPRECATIONS = true (prevents repeat notices)
└─ class_alias() → autoloader recursively loads PSR-4 class