Advertisement
xThomas

./lib/PhpOffice/PhpWord/Autoloader.php

Dec 20th, 2024
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | Source Code | 0 0
  1. <?php
  2.  
  3. namespace PhpOffice\PhpWord;
  4.  
  5. /**
  6. * Custom Autoloader for PHPWord
  7. */
  8. class Autoloader
  9. {
  10. const BASE_DIR = __DIR__;
  11.  
  12. /**
  13. * Register the autoloader
  14. */
  15. public static function register()
  16. {
  17. spl_autoload_register([new self, 'autoload']);
  18. }
  19.  
  20. /**
  21. * Autoload function
  22. */
  23. public static function autoload($class)
  24. {
  25. $prefix = "PhpOffice\\PhpWord\\";
  26. $baseDir = self::BASE_DIR . DIRECTORY_SEPARATOR;
  27.  
  28. if (strpos($class, $prefix) !== 0) {
  29. return false;
  30. }
  31.  
  32. $relativeClass = substr($class, strlen($prefix));
  33. $file = $baseDir . str_replace("\\", DIRECTORY_SEPARATOR, $relativeClass) . ".php";
  34.  
  35. if (file_exists($file)) {
  36. require_once $file;
  37. } else {
  38. die("Class $class not found in $file");
  39. }
  40. }
  41. }
Tags: php phpWord
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement