NestedArrayAccessWithGetters.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace RocketTheme\Toolbox\ArrayTraits;
  3. /**
  4. * Implements getters and setters.
  5. *
  6. * @package RocketTheme\Toolbox\ArrayTraits
  7. * @author RocketTheme
  8. * @license MIT
  9. */
  10. trait NestedArrayAccessWithGetters
  11. {
  12. use NestedArrayAccess;
  13. /**
  14. * Magic setter method
  15. *
  16. * @param mixed $offset Asset name value
  17. * @param mixed $value Asset value
  18. */
  19. public function __set($offset, $value)
  20. {
  21. $this->offsetSet($offset, $value);
  22. }
  23. /**
  24. * Magic getter method
  25. *
  26. * @param mixed $offset Asset name value
  27. * @return mixed Asset value
  28. */
  29. public function __get($offset)
  30. {
  31. return $this->offsetGet($offset);
  32. }
  33. /**
  34. * Magic method to determine if the attribute is set
  35. *
  36. * @param mixed $offset Asset name value
  37. * @return boolean True if the value is set
  38. */
  39. public function __isset($offset)
  40. {
  41. return $this->offsetExists($offset);
  42. }
  43. /**
  44. * Magic method to unset the attribute
  45. *
  46. * @param mixed $offset The name value to unset
  47. */
  48. public function __unset($offset)
  49. {
  50. $this->offsetUnset($offset);
  51. }
  52. }