OverloadedPropertyTrait.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. * Overloaded Property Object Trait
  11. * @package Grav\Framework\Object\Access
  12. */
  13. trait OverloadedPropertyTrait
  14. {
  15. /**
  16. * Checks 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 __isset($offset)
  23. {
  24. return $this->hasProperty($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 __get($offset)
  34. {
  35. return $this->getProperty($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 __set($offset, $value)
  46. {
  47. $this->setProperty($offset, $value);
  48. }
  49. /**
  50. * Magic method to unset the attribute
  51. *
  52. * @param mixed $offset The name value to unset
  53. * @return void
  54. */
  55. #[\ReturnTypeWillChange]
  56. public function __unset($offset)
  57. {
  58. $this->unsetProperty($offset);
  59. }
  60. }