1414class Autoload
1515{
1616 /**
17- * Remove First Slash
17+ * Directory
1818 *
19- * @param $string
20- */
21- private static function removeFirstSlash (&$ string )
22- {
23- if (substr ($ string , 0 , 1 ) == '/ ' ) {
24- $ string = substr ($ string , 1 );
25- }
26- }
27-
28- /**
29- * Remove Last Slash
30- *
31- * @param $string
32- */
33- private static function removeLastSlash (&$ string )
34- {
35- if (substr ($ string , -1 ) == '/ ' ) {
36- $ string = substr ($ string , 0 , -1 );
37- }
38- }
39-
40- /**
41- * Replace Slash
42- *
43- * @param $string
44- */
45- private static function replaceSlash (&$ string )
46- {
47- $ string = str_replace ('\\' , '/ ' , $ string );
48- }
49-
50- /**
51- * Load
52- *
53- * @param $path
19+ * @param $directory
5420 * @param $namespaceRoot
5521 */
56- public static function load ( $ path , $ namespaceRoot )
22+ public static function directory ( $ directory , $ namespaceRoot )
5723 {
58- spl_autoload_register (function ($ className ) use ($ path , $ namespaceRoot ) {
59- self ::replaceSlash ($ path );
60- self ::removeLastSlash ($ path );
61- self ::replaceSlash ($ namespaceRoot );
62- self ::removeFirstSlash ($ namespaceRoot );
63- self ::removeLastSlash ($ namespaceRoot );
64- self ::replaceSlash ($ className );
65- self ::removeFirstSlash ($ className );
66- self ::removeLastSlash ($ className );
24+ spl_autoload_register (function ($ className ) use ($ directory , $ namespaceRoot ) {
25+ Tool ::replaceSlash ($ directory );
26+ Tool ::removeLastSlash ($ directory );
27+ Tool ::replaceSlash ($ namespaceRoot );
28+ Tool ::removeFirstSlash ($ namespaceRoot );
29+ Tool ::removeLastSlash ($ namespaceRoot );
30+ Tool ::replaceSlash ($ className );
31+ Tool ::removeFirstSlash ($ className );
32+ Tool ::removeLastSlash ($ className );
6733 if (substr ($ className , 0 , strlen ($ namespaceRoot )) == $ namespaceRoot ) {
6834 $ className = substr ($ className , strlen ($ namespaceRoot ));
69- self ::removeFirstSlash ($ className );
35+ Tool ::removeFirstSlash ($ className );
7036 }
71- $ file = $ path . '/ ' . $ className . '.php ' ;
37+ $ file = $ directory . '/ ' . $ className . '.php ' ;
7238 if (is_file ($ file )) {
7339 require_once ($ file );
7440 }
@@ -78,21 +44,21 @@ public static function load($path, $namespaceRoot)
7844 /**
7945 * File
8046 *
81- * @param $path
82- * @param $name
47+ * @param $file
48+ * @param $className
8349 */
84- public static function file ($ path , $ name )
50+ public static function file ($ file , $ className )
8551 {
86- spl_autoload_register (function ($ className ) use ($ path , $ name ) {
87- self ::replaceSlash ($ name );
88- self ::removeFirstSlash ($ name );
89- self ::removeLastSlash ($ name );
90- self ::replaceSlash ($ className );
91- self ::removeFirstSlash ($ className );
92- self ::removeLastSlash ($ className );
93- if ($ name == $ className ) {
94- if (is_file ($ path )) {
95- require_once ($ path );
52+ spl_autoload_register (function ($ name ) use ($ file , $ className ) {
53+ Tool ::replaceSlash ($ className );
54+ Tool ::removeFirstSlash ($ className );
55+ Tool ::removeLastSlash ($ className );
56+ Tool ::replaceSlash ($ name );
57+ Tool ::removeFirstSlash ($ name );
58+ Tool ::removeLastSlash ($ name );
59+ if ($ className == $ name ) {
60+ if (is_file ($ file )) {
61+ require_once ($ file );
9662 }
9763 }
9864 });
0 commit comments