Source for file DoctypeRegistry.php

Documentation is available at DoctypeRegistry.php

  1. <?php
  2.  
  3. {
  4.     
  5.     /**
  6.      * Hash of doctype names to doctype objects
  7.      */
  8.     protected $doctypes;
  9.     
  10.     /**
  11.      * Lookup table of aliases to real doctype names
  12.      */
  13.     protected $aliases;
  14.     
  15.     /**
  16.      * Registers a doctype to the registry
  17.      * @note Accepts a fully-formed doctype object, or the
  18.      *        parameters for constructing a doctype object
  19.      * @param $doctype Name of doctype or literal doctype object
  20.      * @param $modules Modules doctype will load
  21.      * @param $modules_for_modes Modules doctype will load for certain modes
  22.      * @param $aliases Alias names for doctype
  23.      * @return Editable registered doctype
  24.      */
  25.     public function register($doctype$xml true$modules array(),
  26.         $tidy_modules array()$aliases array()$dtd_public null$dtd_system null
  27.     {
  28.         if (!is_array($modules)) $modules array($modules);
  29.         if (!is_array($tidy_modules)) $tidy_modules array($tidy_modules);
  30.         if (!is_array($aliases)) $aliases array($aliases);
  31.         if (!is_object($doctype)) {
  32.             $doctype new HTMLPurifier_Doctype(
  33.                 $doctype$xml$modules$tidy_modules$aliases$dtd_public$dtd_system
  34.             );
  35.         }
  36.         $this->doctypes[$doctype->name$doctype;
  37.         $name $doctype->name;
  38.         // hookup aliases
  39.         foreach ($doctype->aliases as $alias{
  40.             if (isset($this->doctypes[$alias])) continue;
  41.             $this->aliases[$alias$name;
  42.         }
  43.         // remove old aliases
  44.         if (isset($this->aliases[$name])) unset($this->aliases[$name]);
  45.         return $doctype;
  46.     }
  47.     
  48.     /**
  49.      * Retrieves reference to a doctype of a certain name
  50.      * @note This function resolves aliases
  51.      * @note When possible, use the more fully-featured make()
  52.      * @param $doctype Name of doctype
  53.      * @return Editable doctype object
  54.      */
  55.     public function get($doctype{
  56.         if (isset($this->aliases[$doctype])) $doctype $this->aliases[$doctype];
  57.         if (!isset($this->doctypes[$doctype])) {
  58.             trigger_error('Doctype ' htmlspecialchars($doctype' does not exist'E_USER_ERROR);
  59.             $anon new HTMLPurifier_Doctype($doctype);
  60.             return $anon;
  61.         }
  62.         return $this->doctypes[$doctype];
  63.     }
  64.     
  65.     /**
  66.      * Creates a doctype based on a configuration object,
  67.      * will perform initialization on the doctype
  68.      * @note Use this function to get a copy of doctype that config
  69.      *        can hold on to (this is necessary in order to tell
  70.      *        Generator whether or not the current document is XML
  71.      *        based or not).
  72.      */
  73.     public function make($config{
  74.         return clone $this->get($this->getDoctypeFromConfig($config));
  75.     }
  76.     
  77.     /**
  78.      * Retrieves the doctype from the configuration object
  79.      */
  80.     public function getDoctypeFromConfig($config{
  81.         // recommended test
  82.         $doctype $config->get('HTML''Doctype');
  83.         if (!empty($doctype)) return $doctype;
  84.         $doctype $config->get('HTML''CustomDoctype');
  85.         if (!empty($doctype)) return $doctype;
  86.         // backwards-compatibility
  87.         if ($config->get('HTML''XHTML')) {
  88.             $doctype 'XHTML 1.0';
  89.         else {
  90.             $doctype 'HTML 4.01';
  91.         }
  92.         if ($config->get('HTML''Strict')) {
  93.             $doctype .= ' Strict';
  94.         else {
  95.             $doctype .= ' Transitional';
  96.         }
  97.         return $doctype;
  98.     }
  99.     
  100. }

Documentation generated on Thu, 19 Jun 2008 18:49:04 -0400 by phpDocumentor 1.4.2