autoload.inc.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * @package dompdf
  4. * @link http://dompdf.github.com/
  5. * @author Benj Carson <benjcarson@digitaljunkies.ca>
  6. * @author Fabien Ménager <fabien.menager@gmail.com>
  7. * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
  8. */
  9. /**
  10. * DOMPDF autoload function
  11. *
  12. * If you have an existing autoload function, add a call to this function
  13. * from your existing __autoload() implementation.
  14. *
  15. * @param string $class
  16. */
  17. function DOMPDF_autoload($class) {
  18. $filename = DOMPDF_INC_DIR . "/" . mb_strtolower($class) . ".cls.php";
  19. if ( is_file($filename) ) {
  20. include_once $filename;
  21. }
  22. }
  23. // If SPL autoload functions are available (PHP >= 5.1.2)
  24. if ( function_exists("spl_autoload_register") ) {
  25. $autoload = "DOMPDF_autoload";
  26. $funcs = spl_autoload_functions();
  27. // No functions currently in the stack.
  28. if ( !DOMPDF_AUTOLOAD_PREPEND || $funcs === false ) {
  29. spl_autoload_register($autoload);
  30. }
  31. // If PHP >= 5.3 the $prepend argument is available
  32. else if ( PHP_VERSION_ID >= 50300 ) {
  33. spl_autoload_register($autoload, true, true);
  34. }
  35. else {
  36. // Unregister existing autoloaders...
  37. $compat = (PHP_VERSION_ID <= 50102 && PHP_VERSION_ID >= 50100);
  38. foreach ($funcs as $func) {
  39. if (is_array($func)) {
  40. // :TRICKY: There are some compatibility issues and some
  41. // places where we need to error out
  42. $reflector = new ReflectionMethod($func[0], $func[1]);
  43. if (!$reflector->isStatic()) {
  44. throw new Exception('This function is not compatible with non-static object methods due to PHP Bug #44144.');
  45. }
  46. // Suprisingly, spl_autoload_register supports the
  47. // Class::staticMethod callback format, although call_user_func doesn't
  48. if ($compat) $func = implode('::', $func);
  49. }
  50. spl_autoload_unregister($func);
  51. }
  52. // Register the new one, thus putting it at the front of the stack...
  53. spl_autoload_register($autoload);
  54. // Now, go back and re-register all of our old ones.
  55. foreach ($funcs as $func) {
  56. spl_autoload_register($func);
  57. }
  58. // Be polite and ensure that userland autoload gets retained
  59. if ( function_exists("__autoload") ) {
  60. spl_autoload_register("__autoload");
  61. }
  62. }
  63. }
  64. else if ( !function_exists("__autoload") ) {
  65. /**
  66. * Default __autoload() function
  67. *
  68. * @param string $class
  69. */
  70. function __autoload($class) {
  71. DOMPDF_autoload($class);
  72. }
  73. }