Skip to content
Open
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
1 change: 1 addition & 0 deletions symfony/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ Modify these files as described in these patches:
```console
docker compose exec php bin/console make:entity --api-resource
```
For more information on the available makers see [Maker documentation](./maker.md).

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.
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.
Expand Down
89 changes: 89 additions & 0 deletions symfony/maker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Symfony maker commands

API Platform comes with a set of maker commands to help you create API Resources and other related classes.

## Available commands

### Create an entity that is an API Resource

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:

```bash
bin/console make:entity --api-resource
```

### Create an API Filter

You can create an API Filter class using the following command:

```bash
bin/console make:filter <type> <name>
```
Where `<type>` is the filter type and `<name>` is the name of the filter class.
Supported types are `orm` and `odm`

> [!NOTE]
> Elasticsearch filters are not yet supported

### Create a State Provider

You can create a State Provider class using the following command:

```bash
bin/console make:state-provider <name>
```

### Create a State Processor

You can create a State Processor class using the following command:

```bash
bin/console make:state-processor <name>
```

## Configuration

You can disable the maker commands by setting the following configuration in your `config/packages/api_platform.yaml` file:

```yaml
api_platform:
maker: false
```
By default, the maker commands are enabled if the maker bundle is detected.

### Namespace configuration

The makers creates all classes in the configured maker bundle root_namespace (default `App`).
Filters are created in `App\\Filter`
State Providers are created in `App\\State`
State Processors are created in `App\\State`

Should you customize the base namespace for all API Platform generated classes you can so in 2 ways:

- Bundle configuration
- Console Command Option

#### Bundle configuration

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:

```yaml
api_platform:
maker:
namespace_prefix: 'Api'
```

#### Console Command Option

You can override the default namespace prefix by using the `--namespace-prefix` option when running the maker commands:

```bash
bin/console make:filter orm MyCustomFilter --namespace-prefix Api\\Filter
bin/console make:state-provider MyProcessor --namespace-prefix Api\\State
bin/console make:state-processor MyProcessor --namespace-prefix Api\\State
```

> [!NOTE]
> Namespace prefixes passed to the cli command will be relative to the maker.root_namespace and **not**
> the configured API Platform namepace_prefix.