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