forked from guzzle/guzzle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Helpers.php
35 lines (28 loc) · 940 Bytes
/
Helpers.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
namespace GuzzleHttp\Tests;
class Helpers
{
public static function readObjectAttribute(object $object, string $attributeName)
{
$reflector = new \ReflectionObject($object);
do {
try {
$attribute = $reflector->getProperty($attributeName);
if (!$attribute || $attribute->isPublic()) {
return $object->$attributeName;
}
$attribute->setAccessible(true);
try {
return $attribute->getValue($object);
} finally {
$attribute->setAccessible(false);
}
} catch (\ReflectionException $e) {
// do nothing
}
} while ($reflector = $reflector->getParentClass());
throw new \Exception(
sprintf('Attribute "%s" not found in object.', $attributeName)
);
}
}