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