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