Projet

Général

Profil

Paste
Télécharger (1,14 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / recaptcha / recaptcha-php / src / autoload.php @ be58a50c

1
<?php
2

    
3
/* An autoloader for ReCaptcha\Foo classes. This should be require()d
4
 * by the user before attempting to instantiate any of the ReCaptcha
5
 * classes.
6
 */
7

    
8
spl_autoload_register(function ($class) {
9
    if (substr($class, 0, 10) !== 'ReCaptcha\\') {
10
      /* If the class does not lie under the "ReCaptcha" namespace,
11
       * then we can exit immediately.
12
       */
13
      return;
14
    }
15

    
16
    /* All of the classes have names like "ReCaptcha\Foo", so we need
17
     * to replace the backslashes with frontslashes if we want the
18
     * name to map directly to a location in the filesystem.
19
     */
20
    $class = str_replace('\\', '/', $class);
21

    
22
    /* First, check under the current directory. It is important that
23
     * we look here first, so that we don't waste time searching for
24
     * test classes in the common case.
25
     */
26
    $path = dirname(__FILE__).'/'.$class.'.php';
27
    if (is_readable($path)) {
28
        require_once $path;
29
    }
30

    
31
    /* If we didn't find what we're looking for already, maybe it's
32
     * a test class?
33
     */
34
    $path = dirname(__FILE__).'/../tests/'.$class.'.php';
35
    if (is_readable($path)) {
36
        require_once $path;
37
    }
38
});