Skip to content

Commit b2bac1e

Browse files
committed
remove service provider laravel see #7014
1 parent 784b209 commit b2bac1e

File tree

6 files changed

+13
-168
lines changed

6 files changed

+13
-168
lines changed

core/filters.md

Lines changed: 4 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -78,27 +78,14 @@ services:
7878
- name: 'api_platform.parameter_provider'
7979
key: 'ApiPlatform\Tests\Fixtures\TestBundle\Parameter\CustomGroupParameterProvider'
8080
```
81-
or if you are using Laravel tag your provider with:
8281
83-
```php
84-
<?php
82+
With Laravel the services are automatically tagged.
8583
86-
namespace App\Providers;
84+
### Declare a filter with Laravel
8785
88-
use ApiPlatform\State\Provider\ParameterProvider;
89-
use ApiPlatform\Tests\Fixtures\TestBundle\Parameter\CustomGroupParameterProvider;
90-
use Illuminate\Support\ServiceProvider;
86+
Filters are classes implementing our `ApiPlatform\Laravel\Eloquent\Filter\FilterInterface`, use [our code](https://github.com/api-platform/core/tree/main/src/Laravel/Eloquent/Filter) as examples. Filters are automatically registered and tagged by our `ServiceProvider`.
9187

92-
class AppServiceProvider extends ServiceProvider
93-
{
94-
public function register(): void
95-
{
96-
$this->app->tag([CustomGroupParameterProvider::class], ParameterProvider::class);
97-
}
98-
}
99-
```
100-
101-
### Call a filter with Symfony
88+
### Declare a filter with Symfony
10289

10390
A Parameter can also call a filter and works on filters that impact the data persistence layer (Doctrine ORM, ODM and Eloquent filters are supported). Let's assume, that we have an Order filter declared:
10491

@@ -132,51 +119,6 @@ class Offer {
132119
}
133120
```
134121

135-
### Call a filter with Laravel
136-
137-
A Parameter can also call a filter and works on filters that impact the data persistence layer (Doctrine ORM, ODM and Eloquent filters are supported). Let's assume, that we have an Order filter declared:
138-
139-
```php
140-
<?php
141-
142-
namespace App\Providers;
143-
144-
use ApiPlatform\Laravel\Eloquent\Filter\OrderFilter;
145-
use ApiPlatform\Metadata\ApiFilter;
146-
use Illuminate\Support\ServiceProvider;
147-
148-
class AppServiceProvider extends ServiceProvider
149-
{
150-
$public function register(): void
151-
{
152-
$this->app->singleton(OrderFilter::class, function ($app) {
153-
return new OrderFilter(['id' => null, 'name' => null], 'order');
154-
});
155-
156-
$this->app->tag([OrderFilter::class], ApiFilter::class);
157-
}
158-
}
159-
```
160-
161-
We can use this filter specifying we want a query parameter with the `:property` placeholder:
162-
163-
```php
164-
namespace App\ApiResource;
165-
166-
use ApiPlatform\Metadata\QueryParameter;
167-
168-
#[GetCollection(
169-
uriTemplate: 'orders',
170-
parameters: [
171-
'order[:property]' => new QueryParameter(filter: 'offer.order_filter'),
172-
]
173-
)
174-
class Offer {
175-
public string $id;
176-
public string $name;
177-
}
178-
```
179-
180122
### Header parameters
181123

182124
The `HeaderParameter` attribute allows to create a parameter that's using HTTP Headers instead of query parameters:

core/identifiers.md

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ To help with your development experience, we introduced an identifier normalizat
55

66
## Custom Identifier Normalizer
77

8+
> [!WARNING]
9+
> This feature is not yet available with Laravel, if you need it please open a Feature Request issue!
10+
811
> In the following chapter, we're assuming that `App\Uuid` is a project-owned class that manages a time-based UUID.
912
1013
Let's say you have the following class, which is identified by a `UUID` type. In this example, `UUID` is not a simple string but an object with many attributes.
@@ -13,7 +16,7 @@ Let's say you have the following class, which is identified by a `UUID` type. In
1316

1417
```php
1518
<?php
16-
// api/src/ApiResource/Person.php with Symfony or app/ApiResource/Person.php with Laravel
19+
// api/src/ApiResource/Person.php with Symfony
1720
namespace App\ApiResource;
1821

1922
use ApiPlatform\Metadata\ApiProperty;
@@ -62,7 +65,7 @@ Let's create a `Provider` for the `Person` resource:
6265

6366
```php
6467
<?php
65-
// api/src/State/PersonProvider.php with Symfony or app/State/PersonProvider.php with Laravel
68+
// api/src/State/PersonProvider.php with Symfony
6669

6770
namespace App\State;
6871

@@ -91,7 +94,7 @@ This case is covered by an URI variable transformer:
9194

9295
```php
9396
<?php
94-
// api/src/Identifier/UuidUriVariableTransformer.php with Symfony or app/Identifier/UuidUriVariableTransformer.php with Laravel
97+
// api/src/Identifier/UuidUriVariableTransformer.php with Symfony
9598
namespace App\Identifier;
9699

97100
use ApiPlatform\Api\UriVariableTransformerInterface;
@@ -166,28 +169,6 @@ services:
166169

167170
Your `PersonProvider` will now work as expected!
168171

169-
### Tag the Service using Laravel
170-
171-
```php
172-
<?php
173-
174-
namespace App\Providers;
175-
176-
use App\Identifier\UuidUriVariableTransformer;
177-
use ApiPlatform\Metadata\UriVariableTransformerInterface;
178-
use Illuminate\Support\ServiceProvider;
179-
180-
class AppServiceProvider extends ServiceProvider
181-
{
182-
public function register(): void
183-
{
184-
$this->app->tag([UuidUriVariableTransformer::class], UriVariableTransformerInterface::class);
185-
}
186-
}
187-
```
188-
189-
Your `PersonProvider` will now work as expected!
190-
191172
## Changing Identifier in a Doctrine Entity
192173

193174
If your resource is also a Doctrine entity and you want to use another identifier other than the Doctrine one, you have to unmark it:

core/openapi.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ API documentation in a user friendly way.
1515

1616
## Using the OpenAPI Command
1717

18-
> [!WARNING]
19-
> These commands are not yet available with Laravel, you're welcome to contribute [on GitHub](https://github.com/api-platform/core)
20-
2118
You can also dump an OpenAPI specification for your API.
2219

2320
OpenAPI, JSON format:
@@ -26,7 +23,7 @@ OpenAPI, JSON format:
2623
bin/console api:openapi:export
2724
```
2825

29-
OpenAPI, YAML format:
26+
OpenAPI, YAML format (you need to install `symfony/yaml` for this to work):
3027

3128
```console
3229
bin/console api:openapi:export --yaml

core/state-processors.md

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -264,32 +264,6 @@ final class UserProcessor implements ProcessorInterface
264264
}
265265
```
266266

267-
Don't forget to tag the service with the `PersistProcessor` and the `RemoveProcessor` state classes.
268-
269-
```php
270-
<?php
271-
272-
namespace App\Providers;
273-
274-
use ApiPlatform\Laravel\Eloquent\State\PersistProcessor;
275-
use ApiPlatform\Laravel\Eloquent\State\RemoveProcessor;
276-
use App\State\UserProcessor;
277-
use Illuminate\Support\ServiceProvider;
278-
279-
class AppServiceProvider extends ServiceProvider
280-
{
281-
public function register(): void
282-
{
283-
$this->app->tag([UserProcessor::class], [PersistProcessor::class, RemoveProcessor::class,]);
284-
}
285-
286-
public function boot(): void
287-
{
288-
}
289-
}
290-
```
291-
If you're using Laravel MongoDB ODM instead of Eloquent ORM, make sure you're using the right services.
292-
293267
Finally, configure that you want to use this processor on the User resource:
294268

295269
```php

core/state-providers.md

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -309,42 +309,18 @@ class Book {}
309309

310310
#### Laravel State Provider mechanism
311311

312-
First, don't forget to tag the service with the `ProviderInterface`
312+
Declare a class that implements our `ProviderInterface`
313313

314314
```php
315315
<?php
316-
317-
namespace App\Providers;
318-
319-
use ApiPlatform\State\ProviderInterface;
320-
use App\State\BookStateProvider;
321-
use Illuminate\Support\ServiceProvider;
322-
323-
class AppServiceProvider extends ServiceProvider
324-
{
325-
public function register(): void
326-
{
327-
$this->app->tag([BookRepresentationProvider::class], ProviderInterface::class);
328-
}
329-
330-
public function boot(): void
331-
{
332-
}
333-
}
334-
```
335-
336-
After that, you can inject the `ProviderInterface`
337-
```php
338-
<?php
339-
// api/src/State/BlogPostProvider.php
316+
// api/app/State/BlogPostProvider.php
340317

341318
namespace App\State;
342319

343320
use App\Dto\AnotherRepresentation;
344321
use App\Models\Book;
345322
use ApiPlatform\Metadata\Operation;
346323
use ApiPlatform\State\ProviderInterface;
347-
use Symfony\Component\DependencyInjection\Attribute\Autowire;
348324

349325
/**
350326
* @implements ProviderInterface<AnotherRepresentation>

laravel/index.md

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -235,31 +235,6 @@ final class BookProvider implements ProviderInterface
235235
}
236236
```
237237

238-
Register the state provider:
239-
240-
```php
241-
<?php
242-
243-
namespace App\Providers;
244-
245-
use App\State\BookProvider;
246-
use ApiPlatform\State\ProviderInterface;
247-
use Illuminate\Contracts\Foundation\Application;
248-
use Illuminate\Support\ServiceProvider;
249-
250-
class ApiServiceProvider extends ServiceProvider
251-
{
252-
public function register(): void
253-
{
254-
$this->app->singleton(BookProvider::class, function (Application $app) {
255-
return new BookProvider();
256-
});
257-
258-
$this->app->tag([BookProvider::class], ProviderInterface::class);
259-
}
260-
}
261-
```
262-
263238
Apply the provider to your operation:
264239

265240
```php

0 commit comments

Comments
 (0)