annotate vendor/instaclick/php-webdriver/lib/WebDriver/ClassLoader.php @ 0:c75dbcec494b

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