StringHash.php 1.1 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. #[\ReturnTypeWillChange]
  22. public function offsetGet($index)
  23. {
  24. $this->accessed[$index] = true;
  25. return parent::offsetGet($index);
  26. }
  27. /**
  28. * Returns a lookup array of all array indexes that have been accessed.
  29. * @return array in form array($index => true).
  30. */
  31. public function getAccessed()
  32. {
  33. return $this->accessed;
  34. }
  35. /**
  36. * Resets the access array.
  37. */
  38. public function resetAccessed()
  39. {
  40. $this->accessed = array();
  41. }
  42. }
  43. // vim: et sw=4 sts=4