Skip to content

Commit 752889e

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

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+
### 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

Comments
 (0)