You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a directory with subdirectories is converted into models the directory structure of the JSON-Schema files will be mirrored to the directory structure of the generated models.
5
+
Models located in a subdirectory will contain a PSR-4 compatible namespace based on the directory structure.
6
+
Set a namespace prefix with the `setNamespacePrefix` method of the `GeneratorConfiguration` object for locating the models inside your application or adding them to your composer autoloading configuration.
7
+
8
+
An example structure of your JSON-Schema files for a user module may look like:
9
+
10
+
.. code-block:: none
11
+
12
+
- Models
13
+
- Request
14
+
- Login.json
15
+
- Register.json
16
+
- Update.json
17
+
- Response
18
+
- Error
19
+
- UserExists.json
20
+
- Login.json
21
+
- Register.json
22
+
- Update.json
23
+
- Modules
24
+
- LoginData.json
25
+
- User.json
26
+
- Message.json
27
+
- generateModels.php
28
+
29
+
Your model generation code inside `generateModels.php` now could look like:
30
+
31
+
.. code-block:: php
32
+
33
+
$generator = new ModelGenerator((new GeneratorConfiguration())->setNamespacePrefix('MyApp\User'));
If referenced classes (eg. in the example given above the modules which may be used in multiple schemas) or nested classes occur multiple times the generator will detect the re-used class and link to the already generated object.
59
+
The generator gives a `duplicated signature` hint in the output.
60
+
61
+
The detection is not bound to namespace limits so a nested object which occurs in `Request\Register.json` as well as in `Response\Register.json` will be generated only once.
62
+
Consequently the class generated to `Response\Register.php` may use classes from the `Request` namespace.
63
+
A duplicated class is not linked to an already generated class if it's a primary object. The detection only links nested classes.
Copy file name to clipboardExpand all lines: docs/source/gettingStarted.rst
+13-1Lines changed: 13 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -119,7 +119,8 @@ Namespace prefix
119
119
120
120
setNamespacePrefix(string $prefix);
121
121
122
-
Configures a namespace prefix for all generated classes. The namespaces will be extended with the directory structure of the source directory. By default no namespace prefix will be set.
122
+
Configures a namespace prefix for all generated classes. By default no namespace prefix will be set. Generated namespaces are PSR-4 compatible.
123
+
Further information about the generated namespaces can be found at `Namespaces <generic/namespaces.html>`__.
123
124
124
125
.. code-block:: php
125
126
@@ -222,3 +223,14 @@ Enable or disable output of the generation process to STDOUT. By default the out
222
223
223
224
(new GeneratorConfiguration())
224
225
->setOutputEnabled(false);
226
+
227
+
The output contains information about generated classes, rendered classes, hints and warnings concerning the internal handling or the given schema files.
228
+
The output of a generation process may look like:
229
+
230
+
.. code-block:: none
231
+
232
+
Generated class MyApp\User\Response\Login
233
+
Generated class MyApp\User\Response\Register
234
+
Duplicated signature 444fd086d8d1f186145a6f81a3ac3f7a for class Register_Message. Redirecting to Login_Message
0 commit comments