Re: Fwd: [PHP-DEV] PHP True Async RFC
| From: | Edmond Dantes | Date: | Fri, 07 Mar 2025 18:40:22 +0000 |
| Subject: | Re: Fwd: [PHP-DEV] PHP True Async RFC | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-126623@lists.php.net to get a copy of this message | ||
>
> This sounds like you are not using DI meant for fibers/multiple requests
at the same time.
>
Spiral already supports DI containers based on *Scope *(like "per request"
injections). Symfony, if I’m not mistaken, does too.
Spiral introduces a restriction to ensure correct handling of Scope
dependencies: they cannot be mixed with regular dependencies. If a Scope
dependency is needed inside a regular dependency, then (using the same
approach that Larry already showed), it should be done through an
additional interface:
```php
final class UserScope
{
public function __construct(
private readonly ContainerInterface $container
) {
}
public function getUserContext(): ?UserContext
{
// error checking is omitted
return $this->container->get(UserContext::class);
}
public function getName(): string
{
return $this->getUserContext()->getName();
}
}
```
At the beginning of a request, Spiral initializes a memory area with Scope
dependencies, so it can be said that it is already prepared to work with
coroutines with minimal modifications.
---
Ed.