From ab38763a5581a238f56049aa9ca8ae2d126bf2a1 Mon Sep 17 00:00:00 2001 From: Steve Grunwell Date: Mon, 20 Apr 2020 16:53:11 +0000 Subject: [PATCH] Update the PSR-4 autoloader Return as early as possible from the autoloader closure if we're not trying to access something in the `Nexcess\LimitOrders` namespace. Additionally, remove the `string` type-hint from the closure, as it may be contributing to #16. --- limit-orders.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/limit-orders.php b/limit-orders.php index 9a90374..89142de 100644 --- a/limit-orders.php +++ b/limit-orders.php @@ -21,8 +21,16 @@ * * @param string $class The classname we're attempting to load. */ -spl_autoload_register( function ( string $class ) { - $filepath = str_replace( __NAMESPACE__ . '\\', '', $class ); +spl_autoload_register( function ( $class ) { + $namespace = __NAMESPACE__ . '\\'; + $class = (string) $class; + + // Move onto the next registered autoloader if the class is outside of our namespace. + if ( 0 !== strncmp( $namespace, $class, strlen( $namespace ) ) ) { + return; + } + + $filepath = str_replace( $namespace, '', $class ); $filepath = __DIR__ . '/src/' . str_replace( '\\', '/', $filepath ) . '.php'; if ( is_readable( $filepath ) ) {