-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReflectionExtractor.php
More file actions
46 lines (35 loc) · 1.11 KB
/
ReflectionExtractor.php
File metadata and controls
46 lines (35 loc) · 1.11 KB
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
36
37
38
39
40
41
42
43
44
45
46
<?php
declare(strict_types=1);
namespace TinyBlocks\Mapper\Internal\Extractors;
use ReflectionClass;
use ReflectionProperty;
final readonly class ReflectionExtractor
{
public function extractProperties(object $object): array
{
$reflection = new ReflectionClass(objectOrClass: $object);
$properties = $reflection->getProperties(
ReflectionProperty::IS_PUBLIC
| ReflectionProperty::IS_PROTECTED
| ReflectionProperty::IS_PRIVATE
);
$extracted = [];
foreach ($properties as $property) {
if ($property->isStatic()) {
continue;
}
$name = $property->getName();
$extracted[$name] = $property->getValue(object: $object);
}
return $extracted;
}
public function extractConstructorParameters(string $class): array
{
$reflection = new ReflectionClass(objectOrClass: $class);
$constructor = $reflection->getConstructor();
if ($constructor === null) {
return [];
}
return $constructor->getParameters();
}
}