You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/services.md
+53-10Lines changed: 53 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,11 +2,54 @@
2
2
3
3
For both [HTTP](http.md) and [CLI](cli.md) applications a service is an object referenced by a name in a [`Container`](https://github.com/Innmind/DI).
4
4
5
-
> [!NOTE]
6
-
> since a container only deals with objects Psalm will complain of type mismatches, so you'll have to suppress those errors (for now).
7
-
8
5
## Defining a service
9
6
7
+
```php
8
+
use Innmind\DI\Service;
9
+
use Innmind\AMQP\Client;
10
+
11
+
/**
12
+
* @template S of object
13
+
* @implements Service<S>
14
+
*/
15
+
enum Services implements Service
16
+
{
17
+
case amqpClient;
18
+
case producerClient;
19
+
case consumerClient;
20
+
21
+
/**
22
+
* @return self<Client>
23
+
*/
24
+
public static function amqpClient(): self
25
+
{
26
+
/** @var self<Client> */
27
+
return self::amqpClient;
28
+
}
29
+
30
+
/**
31
+
* @return self<Client>
32
+
*/
33
+
public static function producerClient(): self
34
+
{
35
+
/** @var self<Client> */
36
+
return self::producerClient;
37
+
}
38
+
39
+
/**
40
+
* @return self<Client>
41
+
*/
42
+
public static function consumerClient(): self
43
+
{
44
+
/** @var self<Client> */
45
+
return self::consumerClient;
46
+
}
47
+
}
48
+
```
49
+
50
+
> [!TIP]
51
+
> If you publish a package you can add an `@internal` flag on the static methods to tell your users to not use the service. And when you plan to remove a service you can use the `@deprecated` flag.
52
+
10
53
```php
11
54
use Innmind\Framework\{
12
55
Main\Http,
@@ -23,7 +66,7 @@ new class extends Http|Cli {
23
66
protected function configure(Application $app): Application
0 commit comments