annotate vendor/instaclick/php-webdriver/lib/WebDriver/ClassLoader.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 1fec387a4317
children
rev   line source
Chris@14 1 <?php
Chris@14 2 /**
Chris@14 3 * Copyright 2012-2017 Anthon Pang. All Rights Reserved.
Chris@14 4 *
Chris@14 5 * Licensed under the Apache License, Version 2.0 (the "License");
Chris@14 6 * you may not use this file except in compliance with the License.
Chris@14 7 * You may obtain a copy of the License at
Chris@14 8 *
Chris@14 9 * http://www.apache.org/licenses/LICENSE-2.0
Chris@14 10 *
Chris@14 11 * Unless required by applicable law or agreed to in writing, software
Chris@14 12 * distributed under the License is distributed on an "AS IS" BASIS,
Chris@14 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Chris@14 14 * See the License for the specific language governing permissions and
Chris@14 15 * limitations under the License.
Chris@14 16 *
Chris@14 17 * @package WebDriver
Chris@14 18 *
Chris@14 19 * @author Anthon Pang <apang@softwaredevelopment.ca>
Chris@14 20 */
Chris@14 21
Chris@14 22 namespace WebDriver;
Chris@14 23
Chris@14 24 /**
Chris@14 25 * WebDriver\ClassLoader (autoloader) class
Chris@14 26 *
Chris@14 27 * @package WebDriver
Chris@14 28 */
Chris@14 29 final class ClassLoader
Chris@14 30 {
Chris@14 31 /**
Chris@14 32 * Load class
Chris@14 33 *
Chris@14 34 * @param string $class Class name
Chris@14 35 */
Chris@14 36 public static function loadClass($class)
Chris@14 37 {
Chris@14 38 $file = strpos($class, '\\') !== false
Chris@14 39 ? str_replace('\\', DIRECTORY_SEPARATOR, $class)
Chris@14 40 : str_replace('_', DIRECTORY_SEPARATOR, $class);
Chris@14 41
Chris@14 42 $path = dirname(__DIR__) . DIRECTORY_SEPARATOR . $file . '.php';
Chris@14 43
Chris@14 44 if (file_exists($path)) {
Chris@14 45 include_once $path;
Chris@14 46 }
Chris@14 47 }
Chris@14 48
Chris@14 49 /**
Chris@14 50 * Autoloader
Chris@14 51 *
Chris@14 52 * @param string $class Class name
Chris@14 53 */
Chris@14 54 public static function autoload($class)
Chris@14 55 {
Chris@14 56 try {
Chris@14 57 self::loadClass($class);
Chris@14 58 } catch (\Exception $e) {
Chris@14 59 }
Chris@14 60 }
Chris@14 61 }
Chris@14 62
Chris@14 63 if (function_exists('spl_autoload_register')) {
Chris@14 64 /**
Chris@14 65 * use the SPL autoload stack
Chris@14 66 */
Chris@14 67 spl_autoload_register(array('WebDriver\ClassLoader', 'autoload'));
Chris@14 68
Chris@14 69 /**
Chris@14 70 * preserve any existing __autoload
Chris@14 71 */
Chris@14 72 if (function_exists('__autoload')) {
Chris@14 73 spl_autoload_register('__autoload');
Chris@14 74 }
Chris@14 75 } else {
Chris@14 76 /**
Chris@14 77 * Our fallback; only one __autoload per PHP instance
Chris@14 78 *
Chris@14 79 * @param string $class Class name
Chris@14 80 */
Chris@14 81 function __autoload($class)
Chris@14 82 {
Chris@14 83 ClassLoader::autoload($class);
Chris@14 84 }
Chris@14 85 }