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