Skip to content
  • About
    • What is Symfony?
    • Community
    • News
    • Contributing
    • Support
  • Documentation
    • Symfony Docs
    • Symfony Book
    • Screencasts
    • Symfony Bundles
    • Symfony Cloud
    • Training
  • Services
    • Platform.sh for Symfony Best platform to deploy Symfony apps
    • SymfonyInsight Automatic quality checks for your apps
    • Symfony Certification Prove your knowledge and boost your career
    • SensioLabs Professional services to help you with Symfony
    • Blackfire Profile and monitor performance of your apps
  • Other
  • Blog
  • Download
sponsored by
  1. Home
  2. Documentation
  3. Bundles
  4. SymfonyMakerBundle

The Symfony MakerBundle

Edit this page

Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code. This bundle assumes you're using a standard Symfony 6.4 directory structure, but many commands can generate code into any application.

Installation

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

1
$ composer require --dev symfony/maker-bundle

Usage

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

1
2
3
4
5
6
7
8
9
10
$ 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

 [...]

 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:

1
$ php bin/console make:controller --help

Linting Generated Code

MakerBundle uses php-cs-fixer to enforce coding standards when generating .php files. When running a make command, MakerBundle will use a php-cs-fixer version and configuration that is packaged with this bundle.

You can explicitly set a custom path to a php-cs-fixer binary and/or configuration file by their respective environment variables:

  • MAKER_PHP_CS_FIXER_BINARY_PATH e.g. tools/vendor/bin/php-cs-fixer
  • MAKER_PHP_CS_FIXER_CONFIG_PATH e.g. .php-cs-fixer.config.php

Tip

Is PHP-CS-Fixer installed globally? To avoid needing to set these in every project, you can instead set these on your operating system.

Configuration

This bundle doesn't require any configuration. But, you can override the default configuration:

1
2
3
4
5
6
# config/packages/maker.yaml
when@dev:
    maker:
        root_namespace: 'App'
        generate_final_classes: true
        generate_final_entities: false

root_namespace

type: string default: App

The root namespace used when generating all of your classes (e.g. App\Entity\Article, App\Command\MyCommand, etc). Changing this to Acme would cause MakerBundle to create new classes like (e.g. Acme\Entity\Article, Acme\Command\MyCommand, etc).

generate_final_classes

type: boolean default: true

By default, MakerBundle will generate all of your classes with the final PHP keyword except for doctrine entities. Set this to false to override this behavior for all maker commands.

See https://www.php.net/manual/en/language.oop5.final.php

1
2
3
4
final class MyVoter
{
    ...
}

1.61

generate_final_classes was introduced in MakerBundle 1.61

generate_final_entities

type: boolean default: false

By default, MakerBundle will not generate any of your doctrine entity classes with the final PHP keyword. Set this to true to override this behavior for all maker commands that create entities.

See https://www.php.net/manual/en/language.oop5.final.php

1
2
3
4
5
#[ORM\Entity(repositoryClass: TaskRepository::class)]
final class Task extends AbstractEntity
{
    ...
}

1.61

generate_final_entities was introduced in MakerBundle 1.61.

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. To do that, you should create a class that extends AbstractMaker in your src/Maker/ directory. And this is really it!

For examples of how to complete your new maker command, see the core maker commands. Make sure your class is registered as a service and tagged with maker.command. If you're using the standard Symfony services.yaml configuration, this will be done automatically.

Overriding the Generated Code

Generated code can never be perfect for everyone. The MakerBundle tries to balance adding "extension points" with keeping the library simple so that existing commands can be improved and new commands can be added.

For that reason, in general, the generated code cannot be modified. In many cases, adding your own maker command is so easy, that we recommend that. However, if there is some extension point that you'd like, please open an issue so we can discuss!

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.
TOC
    Version
    Show your Symfony expertise

    Show your Symfony expertise

    Be trained by SensioLabs experts (2 to 6 day sessions -- French or English).

    Be trained by SensioLabs experts (2 to 6 day sessions -- French or English).

    Version:

    Table of Contents

    • Installation
    • Usage
      • Linting Generated Code
    • Configuration
    • Creating your Own Makers
    • Overriding the Generated Code

    Symfony footer

    Avatar of Vladimir Tsykun, a Symfony contributor

    Thanks Vladimir Tsykun (@vtsykun) for being a Symfony contributor

    19 commits • 319 lines changed

    View all contributors that help us make Symfony

    Become a Symfony contributor

    Be an active part of the community and contribute ideas, code and bug fixes. Both experts and newcomers are welcome.

    Learn how to contribute

    Symfony™ is a trademark of Symfony SAS. All rights reserved.

    • What is Symfony?

      • What is Symfony?
      • Symfony at a Glance
      • Symfony Components
      • Symfony Releases
      • Security Policy
      • Logo & Screenshots
      • Trademark & Licenses
      • symfony1 Legacy
    • Learn Symfony

      • Symfony Docs
      • Symfony Book
      • Reference
      • Bundles
      • Best Practices
      • Training
      • eLearning Platform
      • Certification
    • Screencasts

      • Learn Symfony
      • Learn PHP
      • Learn JavaScript
      • Learn Drupal
      • Learn RESTful APIs
    • Community

      • Symfony Community
      • SymfonyConnect
      • Events & Meetups
      • Projects using Symfony
      • Contributors
      • Symfony Jobs
      • Backers
      • Code of Conduct
      • Downloads Stats
      • Support
    • Blog

      • All Blog Posts
      • A Week of Symfony
      • Case Studies
      • Cloud
      • Community
      • Conferences
      • Diversity
      • Living on the edge
      • Releases
      • Security Advisories
      • Symfony Insight
      • Twig
      • SensioLabs Blog
    • Services

      • SensioLabs services
      • Train developers
      • Manage your project quality
      • Improve your project performance
      • Host Symfony projects

      Powered by

    Follow Symfony