Autoloader.php 977B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /*
  3. * This file is part of Twig.
  4. *
  5. * (c) 2009 Fabien Potencier
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. /**
  11. * Autoloads Twig classes.
  12. *
  13. * @package twig
  14. * @author Fabien Potencier <fabien@symfony.com>
  15. */
  16. class Twig_Autoloader
  17. {
  18. /**
  19. * Registers Twig_Autoloader as an SPL autoloader.
  20. */
  21. static public function register()
  22. {
  23. ini_set('unserialize_callback_func', 'spl_autoload_call');
  24. spl_autoload_register(array(new self, 'autoload'));
  25. }
  26. /**
  27. * Handles autoloading of classes.
  28. *
  29. * @param string $class A class name.
  30. */
  31. static public function autoload($class)
  32. {
  33. if (0 !== strpos($class, 'Twig')) {
  34. return;
  35. }
  36. if (is_file($file = dirname(__FILE__).'/../'.str_replace(array('_', "\0"), array('/', ''), $class).'.php')) {
  37. require $file;
  38. }
  39. }
  40. }