Skip to content

Commit 423ef5e

Browse files
committed
Update CLI generator documentation
1 parent f181948 commit 423ef5e

File tree

1 file changed

+62
-158
lines changed

1 file changed

+62
-158
lines changed

user_guide_src/source/cli/cli_generators.rst

Lines changed: 62 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Creates a new spark command.
3333

3434
Usage:
3535
======
36-
.. code-block:: none
36+
::
3737

3838
make:command <name> [options]
3939

@@ -46,7 +46,29 @@ Options:
4646
* ``--command``: The command name to run in spark. Defaults to ``command:name``.
4747
* ``--group``: The group/namespace of the command. Defaults to ``CodeIgniter`` for basic commands, and ``Generators`` for generator commands.
4848
* ``--type``: The type of command, whether a ``basic`` command or a ``generator`` command. Defaults to ``basic``.
49-
* ``-n``: Set the root namespace. Defaults to value of ``APP_NAMESPACE``.
49+
* ``--namespace``: Set the root namespace. Defaults to value of ``APP_NAMESPACE``.
50+
* ``--suffix``: Append the component suffix to the generated class name.
51+
* ``--force``: Set this flag to overwrite existing files on destination.
52+
53+
make:config
54+
-----------
55+
56+
Creates a new config file.
57+
58+
Usage:
59+
======
60+
::
61+
62+
make:config <name> [options]
63+
64+
Argument:
65+
=========
66+
* ``name``: The name of the config class. **[REQUIRED]**
67+
68+
Options:
69+
========
70+
* ``--namespace``: Set the root namespace. Defaults to value of ``APP_NAMESPACE``.
71+
* ``--suffix``: Append the component suffix to the generated class name.
5072
* ``--force``: Set this flag to overwrite existing files on destination.
5173

5274
make:controller
@@ -56,7 +78,7 @@ Creates a new controller file.
5678

5779
Usage:
5880
======
59-
.. code-block:: none
81+
::
6082

6183
make:controller <name> [options]
6284

@@ -68,7 +90,8 @@ Options:
6890
========
6991
* ``--bare``: Extends from ``CodeIgniter\Controller`` instead of ``BaseController``.
7092
* ``--restful``: Extends from a RESTful resource. Choices are ``controller`` and ``presenter``. Defaults to ``controller``.
71-
* ``-n``: Set the root namespace. Defaults to value of ``APP_NAMESPACE``.
93+
* ``--namespace``: Set the root namespace. Defaults to value of ``APP_NAMESPACE``.
94+
* ``--suffix``: Append the component suffix to the generated class name.
7295
* ``--force``: Set this flag to overwrite existing files on destination.
7396

7497
make:entity
@@ -78,7 +101,7 @@ Creates a new entity file.
78101

79102
Usage:
80103
======
81-
.. code-block:: none
104+
::
82105

83106
make:entity <name> [options]
84107

@@ -88,8 +111,9 @@ Argument:
88111

89112
Options:
90113
========
91-
* ``-n``: Set the root namespace. Defaults to value of ``APP_NAMESPACE``.
92-
* ``-force``: Set this flag to overwrite existing files on destination.
114+
* ``--namespace``: Set the root namespace. Defaults to value of ``APP_NAMESPACE``.
115+
* ``--suffix``: Append the component suffix to the generated class name.
116+
* ``--force``: Set this flag to overwrite existing files on destination.
93117

94118
make:filter
95119
-----------
@@ -98,7 +122,7 @@ Creates a new filter file.
98122

99123
Usage:
100124
======
101-
.. code-block:: none
125+
::
102126

103127
make:filter <name> [options]
104128

@@ -108,7 +132,8 @@ Argument:
108132

109133
Options:
110134
========
111-
* ``-n``: Set the root namespace. Defaults to value of ``APP_NAMESPACE``.
135+
* ``--namespace``: Set the root namespace. Defaults to value of ``APP_NAMESPACE``.
136+
* ``--suffix``: Append the component suffix to the generated class name.
112137
* ``--force``: Set this flag to overwrite existing files on destination.
113138

114139
make:model
@@ -118,7 +143,7 @@ Creates a new model file.
118143

119144
Usage:
120145
======
121-
.. code-block:: none
146+
::
122147

123148
make:model <name> [options]
124149

@@ -129,9 +154,10 @@ Argument:
129154
Options:
130155
========
131156
* ``--dbgroup``: Database group to use. Defaults to ``default``.
132-
* ``--entity``: Set this flag to use an entity class as the return type.
157+
* ``--return``: Set the return type from ``array``, ``object``, or ``entity``. Defaults to ``array``.
133158
* ``--table``: Supply a different table name. Defaults to the pluralized class name.
134-
* ``-n``: Set the root namespace. Defaults to value of ``APP_NAMESPACE``.
159+
* ``--namespace``: Set the root namespace. Defaults to value of ``APP_NAMESPACE``.
160+
* ``--suffix``: Append the component suffix to the generated class name.
135161
* ``--force``: Set this flag to overwrite existing files on destination.
136162

