1
|
|
|
<?php |
2
|
|
|
namespace keeko\tools\generator\name; |
3
|
|
|
|
4
|
|
|
use Propel\Generator\Model\Table; |
5
|
|
|
use keeko\tools\model\Relationship; |
6
|
|
|
use keeko\tools\generator\Types; |
7
|
|
|
|
8
|
|
|
abstract class AbstractModelNameGenerator extends AbstractNameGenerator { |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Generates a name with a given type and based on the object type |
12
|
|
|
* |
13
|
|
|
* @param string $type |
14
|
|
|
* @param Table|Relationship $object |
15
|
|
|
* @return string|null Returns the name or null if the type or object is unknown |
16
|
|
|
*/ |
17
|
|
|
public function generate($type, $object) { |
18
|
|
|
if ($object instanceof Table) { |
19
|
|
|
return $this->generateModel($type, $object); |
20
|
|
|
} else if ($object instanceof Relationship) { |
21
|
|
|
return $this->generateRelationship($type, $object); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
return null; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Generates a name for a model action with a given type |
29
|
|
|
* |
30
|
|
|
* @param string $type |
31
|
|
|
* @param Table $model |
32
|
|
|
* @return string|null Returns the name or null if the type is unknown |
33
|
|
|
*/ |
34
|
|
|
public function generateModel($type, Table $model) { |
35
|
|
|
switch ($type) { |
36
|
|
|
case Types::PAGINATE: |
37
|
|
|
return $this->generateModelPaginate($model); |
38
|
|
|
|
39
|
|
|
case Types::CREATE: |
40
|
|
|
return $this->generateModelCreate($model); |
41
|
|
|
|
42
|
|
|
case Types::READ: |
43
|
|
|
return $this->generateModelRead($model); |
44
|
|
|
|
45
|
|
|
case Types::UPDATE: |
46
|
|
|
return $this->generateModelUpdate($model); |
47
|
|
|
|
48
|
|
|
case Types::DELETE: |
49
|
|
|
return $this->generateModelDelete($model); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
return null; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Generates a name for a model create type |
57
|
|
|
* |
58
|
|
|
* @param Table $model |
59
|
|
|
* @return string |
60
|
|
|
*/ |
61
|
|
|
abstract public function generateModelCreate(Table $model); |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Generates a name for a model read type |
65
|
|
|
* |
66
|
|
|
* @param Table $model |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
|
|
abstract public function generateModelRead(Table $model); |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Generates a name for a model paginate type |
73
|
|
|
* |
74
|
|
|
* @param Table $model |
75
|
|
|
* @return string |
76
|
|
|
*/ |
77
|
|
|
abstract public function generateModelPaginate(Table $model); |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Generates a name for a model update type |
81
|
|
|
* |
82
|
|
|
* @param Table $model |
83
|
|
|
* @return string |
84
|
|
|
*/ |
85
|
|
|
abstract public function generateModelUpdate(Table $model); |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Generates a name for a model delete type |
89
|
|
|
* |
90
|
|
|
* @param Table $model |
91
|
|
|
* @return string |
92
|
|
|
*/ |
93
|
|
|
abstract public function generateModelDelete(Table $model); |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Generates a name for a relationship action with a given type |
97
|
|
|
* |
98
|
|
|
* @param string $type |
99
|
|
|
* @param Relationship $relationship |
100
|
|
|
* @return string|null Returns the name or null if the type is unknown |
101
|
|
|
*/ |
102
|
|
|
public function generateRelationship($type, Relationship $relationship) { |
103
|
|
|
switch ($type) { |
104
|
|
|
case Types::READ: |
105
|
|
|
return $this->generateRelationshipRead($relationship); |
106
|
|
|
|
107
|
|
|
case Types::UPDATE: |
108
|
|
|
return $this->generateRelationshipUpdate($relationship); |
109
|
|
|
|
110
|
|
|
case Types::ADD: |
111
|
|
|
return $this->generateRelationshipAdd($relationship); |
112
|
|
|
|
113
|
|
|
case Types::REMOVE: |
114
|
|
|
return $this->generateRelationshipRemove($relationship); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
return null; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Generates a name for a relationship read type |
122
|
|
|
* |
123
|
|
|
* @param Relationship $relationship |
124
|
|
|
* @return string |
125
|
|
|
*/ |
126
|
|
|
abstract public function generateRelationshipRead(Relationship $relationship); |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Generates a name for a relationship update type |
130
|
|
|
* |
131
|
|
|
* @param Relationship $relationship |
132
|
|
|
* @return string |
133
|
|
|
*/ |
134
|
|
|
abstract public function generateRelationshipUpdate(Relationship $relationship); |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Generates a name for a relationship add type |
138
|
|
|
* |
139
|
|
|
* @param Relationship $relationship |
140
|
|
|
* @return string |
141
|
|
|
*/ |
142
|
|
|
abstract public function generateRelationshipAdd(Relationship $relationship); |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Generates a name for a relationship remove type |
146
|
|
|
* |
147
|
|
|
* @param Relationship $relationship |
148
|
|
|
* @return string |
149
|
|
|
*/ |
150
|
|
|
abstract public function generateRelationshipRemove(Relationship $relationship); |
151
|
|
|
|
152
|
|
|
} |