3 * Copyright 2012-2017 Anthon Pang. All Rights Reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 * @author Anthon Pang <apang@softwaredevelopment.ca>
25 * WebDriver\ClassLoader (autoloader) class
29 final class ClassLoader
34 * @param string $class Class name
36 public static function loadClass($class)
38 $file = strpos($class, '\\') !== false
39 ? str_replace('\\', DIRECTORY_SEPARATOR, $class)
40 : str_replace('_', DIRECTORY_SEPARATOR, $class);
42 $path = dirname(__DIR__) . DIRECTORY_SEPARATOR . $file . '.php';
44 if (file_exists($path)) {
52 * @param string $class Class name
54 public static function autoload($class)
57 self::loadClass($class);
58 } catch (\Exception $e) {
63 if (function_exists('spl_autoload_register')) {
65 * use the SPL autoload stack
67 spl_autoload_register(array('WebDriver\ClassLoader', 'autoload'));
70 * preserve any existing __autoload
72 if (function_exists('__autoload')) {
73 spl_autoload_register('__autoload');
77 * Our fallback; only one __autoload per PHP instance
79 * @param string $class Class name
81 function __autoload($class)
83 ClassLoader::autoload($class);