autoload.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. /* An autoloader for ReCaptcha\Foo classes. This should be require()d
  3. * by the user before attempting to instantiate any of the ReCaptcha
  4. * classes.
  5. */
  6. spl_autoload_register(function ($class) {
  7. if (substr($class, 0, 10) !== 'ReCaptcha\\') {
  8. /* If the class does not lie under the "ReCaptcha" namespace,
  9. * then we can exit immediately.
  10. */
  11. return;
  12. }
  13. /* All of the classes have names like "ReCaptcha\Foo", so we need
  14. * to replace the backslashes with frontslashes if we want the
  15. * name to map directly to a location in the filesystem.
  16. */
  17. $class = str_replace('\\', '/', $class);
  18. /* First, check under the current directory. It is important that
  19. * we look here first, so that we don't waste time searching for
  20. * test classes in the common case.
  21. */
  22. $path = dirname(__FILE__).'/'.$class.'.php';
  23. if (is_readable($path)) {
  24. require_once $path;
  25. }
  26. /* If we didn't find what we're looking for already, maybe it's
  27. * a test class?
  28. */
  29. $path = dirname(__FILE__).'/../tests/'.$class.'.php';
  30. if (is_readable($path)) {
  31. require_once $path;
  32. }
  33. });