]> git.immae.eu Git - github/wallabag/wallabag.git/blame - inc/3rdparty/htmlpurifier/HTMLPurifier/Bootstrap.php
remove autoload section in composer.json
[github/wallabag/wallabag.git] / inc / 3rdparty / htmlpurifier / HTMLPurifier / Bootstrap.php
CommitLineData
d4949327
NL
1<?php\r
2\r
3// constants are slow, so we use as few as possible\r
4if (!defined('HTMLPURIFIER_PREFIX')) {\r
5 define('HTMLPURIFIER_PREFIX', realpath(dirname(__FILE__) . '/..'));\r
6}\r
7\r
8// accomodations for versions earlier than 5.0.2\r
9// borrowed from PHP_Compat, LGPL licensed, by Aidan Lister <aidan@php.net>\r
10if (!defined('PHP_EOL')) {\r
11 switch (strtoupper(substr(PHP_OS, 0, 3))) {\r
12 case 'WIN':\r
13 define('PHP_EOL', "\r\n");\r
14 break;\r
15 case 'DAR':\r
16 define('PHP_EOL', "\r");\r
17 break;\r
18 default:\r
19 define('PHP_EOL', "\n");\r
20 }\r
21}\r
22\r
23/**\r
24 * Bootstrap class that contains meta-functionality for HTML Purifier such as\r
25 * the autoload function.\r
26 *\r
27 * @note\r
28 * This class may be used without any other files from HTML Purifier.\r
29 */\r
30class HTMLPurifier_Bootstrap\r
31{\r
32\r
33 /**\r
34 * Autoload function for HTML Purifier\r
35 * @param string $class Class to load\r
36 * @return bool\r
37 */\r
38 public static function autoload($class)\r
39 {\r
40 $file = HTMLPurifier_Bootstrap::getPath($class);\r
41 if (!$file) {\r
42 return false;\r
43 }\r
44 // Technically speaking, it should be ok and more efficient to\r
45 // just do 'require', but Antonio Parraga reports that with\r
46 // Zend extensions such as Zend debugger and APC, this invariant\r
47 // may be broken. Since we have efficient alternatives, pay\r
48 // the cost here and avoid the bug.\r
49 require_once HTMLPURIFIER_PREFIX . '/' . $file;\r
50 return true;\r
51 }\r
52\r
53 /**\r
54 * Returns the path for a specific class.\r
55 * @param string $class Class path to get\r
56 * @return string\r
57 */\r
58 public static function getPath($class)\r
59 {\r
60 if (strncmp('HTMLPurifier', $class, 12) !== 0) {\r
61 return false;\r
62 }\r
63 // Custom implementations\r
64 if (strncmp('HTMLPurifier_Language_', $class, 22) === 0) {\r
65 $code = str_replace('_', '-', substr($class, 22));\r
66 $file = 'HTMLPurifier/Language/classes/' . $code . '.php';\r
67 } else {\r
68 $file = str_replace('_', '/', $class) . '.php';\r
69 }\r
70 if (!file_exists(HTMLPURIFIER_PREFIX . '/' . $file)) {\r
71 return false;\r
72 }\r
73 return $file;\r
74 }\r
75\r
76 /**\r
77 * "Pre-registers" our autoloader on the SPL stack.\r
78 */\r
79 public static function registerAutoload()\r
80 {\r
81 $autoload = array('HTMLPurifier_Bootstrap', 'autoload');\r
82 if (($funcs = spl_autoload_functions()) === false) {\r
83 spl_autoload_register($autoload);\r
84 } elseif (function_exists('spl_autoload_unregister')) {\r
85 if (version_compare(PHP_VERSION, '5.3.0', '>=')) {\r
86 // prepend flag exists, no need for shenanigans\r
87 spl_autoload_register($autoload, true, true);\r
88 } else {\r
89 $buggy = version_compare(PHP_VERSION, '5.2.11', '<');\r
90 $compat = version_compare(PHP_VERSION, '5.1.2', '<=') &&\r
91 version_compare(PHP_VERSION, '5.1.0', '>=');\r
92 foreach ($funcs as $func) {\r
93 if ($buggy && is_array($func)) {\r
94 // :TRICKY: There are some compatibility issues and some\r
95 // places where we need to error out\r
96 $reflector = new ReflectionMethod($func[0], $func[1]);\r
97 if (!$reflector->isStatic()) {\r
98 throw new Exception(\r
99 'HTML Purifier autoloader registrar is not compatible\r
100 with non-static object methods due to PHP Bug #44144;\r
101 Please do not use HTMLPurifier.autoload.php (or any\r
102 file that includes this file); instead, place the code:\r
103 spl_autoload_register(array(\'HTMLPurifier_Bootstrap\', \'autoload\'))\r
104 after your own autoloaders.'\r
105 );\r
106 }\r
107 // Suprisingly, spl_autoload_register supports the\r
108 // Class::staticMethod callback format, although call_user_func doesn't\r
109 if ($compat) {\r
110 $func = implode('::', $func);\r
111 }\r
112 }\r
113 spl_autoload_unregister($func);\r
114 }\r
115 spl_autoload_register($autoload);\r
116 foreach ($funcs as $func) {\r
117 spl_autoload_register($func);\r
118 }\r
119 }\r
120 }\r
121 }\r
122}\r
123\r
124// vim: et sw=4 sts=4\r