Skip to content

Commit ec51111

Browse files
committed
cleanUp + getScenarios description
1 parent a1ac7e3 commit ec51111

File tree

3 files changed

+65
-9
lines changed

3 files changed

+65
-9
lines changed

src/generator/ApiGenerator.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,11 @@ class ApiGenerator extends Generator
136136

137137
/**
138138
* @var array Map for custom dbModels
139+
*
140+
* @see DbModel::$scenarioDefaultDescription with acceptedInputs: {scenarioName}, {scenarioConst}, {modelName}.
139141
* @example
140142
* 'dbModel' => [
141-
* AcceptedInputs: {scenarioName}, {scenarioConst}, {modelName}.
142-
* 'scenarioDefaultDescription' => " Scenario {scenarioName}", @see DbModel::$scenarioDefaultDescription
143+
* 'scenarioDefaultDescription' => "Scenario {scenarioName}",
143144
* ]
144145
*/
145146
public $dbModel = [];

src/lib/Config.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,11 @@ class Config extends BaseObject
111111

112112
/**
113113
* @var array Map for custom dbModels
114+
*
115+
* @see DbModel::$scenarioDefaultDescription with acceptedInputs: {scenarioName}, {scenarioConst}, {modelName}.
114116
* @example
115117
* 'dbModel' => [
116-
* AcceptedInputs: {scenarioName}, {scenarioConst}, {modelName}.
117-
* 'scenarioDefaultDescription' => " Scenario {scenarioName}", @see DbModel::$scenarioDefaultDescription
118+
* 'scenarioDefaultDescription' => "Scenario {scenarioName}",
118119
* ]
119120
*/
120121
public $dbModel = [];

src/lib/items/DbModel.php

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class DbModel extends BaseObject
8585
/**
8686
* @var array Automatically generated scenarios from the model 'x-scenarios'.
8787
*/
88-
private array $scenarios;
88+
private $_scenarios;
8989

9090
/**
9191
* @var string
@@ -193,18 +193,72 @@ public function dbAttributes():array
193193
}
194194

195195
/**
196+
* Returns a scenarios array based on the 'x-scenarios'.
197+
* Each scenario has the following properties: 'name', 'const', and 'description'.
198+
*
199+
* When the `getScenarios` function is called for the first time on this model,
200+
* the value is stored in `_scenarios` and then returned.
201+
* If the `getScenariosByOpenapiSchema` function is called again on this model,
202+
* the stored value from `_scenarios` is returned.
203+
*
196204
* @return array
197205
*/
198206
public function getScenarios(): array
199207
{
200-
if (isset($this->scenarios)) {
201-
return $this->scenarios;
208+
if (isset($this->_scenarios)) {
209+
return $this->_scenarios;
202210
}
203-
$this->scenarios = $this->getScenariosByOpenapiSchema();
204-
return $this->scenarios;
211+
$this->_scenarios = $this->getScenariosByOpenapiSchema();
212+
return $this->_scenarios;
205213
}
206214

207215
/**
216+
* Returns a scenarios array based on the 'x-scenarios'.
217+
* Each scenario has the following properties: 'name', 'const', and 'description'.
218+
*
219+
* Example for 'schema.yaml':
220+
* x-scenarios:
221+
* - name: create
222+
* description: My custom description for scenario create
223+
* - name: update
224+
*
225+
* 1) With default @see $scenarioDefaultDescription = "Scenario {scenarioName}"
226+
*
227+
* The resulting array:
228+
* [
229+
* [
230+
* 'name' => 'create',
231+
* 'const' => 'SCENARIO_CREATE',
232+
* 'description' => "My custom description for scenario create",
233+
* ],
234+
* [
235+
* 'name' => 'update',
236+
* 'const' => 'SCENARIO_UPDATE',
237+
* 'description' => "Scenario update",
238+
* ],
239+
* ]
240+
*
241+
* 2) With custom @see $scenarioDefaultDescription = implode("\n", [
242+
* "This Backend-Scenario \"{scenarioName}\" exist in both the frontend model and the backend model.",
243+
* "@see \common\client\models\{modelName}::{scenarioConst}",
244+
* ]);
245+
*
246+
* For the 'update' scenario, it is an example of a two-line description.
247+
* E.g. your modelName is 'Project'.
248+
* The resulting array:
249+
* [
250+
* [
251+
* 'name' => 'create',
252+
* 'const' => 'SCENARIO_CREATE',
253+
* 'description' => "My custom description for scenario create",
254+
* ],
255+
* [
256+
* 'name' => 'update',
257+
* 'const' => 'SCENARIO_UPDATE',
258+
* 'description' => "This Backend-Scenario \"update\" exist in both the frontend model and the backend model.\n@see \common\client\models\Project::SCENARIO_UPDATE",
259+
* ],
260+
* ]
261+
*
208262
* @return array
209263
*/
210264
private function getScenariosByOpenapiSchema(): array

0 commit comments

Comments
 (0)