Annotation.php
960 字节
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
<?php
namespace Lackoxygen\ShowDocGeneration\Annotations;
abstract class Annotation
{
public function __construct(array $values)
{
foreach ($this->getSelfProperties() as $property) {
if (isset($values[$property->getName()])) {
$this->{$property->getName()} = $values[$property->getName()];
}
}
}
/**
* @return mixed|\ReflectionProperty[]
*/
protected function getSelfProperties()
{
static $properties;
if (is_null($properties)) {
$ref = new \ReflectionClass($this);
$properties = $ref->getProperties();
}
return $properties;
}
/**
* @return array
*/
public function toArray(): array
{
$array = [];
foreach ($this->getSelfProperties() as $property) {
$array[$property->getName()] = $this->{$property->getName()};
}
return $array;
}
}