ProxyArrayAccessToProperties.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. declare(strict_types=1);
  3. namespace League\Flysystem;
  4. use RuntimeException;
  5. /**
  6. * @internal
  7. */
  8. trait ProxyArrayAccessToProperties
  9. {
  10. private function formatPropertyName(string $offset): string
  11. {
  12. return str_replace('_', '', lcfirst(ucwords($offset, '_')));
  13. }
  14. /**
  15. * @param mixed $offset
  16. *
  17. * @return bool
  18. */
  19. public function offsetExists($offset): bool
  20. {
  21. $property = $this->formatPropertyName((string) $offset);
  22. return isset($this->{$property});
  23. }
  24. /**
  25. * @param mixed $offset
  26. *
  27. * @return mixed
  28. */
  29. #[\ReturnTypeWillChange]
  30. public function offsetGet($offset)
  31. {
  32. $property = $this->formatPropertyName((string) $offset);
  33. return $this->{$property};
  34. }
  35. /**
  36. * @param mixed $offset
  37. * @param mixed $value
  38. */
  39. #[\ReturnTypeWillChange]
  40. public function offsetSet($offset, $value): void
  41. {
  42. throw new RuntimeException('Properties can not be manipulated');
  43. }
  44. /**
  45. * @param mixed $offset
  46. */
  47. #[\ReturnTypeWillChange]
  48. public function offsetUnset($offset): void
  49. {
  50. throw new RuntimeException('Properties can not be manipulated');
  51. }
  52. }