Blame view

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