1
|
|
|
<?php |
2
|
|
|
namespace keeko\tools\model; |
3
|
|
|
|
4
|
|
|
use Propel\Generator\Model\ForeignKey; |
5
|
|
|
use Propel\Generator\Model\Table; |
6
|
|
|
use keeko\framework\utils\NameUtils; |
7
|
|
|
|
8
|
|
|
abstract class Relationship { |
9
|
|
|
|
10
|
|
|
const ONE_TO_ONE = 'one-to-one'; |
11
|
|
|
const ONE_TO_MANY = 'one-to-many'; |
12
|
|
|
const MANY_TO_MANY = 'many-to-many'; |
13
|
|
|
|
14
|
|
|
/** @var Table */ |
15
|
|
|
protected $model; |
16
|
|
|
|
17
|
|
|
/** @var Table */ |
18
|
|
|
protected $foreign; |
19
|
|
|
|
20
|
|
|
/** @var ForeignKey */ |
21
|
|
|
protected $fk; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Returns the type of this relationship |
25
|
|
|
* |
26
|
|
|
* @return string |
27
|
|
|
*/ |
28
|
|
|
abstract public function getType(); |
29
|
|
|
|
30
|
|
|
public function isOneToOne() { |
31
|
|
|
return $this->getType() == Relationship::ONE_TO_ONE; |
|
|
|
|
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Returns the model |
36
|
|
|
* |
37
|
|
|
* @return Table |
38
|
|
|
*/ |
39
|
|
|
public function getModel() { |
40
|
|
|
return $this->model; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Returns the foreign model |
45
|
|
|
* |
46
|
|
|
* @return Table |
47
|
|
|
*/ |
48
|
|
|
public function getForeign() { |
49
|
|
|
return $this->foreign; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Returns the foreign key |
54
|
|
|
* |
55
|
|
|
* @return ForeignKey |
56
|
|
|
*/ |
57
|
|
|
public function getForeignKey() { |
58
|
|
|
return $this->fk; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Returns the related name in studly case |
63
|
|
|
* |
64
|
|
|
* @return string |
65
|
|
|
*/ |
66
|
|
|
abstract public function getRelatedName(); |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Returns the pluralized related name in studly case |
70
|
|
|
* |
71
|
|
|
* @return string |
72
|
|
|
*/ |
73
|
|
|
public function getRelatedPluralName() { |
74
|
|
|
return NameUtils::pluralize($this->getRelatedName()); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Returns the related type name for usage in api environment (slug, type-name, etc) |
79
|
|
|
* |
80
|
|
|
* @return string |
81
|
|
|
*/ |
82
|
|
|
public function getRelatedTypeName() { |
83
|
|
|
return NameUtils::dasherize($this->getRelatedName()); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Returns the pluralized related type name for usage in api environment (slug, type-name, etc) |
88
|
|
|
* |
89
|
|
|
* @return string |
90
|
|
|
*/ |
91
|
|
|
public function getRelatedPluralTypeName() { |
92
|
|
|
return NameUtils::pluralize($this->getRelatedTypeName()); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Returns the reverse related name in studly case |
97
|
|
|
*/ |
98
|
|
|
abstract public function getReverseRelatedName(); |
|
|
|
|
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Returns the pluralized reverse related name in studly case |
102
|
|
|
* |
103
|
|
|
* @return string |
104
|
|
|
*/ |
105
|
|
|
public function getReverseRelatedPluralName() { |
106
|
|
|
return NameUtils::pluralize($this->getReverseRelatedName()); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Returns the reverse related type name for usage in api environment (slug, type-name, etc) |
111
|
|
|
* |
112
|
|
|
* @return string |
113
|
|
|
*/ |
114
|
|
|
public function getReverseRelatedTypeName() { |
115
|
|
|
return NameUtils::dasherize($this->getReverseRelatedName()); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Returns the pluralized reverse related type name for usage in api environment (slug, type-name, etc) |
120
|
|
|
* |
121
|
|
|
* @return string |
122
|
|
|
*/ |
123
|
|
|
public function getReverseRelatedPluralTypeName() { |
124
|
|
|
return NameUtils::pluralize($this->getReverseRelatedTypeName()); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Returns whether the relationship refers to itself |
129
|
|
|
* |
130
|
|
|
* @return bool |
131
|
|
|
*/ |
132
|
|
|
public function isReflexive() { |
133
|
|
|
return $this->model == $this->foreign; |
134
|
|
|
} |
135
|
|
|
} |
This check looks for accesses to local static members using the fully qualified name instead of
self::
.While this is perfectly valid, the fully qualified name of
Certificate::TRIPLEDES_CBC
could just as well be replaced byself::TRIPLEDES_CBC
. Referencing local members withself::
assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.