You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

StringHash.php 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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