diff --git a/examples/preload-aliases.php b/examples/preload-aliases.php new file mode 100644 index 000000000..ae20a72ee --- /dev/null +++ b/examples/preload-aliases.php @@ -0,0 +1,33 @@ + $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); + } +} diff --git a/src/Autoload.php b/src/Autoload.php index 26dd280ee..25a463a5b 100644 --- a/src/Autoload.php +++ b/src/Autoload.php @@ -183,5 +183,14 @@ public static function load($class_name) { return false; } + + /** + * Get the array of deprecated Requests 1.x classes mapped to their equivalent Requests 2.x implementation. + * + * @return array + */ + public static function get_deprecated_classes() { + return self::$deprecated_classes; + } } } diff --git a/tests/AutoloadTest.php b/tests/AutoloadTest.php index e68625325..aa715ef19 100644 --- a/tests/AutoloadTest.php +++ b/tests/AutoloadTest.php @@ -5,6 +5,7 @@ use Requests_Exception_Transport_cURL; use Requests_Utility_FilteredIterator; use WpOrg\Requests\Tests\TestCase; +use WpOrg\Requests\Autoload; use WpOrg\Requests\Utility\FilteredIterator; final class AutoloadTest extends TestCase { @@ -53,4 +54,11 @@ public function testAutoloadOfOldRequestsClassDoesNotThrowAFatalForFinalClass() public function testConstantDeclarationDoesntInfluenceFurtherTests() { $this->assertFalse(defined('REQUESTS_SILENCE_PSR0_DEPRECATIONS')); } + + /** + * Verify that the get_deprecated_classes() method returns an array with 57 items. + */ + public function testGetDeprecatedClassesReturnsAnArrayWithCorrectAmountOfItems() { + $this->assertCount(57, Autoload::get_deprecated_classes()); + } }