comparison vendor/sebastian/object-reflector/src/ObjectReflector.php @ 2:5311817fb629

Theme updates
author Chris Cannam
date Tue, 10 Jul 2018 13:19:18 +0000
parents
children
comparison
equal deleted inserted replaced
1:0b0e5f3b1e83 2:5311817fb629
1 <?php
2 /*
3 * This file is part of 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
11 declare(strict_types=1);
12
13 namespace SebastianBergmann\ObjectReflector;
14
15 class ObjectReflector
16 {
17 /**
18 * @param object $object
19 *
20 * @return array
21 *
22 * @throws InvalidArgumentException
23 */
24 public function getAttributes($object): array
25 {
26 if (!is_object($object)) {
27 throw new InvalidArgumentException;
28 }
29
30 $attributes = [];
31 $className = get_class($object);
32
33 foreach ((array) $object as $name => $value) {
34 $name = explode("\0", (string) $name);
35
36 if (count($name) === 1) {
37 $name = $name[0];
38 } else {
39 if ($name[1] !== $className) {
40 $name = $name[1] . '::' . $name[2];
41 } else {
42 $name = $name[2];
43 }
44 }
45
46 $attributes[$name] = $value;
47 }
48
49 return $attributes;
50 }
51 }