StringHash.php 975 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /**
  3. * This is in almost every respect equivalent to an array except
  4. * that it keeps track of which keys were accessed.
  5. *
  6. * @warning For the sake of backwards compatibility with early versions
  7. * of PHP 5, you must not use the $hash[$key] syntax; if you do
  8. * our version of offsetGet is never called.
  9. */
  10. class HTMLPurifier_StringHash extends ArrayObject
  11. {
  12. protected $accessed = array();
  13. /**
  14. * Retrieves a value, and logs the access.
  15. */
  16. public function offsetGet($index) {
  17. $this->accessed[$index] = true;
  18. return parent::offsetGet($index);
  19. }
  20. /**
  21. * Returns a lookup array of all array indexes that have been accessed.
  22. * @return Array in form array($index => true).
  23. */
  24. public function getAccessed() {
  25. return $this->accessed;
  26. }
  27. /**
  28. * Resets the access array.
  29. */
  30. public function resetAccessed() {
  31. $this->accessed = array();
  32. }
  33. }
  34. // vim: et sw=4 sts=4