EntityLookup.php 1.3 KB

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