1 | <?php |
||
15 | class ModelService extends AbstractService { |
||
16 | |||
17 | private $models = null; |
||
|
|||
18 | private $schema = null; |
||
19 | |||
20 | /** @var Database */ |
||
21 | private $database = null; |
||
22 | |||
23 | private $relationships = null; |
||
24 | |||
25 | private $reader = null; |
||
26 | |||
27 | public function read(Project $project = null) { |
||
37 | 12 | ||
38 | 12 | /** |
|
39 | * @return ModelReader |
||
40 | 12 | */ |
|
41 | 12 | private function getReader() { |
|
47 | 12 | ||
48 | /** |
||
49 | 12 | * Returns the propel schema. The three locations, where the schema is looked up in: |
|
50 | * |
||
51 | * @return string|null the path to the schema |
||
52 | */ |
||
53 | 12 | public function getSchema() { |
|
60 | |||
61 | public function isCoreSchema() { |
||
64 | |||
65 | public function hasSchema() { |
||
68 | |||
69 | /** |
||
70 | * Returns the propel database |
||
71 | * |
||
72 | 12 | * @return Database |
|
73 | 12 | */ |
|
74 | 12 | public function getDatabase() { |
|
77 | 12 | ||
78 | /** |
||
79 | 12 | * Returns the tableName for a given name |
|
80 | * |
||
81 | * @param String $name tableName or modelName |
||
82 | * @return String tableName |
||
83 | */ |
||
84 | public function getTableName($name) { |
||
87 | |||
88 | 11 | /** |
|
89 | 11 | * Returns all model names |
|
90 | 11 | * |
|
91 | 11 | * @return Set |
|
92 | 11 | */ |
|
93 | public function getModelNames() { |
||
96 | |||
97 | /** |
||
98 | * Returns the propel models from the database, where table namespace matches package namespace |
||
99 | * |
||
100 | * @return Map |
||
101 | */ |
||
102 | public function getModels() { |
||
105 | |||
106 | /** |
||
107 | * Returns the model for the given name |
||
108 | * |
||
109 | * @param String $name modelName or tableName |
||
110 | * @return Table |
||
111 | */ |
||
112 | public function getModel($name) { |
||
115 | |||
116 | // /** |
||
117 | 1 | // * Returns the model names for a given package |
|
118 | 1 | // * |
|
119 | 1 | // * @param PackageSchema $package a package to search models for, if omitted global package is used |
|
120 | 1 | // * @return array array with string of model names |
|
121 | // */ |
||
122 | 1 | // public function getPackageModelNames(PackageSchema $package = null) { |
|
123 | // if ($package === null) { |
||
124 | 1 | // $package = $this->packageService->getPackage(); |
|
125 | 1 | // } |
|
126 | 1 | ||
127 | 1 | // $models = []; |
|
128 | 1 | // // if this is a core-module, find the related model |
|
129 | 1 | // if ($package->getVendor() == 'keeko' && $this->isCoreSchema()) { |
|
130 | // $model = $package->getName(); |
||
131 | 1 | // if ($this->hasModel($model)) { |
|
132 | // $models [] = $model; |
||
133 | // } |
||
134 | // } |
||
135 | |||
136 | // // anyway, generate all |
||
137 | // else { |
||
138 | // foreach ($this->getModels() as $model) { |
||
139 | // $models [] = $model->getOriginCommonName(); |
||
140 | 7 | // } |
|
141 | 7 | // } |
|
142 | 7 | ||
143 | // return $models; |
||
144 | // } |
||
145 | |||
146 | /** |
||
147 | 7 | * Checks whether the given model exists |
|
148 | * |
||
149 | 7 | * @param String $name tableName or modelName |
|
150 | * @return boolean |
||
151 | */ |
||
152 | public function hasModel($name) { |
||
155 | |||
156 | /** |
||
157 | * Parses the model name from a given action name |
||
158 | 8 | * |
|
159 | 8 | * @param ActionSchema $action |
|
160 | * @return String modelName |
||
161 | */ |
||
162 | public function getModelNameByAction(ActionSchema $action) { |
||
170 | 1 | ||
171 | 1 | /** |
|
172 | 1 | * Returns the full model object name, including namespace |
|
173 | 1 | * |
|
174 | 1 | * @param ActionSchema $action |
|
175 | 1 | * @return String fullModelObjectName |
|
176 | 1 | */ |
|
177 | public function getFullModelObjectName(ActionSchema $action) { |
||
185 | |||
186 | /** |
||
187 | * Returns wether the given action refers to a model. |
||
188 | * |
||
189 | * Examples: |
||
190 | * |
||
191 | * Action: user-create => model: user |
||
192 | * Action: recover-password => no model |
||
193 | * |
||
194 | * @param ActionSchema $action |
||
195 | * @return boolean |
||
196 | */ |
||
197 | public function isModelAction(ActionSchema $action) { |
||
201 | |||
202 | /** |
||
203 | * Returns all model relationships. |
||
204 | * |
||
205 | * @param Table $model |
||
206 | * @return Relationships |
||
207 | */ |
||
208 | public function getRelationships(Table $model) { |
||
211 | |||
212 | 10 | /** |
|
213 | 10 | * Returns a relationship for a given related type name on a given model |
|
214 | 10 | * |
|
215 | 10 | * @param Table $model |
|
216 | 10 | * @param string $relatedTypeName |
|
217 | 10 | * @return Relationship |
|
218 | 10 | */ |
|
219 | public function getRelationship(Table $model, $relatedTypeName) { |
||
223 | } |
||
224 |
This check marks private properties in classes that are never used. Those properties can be removed.