Autoloader.php 899 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace Dompdf;
  3. /**
  4. * Autoloads Dompdf classes
  5. *
  6. * @package Dompdf
  7. */
  8. class Autoloader
  9. {
  10. const PREFIX = 'Dompdf';
  11. /**
  12. * Register the autoloader
  13. */
  14. public static function register()
  15. {
  16. spl_autoload_register([new self, 'autoload']);
  17. }
  18. /**
  19. * Autoloader
  20. *
  21. * @param string
  22. */
  23. public static function autoload($class)
  24. {
  25. if ($class === 'Dompdf\Cpdf') {
  26. require_once __DIR__ . "/../lib/Cpdf.php";
  27. return;
  28. }
  29. $prefixLength = strlen(self::PREFIX);
  30. if (0 === strncmp(self::PREFIX, $class, $prefixLength)) {
  31. $file = str_replace('\\', '/', substr($class, $prefixLength));
  32. $file = realpath(__DIR__ . (empty($file) ? '' : '/') . $file . '.php');
  33. if (file_exists($file)) {
  34. require_once $file;
  35. }
  36. }
  37. }
  38. }