+ if ( !$filename && strpos( $className, '\\' ) !== false ) {
+ // This class is namespaced, so try looking at the namespace map
+ $prefix = $className;
+ while ( false !== $pos = strrpos( $prefix, '\\' ) ) {
+ // Check to see if this namespace prefix is in the map
+ $prefix = substr( $className, 0, $pos + 1 );
+ if ( isset( self::$psr4Namespaces[$prefix] ) ) {
+ $relativeClass = substr( $className, $pos + 1 );
+ // Build the expected filename, and see if it exists
+ $file = self::$psr4Namespaces[$prefix] .
+ str_replace( '\\', '/', $relativeClass ) . '.php';
+ if ( file_exists( $file ) ) {
+ $filename = $file;
+ break;
+ }
+ }
+
+ // Remove trailing separator for next iteration
+ $prefix = rtrim( $prefix, '\\' );
+ }
+ }
+