Source for file Bootstrap.php

Documentation is available at Bootstrap.php

  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_OS03))) {
  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.  
  23. /**
  24.  * Bootstrap class that contains meta-functionality for HTML Purifier such as
  25.  * the autoload function.
  26.  *
  27.  * @note
  28.  *       This class may be used without any other files from HTML Purifier.
  29.  */
  30. {
  31.     
  32.     /**
  33.      * Autoload function for HTML Purifier
  34.      * @param $class Class to load
  35.      */
  36.     public static function autoload($class{
  37.         $file HTMLPurifier_Bootstrap::getPath($class);
  38.         if (!$filereturn false;
  39.         require HTMLPURIFIER_PREFIX '/' $file;
  40.         return true;
  41.     }
  42.     
  43.     /**
  44.      * Returns the path for a specific class.
  45.      */
  46.     public static function getPath($class{
  47.         if (strncmp('HTMLPurifier'$class12!== 0return false;
  48.         // Custom implementations
  49.         if (strncmp('HTMLPurifier_Language_'$class22=== 0{
  50.             $code str_replace('_''-'substr($class22));
  51.             $file 'HTMLPurifier/Language/classes/' $code '.php';
  52.         else {
  53.             $file str_replace('_''/'$class'.php';
  54.         }
  55.         if (!file_exists(HTMLPURIFIER_PREFIX '/' $file)) return false;
  56.         return $file;
  57.     }
  58.     
  59.     /**
  60.      * "Pre-registers" our autoloader on the SPL stack.
  61.      */
  62.     public static function registerAutoload({
  63.         $autoload array('HTMLPurifier_Bootstrap''autoload');
  64.         if ( ($funcs spl_autoload_functions()) === false {
  65.             spl_autoload_register($autoload);
  66.         elseif (function_exists('spl_autoload_unregister')) {
  67.             $compat version_compare(PHP_VERSION'5.1.2''<='&&
  68.                       version_compare(PHP_VERSION'5.1.0''>=');
  69.             foreach ($funcs as $func{
  70.                 if (is_array($func)) {
  71.                     // :TRICKY: There are some compatibility issues and some
  72.                     // places where we need to error out
  73.                     $reflector new ReflectionMethod($func[0]$func[1]);
  74.                     if (!$reflector->isStatic()) {
  75.                         throw new Exception('
  76.                             HTML Purifier autoloader registrar is not compatible
  77.                             with non-static object methods due to PHP Bug #44144;
  78.                             Please do not use HTMLPurifier.autoload.php (or any
  79.                             file that includes this file); instead, place the code:
  80.                             spl_autoload_register(array(\'HTMLPurifier_Bootstrap\', \'autoload\'))
  81.                             after your own autoloaders.
  82.                         ');
  83.                     }
  84.                     // Suprisingly, spl_autoload_register supports the
  85.                     // Class::staticMethod callback format, although call_user_func doesn't
  86.                     if ($compat$func implode('::'$func);
  87.                 }
  88.                 spl_autoload_unregister($func);
  89.             }
  90.             spl_autoload_register($autoload);
  91.             foreach ($funcs as $funcspl_autoload_register($func);
  92.         }
  93.     }
  94.     
  95. }

Documentation generated on Thu, 19 Jun 2008 18:48:54 -0400 by phpDocumentor 1.4.2