@@ -82,17 +82,17 @@ class DbModel extends BaseObject
82
82
83
83
public $ isNotDb = false ;
84
84
85
- /**
86
- * @var array Automatically generated scenarios from the model 'x-scenarios'.
87
- */
88
- private array $ scenarios ;
89
-
90
85
/**
91
86
* @var string
92
87
* Here, you can set your own default description for the scenario.
93
88
* AcceptedInputs: {scenarioName}, {scenarioConst}, {modelName}.
94
89
*/
95
- public string $ scenarioDefaultDescription = "Scenario {scenarioName} " ;
90
+ public $ scenarioDefaultDescription = "Scenario {scenarioName} " ;
91
+
92
+ /**
93
+ * @var array Automatically generated scenarios from the model 'x-scenarios'.
94
+ */
95
+ private $ _scenarios ;
96
96
97
97
public function getTableAlias ():string
98
98
{
@@ -193,18 +193,72 @@ public function dbAttributes():array
193
193
}
194
194
195
195
/**
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
+ *
196
204
* @return array
197
205
*/
198
206
public function getScenarios (): array
199
207
{
200
- if (isset ($ this ->scenarios )) {
201
- return $ this ->scenarios ;
208
+ if (isset ($ this ->_scenarios )) {
209
+ return $ this ->_scenarios ;
202
210
}
203
- $ this ->scenarios = $ this ->getScenariosByOpenapiSchema ();
204
- return $ this ->scenarios ;
211
+ $ this ->_scenarios = $ this ->getScenariosByOpenapiSchema ();
212
+ return $ this ->_scenarios ;
205
213
}
206
214
207
215
/**
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
+ *
208
262
* @return array
209
263
*/
210
264
private function getScenariosByOpenapiSchema (): array
0 commit comments