-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathParametersTrait.php
More file actions
86 lines (64 loc) · 2.1 KB
/
ParametersTrait.php
File metadata and controls
86 lines (64 loc) · 2.1 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
declare(strict_types=1);
namespace Atlas\Transit\Reflection;
use ReflectionClass;
trait ParametersTrait
{
protected $parameterCount = 0;
protected $parameters = [];
protected $properties = [];
protected $fromDomainToSource = [];
protected $types = [];
protected $classes = [];
protected function setParameters(
ReflectionClass $r,
ReflectionLocator $reflectionLocator
) {
$inflector = $reflectionLocator->getInflector();
$this->parameters = [];
$this->properties = [];
$this->fromDomainToSource = [];
$rparams = $r->getMethod('__construct')->getParameters();
foreach ($rparams as $rparam) {
$name = $rparam->getName();
$this->parameters[$name] = $rparam;
$found = preg_match(
'/^\s*\*\s*@Atlas\\\\Transit\\\\Parameter[ \t]+\$?' . $name . '[ \t]+\$?(.*)/m',
$this->docComment,
$matches
);
if ($found === 1) {
$field = $matches[1];
} else {
$field = $inflector->fromDomainToSource($name);
}
$this->fromDomainToSource[$name] = $field;
if ($r->hasProperty($name)) {
$rprop = $r->getProperty($name);
$rprop->setAccessible(true);
$this->properties[$name] = $rprop;
}
$this->types[$name] = null;
$this->classes[$name] = null;
$type = $rparam->getType();
$class = null !== $type && !$type->isBuiltin() ? $type->getName() : null;
if ($class !== null) {
$this->classes[$name] = $class;
continue;
}
if ($type === null) {
continue;
}
$this->types[$name] = $type->getName();
}
$this->parameterCount = count($this->parameters);
}
public function getFirstParameter()
{
return reset($this->parameters);
}
public function getFirstProperty()
{
return reset($this->properties);
}
}