/dompdf/include/autoload.inc.php

http://dompdf.googlecode.com/ · PHP · 87 lines · 42 code · 13 blank · 32 comment · 14 complexity · 7db56df6bbbb5248cd44eeff67eb82f4 MD5 · raw file

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