Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126623 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id C573E1A00BC for ; Fri, 7 Mar 2025 18:40:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1741372680; bh=TMWeY8JH4wwjt8ZYgCVtTNbRccAdo4KSy2zhlZHf+tU=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Mu2FDz257CnElMD5AuxtdhlO5TtyMKRhcYS0D5iFwsOzqlSCR9VR5Lep698uejGnd qEqP2IhzmXWy8TNlicOjima246XeFxp3hpfPpqVFpWVtUnQtbcv71sck7d0+JczwH4 CGlV93UjEJNYrlcWryzzP8MqvgX8yHSvJb0NsFOwfnPkSY4En92QZ/9di7p/3r+XqL SqodYpfZE7/k6ThuHZJhNOfQvQxiWQAbik4p1f0gDQYhXeOcL+lYyZN65N9esWwGfR rRNcSXMBDQ+F5t9BNx/YZmW/iPVja7k4fl0cDmu50mHYrvWYv3x/4IcU6IwFUyF/GG VQnY3txcBjeTw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7EAEA18007C for ; Fri, 7 Mar 2025 18:37:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_20,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-yb1-f175.google.com (mail-yb1-f175.google.com [209.85.219.175]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 7 Mar 2025 18:37:59 +0000 (UTC) Received: by mail-yb1-f175.google.com with SMTP id 3f1490d57ef6-e53a91756e5so1774027276.1 for ; Fri, 07 Mar 2025 10:40:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741372834; x=1741977634; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=BF+XD0Qt3nkksperqvA0ErsEmCLwX0zVTmShZJ5flGY=; b=lHMrQ1OxslcUx7YJAy+zLQbRMUcVZDdBwYJ6ZvVrxOPWWG8LWZ9246SYAsjhCt4TuR 7W3rHoGn6a/yFmsaNSniesi19ert+onwUTV6R6FXNRvUCKwAbfQThB5KKcCF5PTjZL1G bNdvLrKX4dMdTzfwZgI26EwB6z3H5GKug8XA7YINEFokPRvj7qZnHf1OioVy70SOrxRf 69t9/N6UYr4M4dkxKzPA9il1WjP5HqjIZflb2MuBDxXUz9YVgwPwamAVt+fK0YWTUHsQ 5F92bbZMzqJ6Gi8++vhqujuseZCzxZfv8lXDt6q09kGFZgmcUuqi95c7qcBQmBJM6bpJ xz+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741372834; x=1741977634; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=BF+XD0Qt3nkksperqvA0ErsEmCLwX0zVTmShZJ5flGY=; b=GBeq7x4xkvaiBt3E+6pKGiz5nRoumMyb4ALhp+o4meOM0q9Sy4/fMOdLHcrjYvAPPf 0Tf4JWcLmIqwad6WcGWInvRdT0VPxHozQK9QquvGYE5eghpjiKBqZ8dQhFsVf/y7Vi+r 4uqzdiQMYmM7vh5IAGtvhpTrMwSWWvbXojkE8+VNYx99fpl5vo6DKTjdFS/V7a0UOgCO 4EE1w94gx7gDPx+Xlz2aNExitV0eRp85yVTyJRAR+8jWblu82UVR62knAuGRVZO5aMLY ykS4mipeGnESz1Oa8m02RYaPEF/+wkM8vlYXEC+UnIsh8N8o99BJQhtMCO/RDVcSmuSc 8gYQ== X-Gm-Message-State: AOJu0Yz1tgv0WG5zJlNv3CvGDwTz46RWLRsXz6mD+/LCXmAskQ1om0ra PuKYs5j8Clqi7cRtTa5sVLwJosTIDFOclKZbw487iK5P4VAN/4sNoooANWLjirlcK5FppYggCjq igFEnNIJ/ytEFALkgFnWw/28W/ZY= X-Gm-Gg: ASbGnctS7sgGYMrVOMxq3RxuzUKMesfq1N48qjkTp/1jNlKPz6/isNY2GeurxyrXT2l FklJSuecH24f2V24qgydHfEvi3dZNoU6n/Q4T6Flw2Dp8YdX5P9Y7ylioIIItlhQltT5vAnOkpY 9vzPHcbQs7emQJSIwzgPaJzaxSxw== X-Google-Smtp-Source: AGHT+IEdSkuZ2ypXDtlX6cEPtV+z6nf75kfuvx5ZhwmPZ1VxBsApV/3FPjVonV6JiZ5XJpKURfkdwK2HNACb4tEKyY0= X-Received: by 2002:a05:6902:1686:b0:e39:8e5f:adab with SMTP id 3f1490d57ef6-e635c1c437emr7126671276.39.1741372833783; Fri, 07 Mar 2025 10:40:33 -0800 (PST) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <9964db8c-0ffe-43d5-8246-47fc76b07180@app.fastmail.com> <78a03dd0-fd4a-4f4a-ad8a-37e5704f06fc@app.fastmail.com> <23e162f6-54b0-4564-9d79-7b3bdc3d1ab5@rwec.co.uk> <36cee7e3-2ef8-4f96-a72e-e67a99e5f9bb@rwec.co.uk> <779046a0-7c70-45a9-82c4-7c31c502cec2@rwec.co.uk> <1084afab-e3d7-4fcb-9e09-63c159bc9e10@app.fastmail.com> In-Reply-To: <1084afab-e3d7-4fcb-9e09-63c159bc9e10@app.fastmail.com> Date: Fri, 7 Mar 2025 20:40:22 +0200 X-Gm-Features: AQ5f1JrvenM3xQ0RI32RHCT031AwLuLckyEKttWegvFvdSJJNKnQvM40_mTdy08 Message-ID: Subject: Re: Fwd: [PHP-DEV] PHP True Async RFC To: Rob Landers Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="0000000000002deb41062fc4f507" From: edmond.ht@gmail.com (Edmond Dantes) --0000000000002deb41062fc4f507 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable > > 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=E2=80=99m 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. --0000000000002deb41062fc4f507 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

>
>=C2=A0This sounds like you are not using DI meant for fibers/multiple requ= ests at the same time.
>

Spiral already supports = DI containers based on Scope (like "per request" injection= s). Symfony, if I=E2=80=99m not mistaken, does too.

Spiral introduces a restriction to ensure correct handling of Scope depe= ndencies: they cannot be mixed with regular dependencies. If a Scope depend= ency is needed inside a regular dependency, then (using the same approach t= hat Larry already showed), it should be done through an additional interfac= e:

```php
final class UserScope
{
=C2=A0 =C2=A0 public funct= ion __construct(
=C2=A0 =C2=A0 =C2=A0 =C2=A0 private readonly ContainerI= nterface $container
=C2=A0 =C2=A0 ) {
=C2=A0 =C2=A0 }

=C2=A0 = =C2=A0 public function getUserContext(): ?UserContext
=C2=A0 =C2=A0 {=C2=A0 =C2=A0 =C2=A0 =C2=A0 // error checking is omitted
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 return $this->container->get(UserContext::class);
= =C2=A0 =C2=A0 }

=C2=A0 =C2=A0 public function getName(): string
= =C2=A0 =C2=A0 {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return $this->getUserCont= ext()->getName();
=C2=A0 =C2=A0 }
}
```

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 mi= nimal modifications.=C2=A0=C2=A0

---

Ed.

--0000000000002deb41062fc4f507--