ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
Bootstrap.php
Go to the documentation of this file.
1 <?php
2 
3 // constants are slow, so we use as few as possible
4 if (!defined('HTMLPURIFIER_PREFIX')) {
5  define('HTMLPURIFIER_PREFIX', realpath(dirname(__FILE__) . '/..'));
6 }
7 
8 // accomodations for versions earlier than 5.0.2
9 // borrowed from PHP_Compat, LGPL licensed, by Aidan Lister <aidan@php.net>
10 if (!defined('PHP_EOL')) {
11  switch (strtoupper(substr(PHP_OS, 0, 3))) {
12  case 'WIN':
13  define('PHP_EOL', "\r\n");
14  break;
15  case 'DAR':
16  define('PHP_EOL', "\r");
17  break;
18  default:
19  define('PHP_EOL', "\n");
20  }
21 }
22 
31 {
32 
37  public static function autoload($class) {
39  if (!$file) return false;
40  // Technically speaking, it should be ok and more efficient to
41  // just do 'require', but Antonio Parraga reports that with
42  // Zend extensions such as Zend debugger and APC, this invariant
43  // may be broken. Since we have efficient alternatives, pay
44  // the cost here and avoid the bug.
45  require_once HTMLPURIFIER_PREFIX . '/' . $file;
46  return true;
47  }
48 
52  public static function getPath($class) {
53  if (strncmp('HTMLPurifier', $class, 12) !== 0) return false;
54  // Custom implementations
55  if (strncmp('HTMLPurifier_Language_', $class, 22) === 0) {
56  $code = str_replace('_', '-', substr($class, 22));
57  $file = 'HTMLPurifier/Language/classes/' . $code . '.php';
58  } else {
59  $file = str_replace('_', '/', $class) . '.php';
60  }
61  if (!file_exists(HTMLPURIFIER_PREFIX . '/' . $file)) return false;
62  return $file;
63  }
64 
68  public static function registerAutoload() {
69  $autoload = array('HTMLPurifier_Bootstrap', 'autoload');
70  if ( ($funcs = spl_autoload_functions()) === false ) {
71  spl_autoload_register($autoload);
72  } elseif (function_exists('spl_autoload_unregister')) {
73  $buggy = version_compare(PHP_VERSION, '5.2.11', '<');
74  $compat = version_compare(PHP_VERSION, '5.1.2', '<=') &&
75  version_compare(PHP_VERSION, '5.1.0', '>=');
76  foreach ($funcs as $func) {
77  if ($buggy && is_array($func)) {
78  // :TRICKY: There are some compatibility issues and some
79  // places where we need to error out
80  $reflector = new ReflectionMethod($func[0], $func[1]);
81  if (!$reflector->isStatic()) {
82  throw new Exception('
83  HTML Purifier autoloader registrar is not compatible
84  with non-static object methods due to PHP Bug #44144;
85  Please do not use HTMLPurifier.autoload.php (or any
86  file that includes this file); instead, place the code:
87  spl_autoload_register(array(\'HTMLPurifier_Bootstrap\', \'autoload\'))
88  after your own autoloaders.
89  ');
90  }
91  // Suprisingly, spl_autoload_register supports the
92  // Class::staticMethod callback format, although call_user_func doesn't
93  if ($compat) $func = implode('::', $func);
94  }
95  spl_autoload_unregister($func);
96  }
97  spl_autoload_register($autoload);
98  foreach ($funcs as $func) spl_autoload_register($func);
99  }
100  }
101 
102 }
103 
104 // vim: et sw=4 sts=4