NestedArrayAccessTrait.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * @package Grav\Framework\Object
  4. *
  5. * @copyright Copyright (c) 2015 - 2023 Trilby Media, LLC. All rights reserved.
  6. * @license MIT License; see LICENSE file for details.
  7. */
  8. namespace Grav\Framework\Object\Access;
  9. /**
  10. * Nested ArrayAccess Object Trait
  11. * @package Grav\Framework\Object
  12. */
  13. trait NestedArrayAccessTrait
  14. {
  15. /**
  16. * Whether or not an offset exists.
  17. *
  18. * @param mixed $offset An offset to check for.
  19. * @return bool Returns TRUE on success or FALSE on failure.
  20. */
  21. #[\ReturnTypeWillChange]
  22. public function offsetExists($offset)
  23. {
  24. return $this->hasNestedProperty($offset);
  25. }
  26. /**
  27. * Returns the value at specified offset.
  28. *
  29. * @param mixed $offset The offset to retrieve.
  30. * @return mixed Can return all value types.
  31. */
  32. #[\ReturnTypeWillChange]
  33. public function offsetGet($offset)
  34. {
  35. return $this->getNestedProperty($offset);
  36. }
  37. /**
  38. * Assigns a value to the specified offset.
  39. *
  40. * @param mixed $offset The offset to assign the value to.
  41. * @param mixed $value The value to set.
  42. * @return void
  43. */
  44. #[\ReturnTypeWillChange]
  45. public function offsetSet($offset, $value)
  46. {
  47. $this->setNestedProperty($offset, $value);
  48. }
  49. /**
  50. * Unsets an offset.
  51. *
  52. * @param mixed $offset The offset to unset.
  53. * @return void
  54. */
  55. #[\ReturnTypeWillChange]
  56. public function offsetUnset($offset)
  57. {
  58. $this->unsetNestedProperty($offset);
  59. }
  60. }