Skip to content

Commit

Permalink
Merge pull request #17 from nexcess/fix/typehint-in-autoloader
Browse files Browse the repository at this point in the history
Update the PSR-4 autoloader
  • Loading branch information
bswatson authored Apr 21, 2020
2 parents bd3acb9 + ab38763 commit e88d174
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 e88d174

Please sign in to comment.