forked from symfony/property-info
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PropertyInfoExtractor.php
121 lines (107 loc) · 3.42 KB
/
PropertyInfoExtractor.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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\PropertyInfo;
/**
* Default {@see PropertyInfoExtractorInterface} implementation.
*
* @author Kévin Dunglas <[email protected]>
*/
class PropertyInfoExtractor implements PropertyInfoExtractorInterface
{
/**
* @var PropertyListExtractorInterface[]
*/
private $listExtractors;
/**
* @var PropertyTypeExtractorInterface[]
*/
private $typeExtractors;
/**
* @var PropertyDescriptionExtractorInterface[]
*/
private $descriptionExtractors;
/**
* @var PropertyAccessExtractorInterface[]
*/
private $accessExtractors;
/**
* @param PropertyListExtractorInterface[] $listExtractors
* @param PropertyTypeExtractorInterface[] $typeExtractors
* @param PropertyDescriptionExtractorInterface[] $descriptionExtractors
* @param PropertyAccessExtractorInterface[] $accessExtractors
*/
public function __construct(array $listExtractors = array(), array $typeExtractors = array(), array $descriptionExtractors = array(), array $accessExtractors = array())
{
$this->listExtractors = $listExtractors;
$this->typeExtractors = $typeExtractors;
$this->descriptionExtractors = $descriptionExtractors;
$this->accessExtractors = $accessExtractors;
}
/**
* {@inheritdoc}
*/
public function getProperties($class, array $context = array())
{
return $this->extract($this->listExtractors, 'getProperties', array($class, $context));
}
/**
* {@inheritdoc}
*/
public function getShortDescription($class, $property, array $context = array())
{
return $this->extract($this->descriptionExtractors, 'getShortDescription', array($class, $property, $context));
}
/**
* {@inheritdoc}
*/
public function getLongDescription($class, $property, array $context = array())
{
return $this->extract($this->descriptionExtractors, 'getLongDescription', array($class, $property, $context));
}
/**
* {@inheritdoc}
*/
public function getTypes($class, $property, array $context = array())
{
return $this->extract($this->typeExtractors, 'getTypes', array($class, $property, $context));
}
/**
* {@inheritdoc}
*/
public function isReadable($class, $property, array $context = array())
{
return $this->extract($this->accessExtractors, 'isReadable', array($class, $property, $context));
}
/**
* {@inheritdoc}
*/
public function isWritable($class, $property, array $context = array())
{
return $this->extract($this->accessExtractors, 'isWritable', array($class, $property, $context));
}
/**
* Iterates over registered extractors and return the first value found.
*
* @param array $extractors
* @param string $method
* @param array $arguments
*
* @return mixed
*/
private function extract(array $extractors, $method, array $arguments)
{
foreach ($extractors as $extractor) {
$value = \call_user_func_array(array($extractor, $method), $arguments);
if (null !== $value) {
return $value;
}
}
}
}