File tree Expand file tree Collapse file tree 1 file changed +50
-5
lines changed
Expand file tree Collapse file tree 1 file changed +50
-5
lines changed Original file line number Diff line number Diff line change 2121
2222namespace WebDriver ;
2323
24- /**
25- * @TODO implement the class loader!
26- */
27- require_once (__DIR__ . '/__init__.php ' );
28-
2924/**
3025 * WebDriver\ClassLoader (autoloader) class
3126 *
3227 * @package WebDriver
3328 */
3429final class ClassLoader
3530{
31+ /**
32+ * Load class
33+ *
34+ * @param string $class Class name
35+ */
36+ public static function loadClass ($ class )
37+ {
38+ $ file = strpos ($ class , '\\' ) !== false
39+ ? str_replace ('\\' , DIRECTORY_SEPARATOR , $ class )
40+ : str_replace ('_ ' , DIRECTORY_SEPARATOR , $ class );
41+
42+ $ path = dirname (__DIR__ ) . DIRECTORY_SEPARATOR . $ file . '.php ' ;
43+
44+ if (file_exists ($ path )) {
45+ include_once $ path ;
46+ }
47+ }
48+
49+ /**
50+ * Autoloader
51+ *
52+ * @param string $class Class name
53+ */
54+ public static function autoload ($ class )
55+ {
56+ try {
57+ self ::loadClass ($ class );
58+ } catch (Exception $ e ) {
59+ }
60+ }
61+ }
62+
63+ // Note: only one __autoload per PHP instance
64+ if (function_exists ('spl_autoload_register ' ))
65+ {
66+ // use the SPL autoload stack
67+ spl_autoload_register (array ('WebDriver\ClassLoader ' , 'autoload ' ));
68+
69+ // preserve any existing __autoload
70+ if (function_exists ('__autoload ' ))
71+ {
72+ spl_autoload_register ('__autoload ' );
73+ }
74+ }
75+ else
76+ {
77+ function __autoload ($ class )
78+ {
79+ ClassLoader::autoload ($ class );
80+ }
3681}
You can’t perform that action at this time.
0 commit comments