Skip to content

Commit

Permalink
Update the PSR-4 autoloader
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
stevegrunwell committed Apr 20, 2020
1 parent bd3acb9 commit ab38763
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions limit-orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ) {
Expand Down

0 comments on commit ab38763

Please sign in to comment.