137163
make:seeder
@@ -141,7 +167,7 @@ Creates a new seeder file.
141167

142168
Usage:
143169
======
144-
.. code-block:: none
170+
::
145171

146172
make:seeder <name> [options]
147173

@@ -151,7 +177,8 @@ Argument:
151177

152178
Options:
153179
========
154-
* ``-n``: Set the root namespace. Defaults to value of ``APP_NAMESPACE``.
180+
* ``--namespace``: Set the root namespace. Defaults to value of ``APP_NAMESPACE``.
181+
* ``--suffix``: Append the component suffix to the generated class name.
155182
* ``--force``: Set this flag to overwrite existing files on destination.
156183

157184
make:migration
@@ -161,7 +188,7 @@ Creates a new migration file.
161188

162189
Usage:
163190
======
164-
.. code-block:: none
191+
::
165192

166193
make:migration <name> [options]
167194

@@ -171,30 +198,13 @@ Argument:
171198

172199
Options:
173200
========
174-
* ``-n``: Set the root namespace. Defaults to value of ``APP_NAMESPACE``.
201+
* ``--session``: Generate a migration file for database sessions.
202+
* ``--table``: Set the table name to use for database sessions. Defaults to ``ci_sessions``.
203+
* ``--dbgroup``: Set the database group for database sessions. Defaults to ``default`` group.
204+
* ``--namespace``: Set the root namespace. Defaults to value of ``APP_NAMESPACE``.
205+
* ``--suffix``: Append the component suffix to the generated class name.
175206
* ``--force``: Set this flag to overwrite existing files on destination.
176207

177-
session:migration
178-
-----------------
179-
180-
Generates the migration file for database sessions.
181-
182-
Usage:
183-
======
184-
.. code-block:: none
185-
186-
session:migration [options]
187-
188-
Options:
189-
========
190-
* ``-g``: Set the database group.
191-
* ``-t``: Set the table name. Defaults to ``ci_sessions``.
192-
* ``-n``: Set the root namespace. Defaults to value of ``APP_NAMESPACE``.
193-
* ``--force``: Set this flag to overwrite existing files on destination.
194-
195-
.. note:: When running ``php spark help session:migration``, you will see that it has the argument ``name`` listed.
196-
This argument is not used as the class name is derived from the table name passed to the ``-t`` option.
197-
198208
.. note:: Do you need to have the generated code in a subfolder? Let's say if you want to create a controller
199209
class to reside in the ``Admin`` subfolder of the main ``Controllers`` folder, you will just need
200210
to prepend the subfolder to the class name, like this: ``php spark make:controller admin/login``. This
@@ -203,14 +213,15 @@ Options:
203213

204214
.. note:: Working on modules? Code generation will set the root namespace to a default of ``APP_NAMESPACE``.
205215
Should you need to have the generated code elsewhere in your module namespace, make sure to set
206-
the ``-n`` option in your command, e.g., ``php spark make:model blog -n Acme\Blog``.
216+
the ``--namespace`` option in your command, e.g., ``php spark make:model blog --namespace Acme\Blog``.
207217

208-
.. warning:: Make sure when setting the ``-n`` option that the supplied namespace is a valid namespace
209-
defined in your ``$psr4`` array in ``Config\Autoload`` or defined in your composer autoload file.
210-
Otherwise, a ``RuntimeException`` will be thrown.
218+
.. warning:: Make sure when setting the ``--namespace`` option that the supplied namespace is a valid
219+
namespace defined in your ``$psr4`` array in ``Config\Autoload`` or defined in your composer autoload
220+
file. Otherwise, code generation will be interrupted.
211221

212222
.. warning:: Use of ``migrate:create`` to create migration files is now deprecated. It will be removed in
213-
future releases. Please use ``make:migration`` as replacement.
223+
future releases. Please use ``make:migration`` as replacement. Also, please use ``make:migration --session``
224+
to use instead of the deprecated ``session:migration``.
214225

215226
****************************************
216227
Scaffolding a Complete Set of Stock Code
@@ -234,122 +245,15 @@ will create the following classes:
234245

