ObjectReflector.php 1014 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php declare(strict_types=1);
  2. /*
  3. * This file is part of sebastian/object-reflector.
  4. *
  5. * (c) Sebastian Bergmann <sebastian@phpunit.de>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace SebastianBergmann\ObjectReflector;
  11. use function count;
  12. use function explode;
  13. final class ObjectReflector
  14. {
  15. /**
  16. * @psalm-return array<string,mixed>
  17. */
  18. public function getProperties(object $object): array
  19. {
  20. $properties = [];
  21. $className = $object::class;
  22. foreach ((array) $object as $name => $value) {
  23. $name = explode("\0", (string) $name);
  24. if (count($name) === 1) {
  25. $name = $name[0];
  26. } elseif ($name[1] !== $className) {
  27. $name = $name[1] . '::' . $name[2];
  28. } else {
  29. $name = $name[2];
  30. }
  31. $properties[$name] = $value;
  32. }
  33. return $properties;
  34. }
  35. }