Auth
5 months ago
Cookie
5 months ago
Exception
5 months ago
Proxy
5 months ago
Response
5 months ago
Transport
5 months ago
Utility
5 months ago
Auth.php
5 months ago
Autoload.php
5 months ago
Capability.php
5 months ago
Cookie.php
5 months ago
Exception.php
5 months ago
HookManager.php
5 months ago
Hooks.php
5 months ago
IdnaEncoder.php
5 months ago
Ipv6.php
5 months ago
Iri.php
5 months ago
Port.php
5 months ago
Proxy.php
5 months ago
Requests.php
5 months ago
Response.php
5 months ago
Session.php
5 months ago
Ssl.php
5 months ago
Transport.php
5 months ago
Autoload.php
188 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Autoloader for AmeliaVendor_Requests for PHP. |
| 4 | * |
| 5 | * Include this file if you'd like to avoid having to create your own autoloader. |
| 6 | * |
| 7 | * @package AmeliaVendor_Requests |
| 8 | * @since 2.0.0 |
| 9 | * |
| 10 | * @codeCoverageIgnore |
| 11 | */ |
| 12 | |
| 13 | namespace AmeliaVendor\WpOrg\Requests; |
| 14 | |
| 15 | /* |
| 16 | * Ensure the autoloader is only declared once. |
| 17 | * This safeguard is in place as this is the typical entry point for this library |
| 18 | * and this file being required unconditionally could easily cause |
| 19 | * fatal "Class already declared" errors. |
| 20 | */ |
| 21 | if (class_exists('AmeliaVendor\WpOrg\Requests\Autoload') === false) { |
| 22 | |
| 23 | /** |
| 24 | * Autoloader for Requests for PHP. |
| 25 | * |
| 26 | * This autoloader supports the PSR-4 based Requests 2.0.0 classes in a case-sensitive manner |
| 27 | * as the most common server OS-es are case-sensitive and the file names are in mixed case. |
| 28 | * |
| 29 | * For the PSR-0 Requests 1.x BC-layer, requested classes will be treated case-insensitively. |
| 30 | * |
| 31 | * @package Requests |
| 32 | */ |
| 33 | final class Autoload { |
| 34 | |
| 35 | /** |
| 36 | * List of the old PSR-0 class names in lowercase as keys with their PSR-4 case-sensitive name as a value. |
| 37 | * |
| 38 | * @var array |
| 39 | */ |
| 40 | private static $deprecated_classes = [ |
| 41 | // Interfaces. |
| 42 | 'requests_auth' => '\AmeliaVendor\WpOrg\Requests\Auth', |
| 43 | 'requests_hooker' => '\AmeliaVendor\WpOrg\Requests\HookManager', |
| 44 | 'requests_proxy' => '\AmeliaVendor\WpOrg\Requests\Proxy', |
| 45 | 'requests_transport' => '\AmeliaVendor\WpOrg\Requests\Transport', |
| 46 | |
| 47 | // Classes. |
| 48 | 'requests_cookie' => '\AmeliaVendor\WpOrg\Requests\Cookie', |
| 49 | 'requests_exception' => '\AmeliaVendor\WpOrg\Requests\Exception', |
| 50 | 'requests_hooks' => '\AmeliaVendor\WpOrg\Requests\Hooks', |
| 51 | 'requests_idnaencoder' => '\AmeliaVendor\WpOrg\Requests\IdnaEncoder', |
| 52 | 'requests_ipv6' => '\AmeliaVendor\WpOrg\Requests\Ipv6', |
| 53 | 'requests_iri' => '\AmeliaVendor\WpOrg\Requests\Iri', |
| 54 | 'requests_response' => '\AmeliaVendor\WpOrg\Requests\Response', |
| 55 | 'requests_session' => '\AmeliaVendor\WpOrg\Requests\Session', |
| 56 | 'requests_ssl' => '\AmeliaVendor\WpOrg\Requests\Ssl', |
| 57 | 'requests_auth_basic' => '\AmeliaVendor\WpOrg\Requests\Auth\Basic', |
| 58 | 'requests_cookie_jar' => '\AmeliaVendor\WpOrg\Requests\Cookie\Jar', |
| 59 | 'requests_proxy_http' => '\AmeliaVendor\WpOrg\Requests\Proxy\Http', |
| 60 | 'requests_response_headers' => '\AmeliaVendor\WpOrg\Requests\Response\Headers', |
| 61 | 'requests_transport_curl' => '\AmeliaVendor\WpOrg\Requests\Transport\Curl', |
| 62 | 'requests_transport_fsockopen' => '\AmeliaVendor\WpOrg\Requests\Transport\Fsockopen', |
| 63 | 'requests_utility_caseinsensitivedictionary' => '\AmeliaVendor\WpOrg\Requests\Utility\CaseInsensitiveDictionary', |
| 64 | 'requests_utility_filterediterator' => '\AmeliaVendor\WpOrg\Requests\Utility\FilteredIterator', |
| 65 | 'requests_exception_http' => '\AmeliaVendor\WpOrg\Requests\Exception\Http', |
| 66 | 'requests_exception_transport' => '\AmeliaVendor\WpOrg\Requests\Exception\Transport', |
| 67 | 'requests_exception_transport_curl' => '\AmeliaVendor\WpOrg\Requests\Exception\Transport\Curl', |
| 68 | 'requests_exception_http_304' => '\AmeliaVendor\WpOrg\Requests\Exception\Http\Status304', |
| 69 | 'requests_exception_http_305' => '\AmeliaVendor\WpOrg\Requests\Exception\Http\Status305', |
| 70 | 'requests_exception_http_306' => '\AmeliaVendor\WpOrg\Requests\Exception\Http\Status306', |
| 71 | 'requests_exception_http_400' => '\AmeliaVendor\WpOrg\Requests\Exception\Http\Status400', |
| 72 | 'requests_exception_http_401' => '\AmeliaVendor\WpOrg\Requests\Exception\Http\Status401', |
| 73 | 'requests_exception_http_402' => '\AmeliaVendor\WpOrg\Requests\Exception\Http\Status402', |
| 74 | 'requests_exception_http_403' => '\AmeliaVendor\WpOrg\Requests\Exception\Http\Status403', |
| 75 | 'requests_exception_http_404' => '\AmeliaVendor\WpOrg\Requests\Exception\Http\Status404', |
| 76 | 'requests_exception_http_405' => '\AmeliaVendor\WpOrg\Requests\Exception\Http\Status405', |
| 77 | 'requests_exception_http_406' => '\AmeliaVendor\WpOrg\Requests\Exception\Http\Status406', |
| 78 | 'requests_exception_http_407' => '\AmeliaVendor\WpOrg\Requests\Exception\Http\Status407', |
| 79 | 'requests_exception_http_408' => '\AmeliaVendor\WpOrg\Requests\Exception\Http\Status408', |
| 80 | 'requests_exception_http_409' => '\AmeliaVendor\WpOrg\Requests\Exception\Http\Status409', |
| 81 | 'requests_exception_http_410' => '\AmeliaVendor\WpOrg\Requests\Exception\Http\Status410', |
| 82 | 'requests_exception_http_411' => '\AmeliaVendor\WpOrg\Requests\Exception\Http\Status411', |
| 83 | 'requests_exception_http_412' => '\AmeliaVendor\WpOrg\Requests\Exception\Http\Status412', |
| 84 | 'requests_exception_http_413' => '\AmeliaVendor\WpOrg\Requests\Exception\Http\Status413', |
| 85 | 'requests_exception_http_414' => '\AmeliaVendor\WpOrg\Requests\Exception\Http\Status414', |
| 86 | 'requests_exception_http_415' => '\AmeliaVendor\WpOrg\Requests\Exception\Http\Status415', |
| 87 | 'requests_exception_http_416' => '\AmeliaVendor\WpOrg\Requests\Exception\Http\Status416', |
| 88 | 'requests_exception_http_417' => '\AmeliaVendor\WpOrg\Requests\Exception\Http\Status417', |
| 89 | 'requests_exception_http_418' => '\AmeliaVendor\WpOrg\Requests\Exception\Http\Status418', |
| 90 | 'requests_exception_http_428' => '\AmeliaVendor\WpOrg\Requests\Exception\Http\Status428', |
| 91 | 'requests_exception_http_429' => '\AmeliaVendor\WpOrg\Requests\Exception\Http\Status429', |
| 92 | 'requests_exception_http_431' => '\AmeliaVendor\WpOrg\Requests\Exception\Http\Status431', |
| 93 | 'requests_exception_http_500' => '\AmeliaVendor\WpOrg\Requests\Exception\Http\Status500', |
| 94 | 'requests_exception_http_501' => '\AmeliaVendor\WpOrg\Requests\Exception\Http\Status501', |
| 95 | 'requests_exception_http_502' => '\AmeliaVendor\WpOrg\Requests\Exception\Http\Status502', |
| 96 | 'requests_exception_http_503' => '\AmeliaVendor\WpOrg\Requests\Exception\Http\Status503', |
| 97 | 'requests_exception_http_504' => '\AmeliaVendor\WpOrg\Requests\Exception\Http\Status504', |
| 98 | 'requests_exception_http_505' => '\AmeliaVendor\WpOrg\Requests\Exception\Http\Status505', |
| 99 | 'requests_exception_http_511' => '\AmeliaVendor\WpOrg\Requests\Exception\Http\Status511', |
| 100 | 'requests_exception_http_unknown' => '\AmeliaVendor\WpOrg\Requests\Exception\Http\StatusUnknown', |
| 101 | ]; |
| 102 | |
| 103 | /** |
| 104 | * Register the autoloader. |
| 105 | * |
| 106 | * Note: the autoloader is *prepended* in the autoload queue. |
| 107 | * This is done to ensure that the Requests 2.0 autoloader takes precedence |
| 108 | * over a potentially (dependency-registered) Requests 1.x autoloader. |
| 109 | * |
| 110 | * @internal This method contains a safeguard against the autoloader being |
| 111 | * registered multiple times. This safeguard uses a global constant to |
| 112 | * (hopefully/in most cases) still function correctly, even if the |
| 113 | * class would be renamed. |
| 114 | * |
| 115 | * @return void |
| 116 | */ |
| 117 | public static function register() { |
| 118 | if (defined('REQUESTS_AUTOLOAD_REGISTERED') === false) { |
| 119 | spl_autoload_register([self::class, 'load'], true); |
| 120 | define('REQUESTS_AUTOLOAD_REGISTERED', true); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Autoloader. |
| 126 | * |
| 127 | * @param string $class_name Name of the class name to load. |
| 128 | * |
| 129 | * @return bool Whether a class was loaded or not. |
| 130 | */ |
| 131 | public static function load($class_name) { |
| 132 | // Check that the class starts with "Requests" (PSR-0) or "AmeliaVendor\WpOrg\Requests" (PSR-4). |
| 133 | $psr_4_prefix_pos = strpos($class_name, 'AmeliaVendor\\WpOrg\\Requests\\'); |
| 134 | |
| 135 | if (stripos($class_name, 'Requests') !== 0 && $psr_4_prefix_pos !== 0) { |
| 136 | return false; |
| 137 | } |
| 138 | |
| 139 | $class_lower = strtolower($class_name); |
| 140 | |
| 141 | if ($class_lower === 'requests') { |
| 142 | // Reference to the original PSR-0 Requests class. |
| 143 | $file = dirname(__DIR__) . '/library/Requests.php'; |
| 144 | } elseif ($psr_4_prefix_pos === 0) { |
| 145 | // PSR-4 classname. |
| 146 | $file = __DIR__ . '/' . strtr(substr($class_name, 15), '\\', '/') . '.php'; |
| 147 | } |
| 148 | |
| 149 | if (isset($file) && file_exists($file)) { |
| 150 | include $file; |
| 151 | return true; |
| 152 | } |
| 153 | |
| 154 | /* |
| 155 | * Okay, so the class starts with "Requests", but we couldn't find the file. |
| 156 | * If this is one of the deprecated/renamed PSR-0 classes being requested, |
| 157 | * let's alias it to the new name and throw a deprecation notice. |
| 158 | */ |
| 159 | if (isset(self::$deprecated_classes[$class_lower])) { |
| 160 | /* |
| 161 | * Integrators who cannot yet upgrade to the PSR-4 class names can silence deprecations |
| 162 | * by defining a `REQUESTS_SILENCE_PSR0_DEPRECATIONS` constant and setting it to `true`. |
| 163 | * The constant needs to be defined before the first deprecated class is requested |
| 164 | * via this autoloader. |
| 165 | */ |
| 166 | if (!defined('REQUESTS_SILENCE_PSR0_DEPRECATIONS') || REQUESTS_SILENCE_PSR0_DEPRECATIONS !== true) { |
| 167 | // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error |
| 168 | trigger_error( |
| 169 | 'The PSR-0 `Requests_...` class names in the Requests library are deprecated.' |
| 170 | . ' Switch to the PSR-4 `WpOrg\Requests\...` class names at your earliest convenience.', |
| 171 | E_USER_DEPRECATED |
| 172 | ); |
| 173 | |
| 174 | // Prevent the deprecation notice from being thrown twice. |
| 175 | if (!defined('REQUESTS_SILENCE_PSR0_DEPRECATIONS')) { |
| 176 | define('REQUESTS_SILENCE_PSR0_DEPRECATIONS', true); |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | // Create an alias and let the autoloader recursively kick in to load the PSR-4 class. |
| 181 | return class_alias(self::$deprecated_classes[$class_lower], $class_name, true); |
| 182 | } |
| 183 | |
| 184 | return false; |
| 185 | } |
| 186 | } |
| 187 | } |
| 188 |