235246
(1) ``App\Controllers\User``;
236247
(2) ``App\Models\User``;
237-
(3) ``App\Entities\User``;
238-
(4) ``App\Database\Migrations\<some date here>_User``; and
239-
(5) ``App\Database\Seeds\User``.
240-
241-
****************
242-
GeneratorCommand
243-
****************
244-
245-
All generator commands must extend ``GeneratorCommand`` to fully utilize its methods that are used in code
246-
generation. While some of the methods are already functional, you may have the need to customize or upgrade
247-
what each method does. You can do so as all methods have protected visibility, except for the ``run()`` method
248-
which is public and need not be overridden as it is essentially complete.
249-
250-
.. php:class:: CodeIgniter\\CLI\\GeneratorCommand
251-
252-
.. php:method:: getClassName()
253-
254-
:rtype: string
255-
256-
Gets the class name from input. This can be overridden if name is really
257-
required by providing a prompt.
258-
259-
.. php:method:: sanitizeClassName(string $class)
260-
261-
:param string $class: Class name.
262-
:rtype: string
263-
264-
Trims input, normalize separators, and ensures all paths are in Pascal case.
265-
266-
.. php:method:: qualifyClassName(string $class)
267-
268-
:param string $class: Class name.
269-
:rtype: string
270-
271-
Parses the class name and checks if it is already fully qualified.
272-
273-
.. php:method:: getRootNamespace()
274-
275-
:rtype: string
276-
277-
Gets the root namespace from input. Defaults to value of ``APP_NAMESPACE``.
278-
279-
.. php:method:: getNamespacedClass(string $rootNamespace, string $class)
280-
281-
:param string $rootNamespace: The root namespace of the class.
282-
:param string $class: Class name
283-
:returns: The fully qualified class name
284-
:rtype: string
285-
286-
Gets the qualified class name. This should be implemented.
287-
288-
.. php:method:: buildPath(string $class)
289-
290-
:param string $class: The fully qualified class name
291-
:returns: The absolute path to where the class will be saved.
292-
:rtype: string
293-
:throws: RuntimeException
294-
295-
Builds the file path from the class name.
296-
297-
.. php:method:: modifyBasename(string $filename)
298-
299-
:param string $filename: The basename of the file path.
300-
:returns: A modified basename for the file.
301-
:rtype: string
302-
303-
Provides last chance for child generators to change the file's basename before saving.
304-
This is useful for migration files where the basename has a date component.
305-
306-
.. php:method:: buildClassContents(string $class)
307-
308-
:param string $class: The fully qualified class name.
309-
:rtype: string
310-
311-
Builds the contents for class being generated, doing all the replacements necessary in the template.
312-
313-
.. php:method:: getTemplate()
314-
315-
:rtype: string
316-
317-
Gets the template for the class being generated. This must be implemented.
318-
319-
.. php:method:: getNamespace(string $class)
320-
321-
:param string $class: The fully qualified class name.
322-
:rtype: string
323-
324-
Retrieves the namespace part from the fully qualified class name.
325-
326-
.. php:method:: setReplacements(string $template, string $class)
327-
328-
:param string $template: The template string to use.
329-
:param string $class: The fully qualified class name.
330-
:returns: The template string with all annotations replaced.
331-
:rtype: string
332-
333-
Performs all the necessary replacements.
334-
335-
.. php:method:: sortImports(string $template)
336-
337-
:param string $template: The template file.
338-
:returns: The template file with all imports already sorted.
339-
:rtype: string
340-
341-
Alphabetically sorts the imports for a given template.
342-
343-
.. warning:: Child generators should make sure to implement ``GeneratorCommand``'s two abstract methods:
344-
``getNamespacedClass`` and ``getTemplate``, or else you will get a PHP fatal error.
248+
(3) ``App\Database\Migrations\<some date here>_User``; and
249+
(4) ``App\Database\Seeds\User``.
345250

346-
.. note:: ``GeneratorCommand`` has the default argument of ``['name' => 'Class name']``. You can
347-
override the description by supplying the name in your ``$arguments`` property, e.g., ``['name' => 'Module class name']``.
251+
To include an ``Entity`` class in the scaffolded files, just include the ``--return entity`` to the command
252+
and it will be passed to the model generator.
348253

349-
.. note:: ``GeneratorCommand`` has the default options of ``-n`` and ``--force``. Child classes cannot override
350-
these two properties as they are crucial in the implementation of the code generation.
254+
**************
255+
GeneratorTrait
256+
**************
351257

352-
.. note:: Generators are default listed under the ``Generators`` namespace because it is the default group
353-
name in ``GeneratorCommand``. If you want to have your own generator listed elsewhere under a different
354-
namespace, you will just need to provide the ``$group`` property in your child generator,
355-
e.g., ``protected $group = 'CodeIgniter';``.
258+
All generator commands must use the ``GeneratorTrait`` to fully utilize its methods that are used in code
259+
generation.

0 commit comments

Comments
 (0)