EntityLookup.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * Object that provides entity lookup table from entity name to character
  4. */
  5. class HTMLPurifier_EntityLookup
  6. {
  7. /**
  8. * Assoc array of entity name to character represented.
  9. * @type array
  10. */
  11. public $table;
  12. /**
  13. * Sets up the entity lookup table from the serialized file contents.
  14. * @param bool $file
  15. * @note The serialized contents are versioned, but were generated
  16. * using the maintenance script generate_entity_file.php
  17. * @warning This is not in constructor to help enforce the Singleton
  18. */
  19. public function setup($file = false)
  20. {
  21. if (!$file) {
  22. $file = HTMLPURIFIER_PREFIX . '/HTMLPurifier/EntityLookup/entities.ser';
  23. }
  24. $this->table = unserialize(file_get_contents($file));
  25. }
  26. /**
  27. * Retrieves sole instance of the object.
  28. * @param bool|HTMLPurifier_EntityLookup $prototype Optional prototype of custom lookup table to overload with.
  29. * @return HTMLPurifier_EntityLookup
  30. */
  31. public static function instance($prototype = false)
  32. {
  33. // no references, since PHP doesn't copy unless modified
  34. static $instance = null;
  35. if ($prototype) {
  36. $instance = $prototype;
  37. } elseif (!$instance) {
  38. $instance = new HTMLPurifier_EntityLookup();
  39. $instance->setup();
  40. }
  41. return $instance;
  42. }
  43. }
  44. // vim: et sw=4 sts=4