-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnnotationReader.php
48 lines (45 loc) · 1.31 KB
/
AnnotationReader.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
<?php
/**
* Created by PhpStorm.
* User: erman.titiz
* Date: 29/09/16
* Time: 13:53
*/
namespace BiberLtd\Bundle\BaseEntityBundle;
use Doctrine\Common\Annotations\AnnotationReader AS AR;
class AnnotationReader extends AR
{
/**
* Get type of property from property declaration
*
* @param \ReflectionProperty $property
*
* @return null|string
*/
public function getPropertyType(\ReflectionProperty $property)
{
$doc = $property->getDocComment();
preg_match_all('#@(.*?)\n#s', $doc, $annotations);
if (isset($annotations[1])) {
foreach ($annotations[1] as $annotation) {
preg_match_all('#\s*(.*?)\s+#s', $annotation, $parts);
if (!isset($parts[1])) {
continue;
}
$declaration = $parts[1];
if (isset($declaration[0]) && $declaration[0] === 'var') {
if (isset($declaration[1])) {
if (substr($declaration[1], 0, 1) === '$') {
return null;
}
else {
return $declaration[1];
}
}
}
}
return null;
}
return $doc;
}
}