|
| 1 | +# Symfony maker commands |
| 2 | + |
| 3 | +API Platform comes with a set of maker commands to help you create Api Resources and other related classes. |
| 4 | + |
| 5 | +## Available commands |
| 6 | + |
| 7 | +### Create an entity that is an API Resource |
| 8 | + |
| 9 | +You can use Symfony [MakerBundle](https://symfonycasts.com/screencast/symfony-fundamentals/maker-command?cid=apip) to generate a Doctrine entity that is also a resource thanks to the `--api-resource` option: |
| 10 | + |
| 11 | +```bash |
| 12 | +bin/console make:entity --api-resource |
| 13 | +``` |
| 14 | + |
| 15 | +### Create an API Filter |
| 16 | + |
| 17 | +You can create an Api Filter class using the following command: |
| 18 | + |
| 19 | +```bash |
| 20 | +bin/console make:filter <type> <name> |
| 21 | +``` |
| 22 | +Where `<type>` is the filter type and `<name>` is the name of the filter class. |
| 23 | +Supported types are `orm` and `odm` |
| 24 | + |
| 25 | +> [!NOTE] |
| 26 | +> Elasticsearch filters are not yet supported |
| 27 | +
|
| 28 | +### Create a State Provider |
| 29 | + |
| 30 | +You can create a State Provider class using the following command: |
| 31 | + |
| 32 | +```bash |
| 33 | +bin/console make:state-provider <name> |
| 34 | +``` |
| 35 | + |
| 36 | +### Create a State Processor |
| 37 | + |
| 38 | +You can create a State Processor class using the following command: |
| 39 | + |
| 40 | +```bash |
| 41 | +bin/console make:state-processor <name> |
| 42 | +``` |
| 43 | + |
| 44 | +## Configuration |
| 45 | + |
| 46 | +You can disable the maker commands by setting the following configuration in your `config/packages/api_platform.yaml` file: |
| 47 | + |
| 48 | +```yaml |
| 49 | +api_platform: |
| 50 | + maker: false |
| 51 | +``` |
| 52 | +By default, the maker commands are enabled if the maker bundle is detected. |
| 53 | +
|
| 54 | +### Namespace configuration |
| 55 | +
|
| 56 | +The makers creates all classes in the configured maker bundle root_namespace (default `App`). |
| 57 | +Filters are created in `App\\Filter` |
| 58 | +State Providers are created in `App\\State` |
| 59 | +State Processors are created in `App\\State` |
| 60 | + |
| 61 | +Should you customize the base namespace for all API Platform generated classes you can so in 2 ways: |
| 62 | + |
| 63 | +- Bundle configuration |
| 64 | +- Console Command Option |
| 65 | + |
| 66 | +#### Bundle configuration |
| 67 | + |
| 68 | +To change the default namespace prefix (relative to the maker.root_namespace), you can set the following configuration in your `config/packages/api_platform.yaml` file: |
| 69 | + |
| 70 | +```yaml |
| 71 | +api_platform: |
| 72 | + maker: |
| 73 | + namespace_prefix: 'Api' |
| 74 | +``` |
| 75 | + |
| 76 | +#### Console Command Option |
| 77 | + |
| 78 | +You can override the default namespace prefix by using the `--namespace-prefix` option when running the maker commands: |
| 79 | + |
| 80 | +```bash |
| 81 | +bin/console make:filter orm MyCustomFilter --namespace-prefix Api\\Filter |
| 82 | +bin/console make:state-provider MyProcessor --namespace-prefix Api\\State |
| 83 | +bin/console make:state-processor MyProcessor --namespace-prefix Api\\State |
| 84 | +``` |
| 85 | + |
| 86 | +> [!NOTE] |
| 87 | +> Namespace prefixes passed to the cli command will be relative to the maker.root_namespace and **not** |
| 88 | +> the configured API Platform namepace_prefix. |
| 89 | + |
0 commit comments