StringHash.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. /**
  13. * @type array
  14. */
  15. protected $accessed = array();
  16. /**
  17. * Retrieves a value, and logs the access.
  18. * @param mixed $index
  19. * @return mixed
  20. */
  21. public function offsetGet($index)
  22. {
  23. $this->accessed[$index] = true;
  24. return parent::offsetGet($index);
  25. }
  26. /**
  27. * Returns a lookup array of all array indexes that have been accessed.
  28. * @return array in form array($index => true).
  29. */
  30. public function getAccessed()
  31. {
  32. return $this->accessed;
  33. }
  34. /**
  35. * Resets the access array.
  36. */
  37. public function resetAccessed()
  38. {
  39. $this->accessed = array();
  40. }
  41. }
  42. // vim: et sw=4 sts=4