@@ -68,6 +68,13 @@ class Autoloader {
6868 */
6969 protected $ mappings = false ;
7070
71+ /**
72+ * Stores Classmap Generated Files.
73+ *
74+ * @var bool
75+ */
76+ protected $ classmaps = false ;
77+
7178 /**
7279 * Autoloader constructor.
7380 *
@@ -97,10 +104,21 @@ protected function set_options( $options ) {
97104 'prepend ' => false ,
98105 'mapping ' => false ,
99106 'search_folders ' => false ,
107+ 'classmaps ' => false ,
100108 ), $ options );
101109 $ this ->options ['exclude ' ] = ( ! is_array ( $ this ->options ['exclude ' ] ) ) ? array_filter ( array ( $ this ->options ['exclude ' ] ) ) : $ this ->options ['exclude ' ];
102110 $ this ->options ['mapping ' ] = ( ! is_array ( $ this ->options ['mapping ' ] ) ) ? array () : $ this ->options ['mapping ' ];
103111 $ this ->mappings = $ this ->options ['mapping ' ];
112+
113+ if ( ! empty ( $ this ->options ['classmaps ' ] ) ) {
114+ if ( is_array ( $ this ->options ['classmaps ' ] ) ) {
115+ $ this ->classmaps = $ this ->options ['classmaps ' ];
116+ unset( $ this ->options ['classmaps ' ] );
117+ } elseif ( is_string ( $ this ->options ['classmaps ' ] ) && file_exists ( $ this ->options ['classmaps ' ] ) ) {
118+ $ this ->classmaps = include $ this ->options ['classmaps ' ];
119+ }
120+ }
121+
104122 unset( $ this ->options ['mapping ' ] );
105123 return $ this ;
106124 }
@@ -171,6 +189,16 @@ public function autoload( $class ) {
171189 $ folders = null ;
172190 $ is_loaded = false ;
173191
192+ /**
193+ * @uses varunsridharan/php-classmap-generator script which provides location along with class name
194+ */
195+ if ( isset ( $ this ->classmaps [ $ class ] ) ) {
196+ $ is_loaded = $ this ->load_file ( $ this ->classmaps [ $ class ], $ class );
197+ if ( false === $ is_loaded ) {
198+ $ is_loaded = $ this ->load_file ( $ this ->base_path . $ this ->classmaps [ $ class ], $ class );
199+ }
200+ }
201+
174202 /**
175203 * Checks and loads file if given class exists in mapping array.
176204 *
@@ -179,7 +207,7 @@ public function autoload( $class ) {
179207 * '\somenamespace\someclass2' => 'your-path/file2.php'
180208 * )
181209 */
182- if ( isset ( $ this ->mappings [ $ class ] ) ) {
210+ if ( false === $ is_loaded && isset ( $ this ->mappings [ $ class ] ) ) {
183211 $ is_loaded = $ this ->load_file ( $ this ->mappings [ $ class ], $ class );
184212 if ( false === $ is_loaded ) {
185213 $ is_loaded = $ this ->load_file ( $ this ->base_path . $ this ->mappings [ $ class ], $ class );
0 commit comments