Security update for permissions_by_term
[yaffs-website] / vendor / instaclick / php-webdriver / lib / WebDriver / ClassLoader.php
1 <?php
2 /**
3  * Copyright 2012-2017 Anthon Pang. All Rights Reserved.
4  *
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
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * @package WebDriver
18  *
19  * @author Anthon Pang <apang@softwaredevelopment.ca>
20  */
21
22 namespace WebDriver;
23
24 /**
25  * WebDriver\ClassLoader (autoloader) class
26  *
27  * @package WebDriver
28  */
29 final class ClassLoader
30 {
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 if (function_exists('spl_autoload_register')) {
64     /**
65      * use the SPL autoload stack
66      */
67     spl_autoload_register(array('WebDriver\ClassLoader', 'autoload'));
68
69     /**
70      * preserve any existing __autoload
71      */
72     if (function_exists('__autoload')) {
73         spl_autoload_register('__autoload');
74     }
75 } else {
76     /**
77      * Our fallback; only one __autoload per PHP instance
78      *
79      * @param string $class Class name
80      */
81     function __autoload($class)
82     {
83         ClassLoader::autoload($class);
84     }
85 }