Autoloader.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. @trigger_error('The Twig_Autoloader class is deprecated since version 1.21 and will be removed in 2.0. Use Composer instead.', E_USER_DEPRECATED);
  11. /**
  12. * Autoloads Twig classes.
  13. *
  14. * @author Fabien Potencier <fabien@symfony.com>
  15. *
  16. * @deprecated since 1.21 and will be removed in 2.0. Use Composer instead. 2.0.
  17. */
  18. class Twig_Autoloader
  19. {
  20. /**
  21. * Registers Twig_Autoloader as an SPL autoloader.
  22. *
  23. * @param bool $prepend Whether to prepend the autoloader or not.
  24. */
  25. public static function register($prepend = false)
  26. {
  27. @trigger_error('Using Twig_Autoloader is deprecated since version 1.21. Use Composer instead.', E_USER_DEPRECATED);
  28. if (PHP_VERSION_ID < 50300) {
  29. spl_autoload_register(array(__CLASS__, 'autoload'));
  30. } else {
  31. spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend);
  32. }
  33. }
  34. /**
  35. * Handles autoloading of classes.
  36. *
  37. * @param string $class A class name.
  38. */
  39. public static function autoload($class)
  40. {
  41. if (0 !== strpos($class, 'Twig')) {
  42. return;
  43. }
  44. if (is_file($file = dirname(__FILE__).'/../'.str_replace(array('_', "\0"), array('/', ''), $class).'.php')) {
  45. require $file;
  46. }
  47. }
  48. }