Skip to content

Commit 99e47a5

Browse files
committed
docs(symfony/maker): add documentation for the maker with new namespace prefix support
1 parent ab5fad6 commit 99e47a5

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

symfony/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ Modify these files as described in these patches:
473473
```console
474474
docker compose exec php bin/console make:entity --api-resource
475475
```
476+
For more information on the available makers see [Maker documentation](./maker.md).
476477

477478
Doctrine's [attributes](https://www.doctrine-project.org/projects/doctrine-orm/en/current/reference/attributes-reference.html) map these entities to tables in the database.
478479
Mapping through [annotations](https://www.doctrine-project.org/projects/doctrine-annotations/en/current/index.html) is still supported for backward compatibility, but they are considered deprecated and attributes are now the recommended approach.

symfony/maker.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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+
29+
### Create a State Provider
30+
31+
You can create a State Provider class using the following command:
32+
33+
```bash
34+
bin/console make:state-provider <name>
35+
```
36+
37+
### Create a State Processor
38+
39+
You can create a State Processor class using the following command:
40+
41+
```bash
42+
bin/console make:state-processor <name>
43+
```
44+
45+
## Configuration
46+
47+
You can disable the maker commands by setting the following configuration in your `config/packages/api_platform.yaml` file:
48+
49+
```yaml
50+
api_platform:
51+
maker: false
52+
```
53+
By default, the maker commands are enabled if the maker bundle is detected.
54+
55+
### Namespace configuration
56+
57+
The makers creates all classes in the configured maker bundle root_namespace (default `App`).
58+
Filters are created in `App\\Filter`
59+
State Providers are created in `App\\State`
60+
State Processors are created in `App\\State`
61+
62+
Should you customize the base namespace for all Api Platform generated classes you can so in 2 ways:
63+
64+
- Bundle configuration
65+
- Console Command Option
66+
67+
#### Bundle configuration
68+
69+
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:
70+
71+
```yaml
72+
api_platform:
73+
maker:
74+
namespace_prefix: 'Api'
75+
```
76+
77+
#### Console Command Option
78+
79+
You can override the default namespace prefix by using the `--namespace-prefix` option when running the maker commands:
80+
81+
```bash
82+
bin/console make:filter orm MyCustomFilter --namespace-prefix Api\\Filter
83+
bin/console make:state-provider MyProcessor --namespace-prefix Api\\State
84+
bin/console make:state-processor MyProcessor --namespace-prefix Api\\State
85+
```
86+
87+
> [!NOTE]
88+
> Namespace prefixes passed to the cli command will be relative to the maker.root_namespace and **not**
89+
> the configured api platform namepace_prefix.

0 commit comments

Comments
 (0)