|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Ubiquity\orm\parser; |
|
4
|
|
|
|
|
5
|
|
|
trait ReflexionFieldsTrait { |
|
6
|
|
|
|
|
7
|
|
|
abstract public static function getAnnotationMember($class, $member, $annotation); |
|
8
|
|
|
|
|
9
|
|
|
abstract public static function getAnnotsEngine(); |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* |
|
13
|
|
|
* @param string $class |
|
14
|
|
|
* @param string $member |
|
15
|
|
|
* @return object|boolean |
|
16
|
|
|
*/ |
|
17
|
47 |
|
protected static function getAnnotationColumnMember($class, $member) { |
|
18
|
47 |
|
if (($r = self::getAnnotationMember ( $class, $member, 'column' )) === false) { |
|
19
|
47 |
|
$r = self::getAnnotationMember ( $class, $member, 'joinColumn' ); |
|
20
|
|
|
} |
|
21
|
47 |
|
return $r; |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
47 |
|
public static function getDbType($class, $member) { |
|
25
|
47 |
|
$ret = self::getAnnotationColumnMember ( $class, $member ); |
|
26
|
47 |
|
if (\is_object ( $ret ) && \property_exists ( $ret, 'dbType' )) { |
|
27
|
16 |
|
return $ret->dbType; |
|
28
|
|
|
} |
|
29
|
47 |
|
return false; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
47 |
|
public static function isSerializable($class, $member) { |
|
33
|
47 |
|
return self::getAnnotationMember ( $class, $member, 'transient' ) === false |
|
34
|
47 |
|
&& self::getAnnotationMember ( $class, $member, 'manyToOne' ) === false |
|
35
|
47 |
|
&& self::getAnnotationMember ( $class, $member, 'manyToMany' ) === false |
|
36
|
47 |
|
&& self::getAnnotationMember ( $class, $member, 'oneToMany' ) === false; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
47 |
|
public static function getFieldName($class, $member) { |
|
40
|
47 |
|
$ret = self::getAnnotationColumnMember ( $class, $member ); |
|
41
|
47 |
|
if ($ret === false || ! isset ( $ret->name )) { |
|
42
|
47 |
|
$ret = $member; |
|
43
|
|
|
} else { |
|
44
|
16 |
|
$ret = $ret->name; |
|
45
|
|
|
} |
|
46
|
47 |
|
return $ret; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
47 |
|
public static function isNullable($class, $member) { |
|
50
|
47 |
|
$ret = self::getAnnotationColumnMember ( $class, $member ); |
|
51
|
47 |
|
if (\is_object ( $ret ) && \property_exists ( $ret, 'nullable' )) { |
|
52
|
16 |
|
return $ret->nullable; |
|
53
|
|
|
} |
|
54
|
47 |
|
return false; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
54 |
|
public static function getProperties($class) { |
|
58
|
54 |
|
$reflect = new \ReflectionClass ( $class ); |
|
59
|
54 |
|
return $reflect->getProperties (); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
34 |
|
public static function getProperty($instance, $member) { |
|
63
|
34 |
|
$reflect = new \ReflectionClass ( $instance ); |
|
64
|
34 |
|
$prop = false; |
|
65
|
34 |
|
if ($reflect->hasProperty ( $member )) { |
|
66
|
34 |
|
$prop = $reflect->getProperty ( $member ); |
|
67
|
|
|
} |
|
68
|
34 |
|
return $prop; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
8 |
|
public static function getPropertyType($class, $property) { |
|
72
|
8 |
|
if (($r = self::getMetadata ( $class, $property, 'var', 'type' )) === false) { |
|
73
|
8 |
|
$reflect = new \ReflectionProperty ( $class, $property ); |
|
74
|
8 |
|
return $reflect->getType (); |
|
75
|
|
|
} |
|
76
|
8 |
|
return $r; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
8 |
|
public static function getMetadata($class, $property, $type, $name) { |
|
80
|
8 |
|
$a = self::getAnnotsEngine ()->getAnnotsOfProperty ( $class, $property, $type ); |
|
81
|
8 |
|
if (! \count ( $a )) { |
|
82
|
8 |
|
return false; |
|
83
|
|
|
} |
|
84
|
8 |
|
return \trim ( $a [0]->$name, ';' ); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
|