Mercurial > hg > isophonics-drupal-site
annotate vendor/sebastian/object-reflector/src/ObjectReflector.php @ 19:fa3358dc1485 tip
Add ndrum files
author | Chris Cannam |
---|---|
date | Wed, 28 Aug 2019 13:14:47 +0100 |
parents | 1fec387a4317 |
children |
rev | line source |
---|---|
Chris@14 | 1 <?php |
Chris@14 | 2 /* |
Chris@14 | 3 * This file is part of object-reflector. |
Chris@14 | 4 * |
Chris@14 | 5 * (c) Sebastian Bergmann <sebastian@phpunit.de> |
Chris@14 | 6 * |
Chris@14 | 7 * For the full copyright and license information, please view the LICENSE |
Chris@14 | 8 * file that was distributed with this source code. |
Chris@14 | 9 */ |
Chris@14 | 10 |
Chris@14 | 11 declare(strict_types=1); |
Chris@14 | 12 |
Chris@14 | 13 namespace SebastianBergmann\ObjectReflector; |
Chris@14 | 14 |
Chris@14 | 15 class ObjectReflector |
Chris@14 | 16 { |
Chris@14 | 17 /** |
Chris@14 | 18 * @param object $object |
Chris@14 | 19 * |
Chris@14 | 20 * @return array |
Chris@14 | 21 * |
Chris@14 | 22 * @throws InvalidArgumentException |
Chris@14 | 23 */ |
Chris@14 | 24 public function getAttributes($object): array |
Chris@14 | 25 { |
Chris@14 | 26 if (!is_object($object)) { |
Chris@14 | 27 throw new InvalidArgumentException; |
Chris@14 | 28 } |
Chris@14 | 29 |
Chris@14 | 30 $attributes = []; |
Chris@14 | 31 $className = get_class($object); |
Chris@14 | 32 |
Chris@14 | 33 foreach ((array) $object as $name => $value) { |
Chris@14 | 34 $name = explode("\0", (string) $name); |
Chris@14 | 35 |
Chris@14 | 36 if (count($name) === 1) { |
Chris@14 | 37 $name = $name[0]; |
Chris@14 | 38 } else { |
Chris@14 | 39 if ($name[1] !== $className) { |
Chris@14 | 40 $name = $name[1] . '::' . $name[2]; |
Chris@14 | 41 } else { |
Chris@14 | 42 $name = $name[2]; |
Chris@14 | 43 } |
Chris@14 | 44 } |
Chris@14 | 45 |
Chris@14 | 46 $attributes[$name] = $value; |
Chris@14 | 47 } |
Chris@14 | 48 |
Chris@14 | 49 return $attributes; |
Chris@14 | 50 } |
Chris@14 | 51 } |