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