@@ -8,11 +8,14 @@ Pre-registered resolvers are available and can easily be overridden.
8
8
There are two pre-registered operation path naming services:
9
9
10
10
| Service name | Entity name | Path result |
11
- | -------------------------------------------------------------- | ------------ | --------------- |
11
+ | ---------------------------------------------------------------- | -------------- | ----------------- |
12
12
| ` api_platform.metadata.path_segment_name_generator.underscore ` | ` MyResource ` | ` /my_resources ` |
13
13
| ` api_platform.metadata.path_segment_name_generator.dash ` | ` MyResource ` | ` /my-resources ` |
14
14
15
15
The default resolver is ` api_platform.metadata.path_segment_name_generator.underscore ` .
16
+
17
+ ### Configuration using Symfony
18
+
16
19
To change it to the dash resolver, add the following lines to ` api/config/packages/api_platform.yaml ` :
17
20
18
21
``` yaml
@@ -21,6 +24,19 @@ api_platform:
21
24
path_segment_name_generator : api_platform.metadata.path_segment_name_generator.dash
22
25
` ` `
23
26
27
+ ### Configuration using Laravel
28
+
29
+ To change it to the dash resolver, add the following lines to ` config/api-platform.php`:
30
+
31
+ ` ` ` php
32
+ <?php
33
+ // config/api-platform.php
34
+ return [
35
+ // ....
36
+ 'path_segment_name_generator' => 'api_platform.metadata.path_segment_name_generator.dash'
37
+ ];
38
+ ` ` `
39
+
24
40
# # Create a Custom Operation Path Resolver
25
41
26
42
Let's assume we need URLs without separators (e.g. `api.tld/myresources`)
@@ -31,7 +47,7 @@ Make sure the custom segment generator implements [`ApiPlatform\Metadata\Operati
31
47
32
48
` ` ` php
33
49
<?php
34
- // api/src/Operation/SingularPathSegmentNameGenerator.php
50
+ // api/src/Operation/SingularPathSegmentNameGenerator.php with Symfony or app/Operation/SingularPathSegmentNameGenerator.php with Laravel
35
51
namespace App\O peration;
36
52
37
53
use ApiPlatform\M etadata\O peration\P athSegmentNameGeneratorInterface;
@@ -61,7 +77,7 @@ class SingularPathSegmentNameGenerator implements PathSegmentNameGeneratorInterf
61
77
62
78
Note that `$name` contains a camelCase string, by default the resource class name (e.g. `MyResource`).
63
79
64
- # ## Registering the Service
80
+ # ## Registering the Service (for Symfony only)
65
81
66
82
If you haven't disabled the autowiring option, the service will be registered automatically and you have nothing more to
67
83
do.
@@ -74,10 +90,23 @@ services:
74
90
'App\O peration\S ingularPathSegmentNameGenerator': ~
75
91
` ` `
76
92
77
- # ## Configuring It
93
+ # ## Configuring the Service
94
+
95
+ # ### Configuring It using Symfony
78
96
79
97
` ` ` yaml
80
98
# api/config/packages/api_platform.yaml
81
99
api_platform:
82
100
path_segment_name_generator: 'App\O peration\S ingularPathSegmentNameGenerator'
83
101
` ` `
102
+
103
+ # ### Configuring It using Laravel
104
+
105
+ ` ` ` php
106
+ <?php
107
+ // config/api-platform.php
108
+ return [
109
+ // ....
110
+ 'path_segment_name_generator' => App\O peration\S ingularPathSegmentNameGenerator::class
111
+ ];
112
+ ` ` `
0 commit comments