Autoloader.php 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. * @return boolean Returns true if the class has been loaded
  32. */
  33. static public function autoload($class)
  34. {
  35. if (0 !== strpos($class, 'Twig')) {
  36. return;
  37. }
  38. if (file_exists($file = dirname(__FILE__).'/../'.str_replace(array('_', "\0"), array('/', ''), $class).'.php')) {
  39. require $file;
  40. }
  41. }
  42. }