Skip to content

Added the initial documentation #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,11 @@ SymfonyMakerBundle

Symfony Maker helps you creating empty commands, controllers, form classes,
tests and more so you can forget about the required boilerplate code. This
bundle replaces [SensioGeneratorBundle](https://github.com/sensiolabs/SensioGeneratorBundle)
in modern Symfony applications.
bundle is an alternative to [SensioGeneratorBundle][1] for modern Symfony
applications and requires using Symfony 3.4 or newer and [Symfony Flex][2].

[Read the docs][3]

[1]: https://github.com/sensiolabs/SensioGeneratorBundle
[2]: https://symfony.com/doc/current/setup/flex.html
[3]: Resources/doc/index.rst
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would link to the rendered documentation on symfony.com instead. Reading reStructuredText files may not be much fun.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! We'll update this when/if docs are published on symfony.com

121 changes: 121 additions & 0 deletions src/Resources/doc/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
SymfonyMakerBundle
==================

Symfony Maker helps you creating empty commands, controllers, form classes,
tests and more so you can forget about the required boilerplate code. This
bundle is an alternative to `SensioGeneratorBundle`_ for modern Symfony
applications and requires using Symfony 3.4 or newer and `Symfony Flex`_.

Installation
------------

Run this command to install and enable this bundle in your application:

.. code-block:: terminal

$ composer require maker

Usage
-----

This bundle provides several commands under the ``maker:`` namespace. List them
all executing this command:

.. code-block:: terminal

$ php bin/console list make

make:command Creates a new console command class
make:controller Creates a new controller class
make:entity Creates a new Doctrine entity class

[...]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about to explicitly list all the commands here? We'd know exactly all that is possible to make only by reading the readme.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to not do that to avoid having to maintain that list forever. This bundle just started, so we'll update this list of commands often ... and the less work we put on ourselves (e.g. maintaining this doc) the better.


make:validator Creates a new validator and constraint class
make:voter Creates a new security voter class

The names of the commands are self-explanatory, but some of them include
optional arguments and options. Check them out with the ``--help`` option:

.. code-block:: terminal

$ php bin/console make:controller --help

Creating your Own Makers
------------------------

In case your applications need to generate custom boilerplate code, you can
create your own ``make:...`` command reusing the tools provided by this bundle.
Imagine that you need to create a ``make:report`` command. First, create an
empty command:

.. code-block:: terminal

$ cd your-project/
$ php bin/console make:command 'make:report'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not create a make:maker command? 😃

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the moment this is an "edge feature". If it gets popular, we would add it in the future.


Then, change the generated command to extend from
:class:`Symfony\\Bundle\\MakerBundle\\Command\\AbstractCommand`, which is the
base command used by all ``make:`` commands:

.. code-block:: diff

// ...
-use Symfony\Component\Console\Command\Command;
+use Symfony\Bundle\MakerBundle\Command\AbstractCommand;

-class MakeReportCommand extends Command
+class MakeReportCommand extends AbstractCommand
{
protected static $defaultName = 'make:report';

// ...
}

Finally, implement the methods required by the ``AbstractCommand`` class::

// ...
use Symfony\Bundle\MakerBundle\Command\AbstractCommand;
use Symfony\Bundle\MakerBundle\ConsoleStyle;
use Symfony\Bundle\MakerBundle\DependencyBuilder;

class MakeReportCommand extends AbstractCommand
{
protected static $defaultName = 'make:report';

// ...

// Returns pairs of name-value parameters used to fill in the
// skeleton files of the generated code and the success/error messages
protected function getParameters(): array
{
return [
'filename' => sprintf('report-%s.txt', date('YmdHis')),
];
}

// Returns pairs of skeleton files (absolute paths) and their corresponding
// generated files (with paths relative to the app)
protected function getFiles(array $params): array
{
return [
__DIR__.'/../Resources/skeleton/report.txt' => 'reports/'.$params['filename'];
];
}

// Optionally, display some message after the generation of code
protected function writeNextStepsMessage(array $params, ConsoleStyle $io)
{
$io->text(sprintf('A new report was generated in the %s file.', $params['filename']));
}

// Optionally, define which classes must exist in the application to make
// this command work (useful to ensure that needed dependencies are installed)
protected function configureDependencies(DependencyBuilder $dependencies)
{
$dependencies->addClassDependency(PdfGenerator::class, ['acme-pdf-generator'], true);
}
}

.. _`SensioGeneratorBundle`: https://github.com/sensiolabs/SensioGeneratorBundle
.. _`Symfony Flex`: https://symfony.com/doc/current/setup/flex.html