Repository navigation
Expand file tree
/
Copy pathpreload-aliases.php
More file actions
41 lines (35 loc) · 1.63 KB
/
Copy pathpreload-aliases.php
File metadata and controls
41 lines (35 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
/**
* Requests for PHP, an HTTP library.
*
* @package Requests\Examples
* @copyright 2012-2023 Requests Contributors
* @license https://github.com/WordPress/Requests/blob/stable/LICENSE ISC
* @link https://github.com/WordPress/Requests
*/
/*
* If you need to run the Requests v2.x library with another framework/CMS that still ships v1.x,
* use the following to preload the class aliases before the actual implementations of Requests v1.x. get loaded.
*
* Please note that mixing Requests v1.x and v2.x files is a bad idea and may have side effects.
* Do so at your own risk.
*/
// First, include the Requests Autoloader.
require_once 'path/to/Requests/src/Autoload.php';
// Make sure the autoloader is registered first as otherwise you may run into trouble on PHP 8.1.
// See: https://news-web.php.net/php.internals/115549
WpOrg\Requests\Autoload::register();
// Silence deprecations.
// Depending on when the bootstrapping is done, you may need to wrap this in a `if (!defined(...)) {}`.
define('REQUESTS_SILENCE_PSR0_DEPRECATIONS', true);
$preload = WpOrg\Requests\Autoload::get_deprecated_classes();
// Add the base Requests class, just to be safe.
$preload['requests'] = '\WpOrg\Requests\Requests';
// Preload the class aliases for the Requests 1.x classes to ensure only Requests 2.x classes get loaded.
foreach ($preload as $old => $new) {
// Make sure we don't get "Class already exists errors" from autoloading chains.
// Think: an `implements` causing an interface to be loaded before we explicitly request it.
if (class_exists($old) === false && interface_exists($old) === false) {
WpOrg\Requests\Autoload::load($old);
}
}