ContainerEventManager cannot remove a service listener by its resolved object
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Start with ContainerEventManager and the service registration, resolution, and removal paths described in the issue. Run the supplied reproduce.php script to confirm that removal leaves a listener registered and one dispatch calls it twice after re-adding. Done means removal by the resolved object leaves no listener, and re-adding it produces exactly one callback; linked pull request #142 is already open.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Bug Description
A listener registered by its DI service name cannot be removed using the object returned by getListeners(). The original registration remains active, and registering the returned object again causes duplicate callbacks. This prevents temporarily suspending a resolved listener through the public event manager API.
Environment
Reproduced with nettrine/orm v0.10.1 (480480c92b0d2f35165fa3e478584cef60fac394), Nette DI3.2.7, Doctrine EventManager2.1.1 and PHP8.5.12. The same lookup mismatch is present in upstream master f2fba56a1a29f3568a378eeaa50628888671d5e8. No database, EntityManager, application bootstrap or custom EventManager subclass is needed.
Steps To Reproduce
In a Composer project with nettrine/orm:0.10.1 installed, save this as reproduce.php in the project root and run php reproduce.php:
<?php declare(strict_types = 1);
require 'vendor/autoload.php';
use Doctrine\Common\EventArgs;
use Nette\DI\Container;
use Nettrine\ORM\Events\ContainerEventManager;
final class ReproducerListener
{
public int $calls = 0;
public function onClear(EventArgs $args): void
{
$this->calls++;
}
}
$listener = new ReproducerListener();
$container = new Container();
$container->addService('listener', static fn (): ReproducerListener => $listener);
$events = new ContainerEventManager($container);
$events->addEventListener('onClear', 'listener');
$resolved = array_values($events->getListeners('onClear'))[0];
$events->removeEventListener('onClear', $resolved);
printf("Listeners after removal: %d\n", count($events->getListeners('onClear')));
$events->addEventListener('onClear', $resolved);
$events->dispatchEvent('onClear');
printf("Calls after one dispatch: %d\n", $listener->calls);
Actual Behavior
Listeners after removal: 1
Calls after one dispatch: 2
Expected Behavior
Listeners after removal: 0
Calls after one dispatch: 1
After removal, the event should have no listeners. Registering the same object again should result in exactly one callback for one dispatch.
Cause
Service registrations retain a service@<name> key after resolution, while object removal looks up the object hash. Re-adding the object creates a second registration. Removal and restoration should work by listener identity while preserving lazy construction, order and subscriptions to other events.
Separate static-analysis context
The full upstream master check with PHPStan 2.3.5 / strict-rules 2.1.1 reports one existing variable.undefined diagnostic for the Binder-bound $this in src/ManagerRegistry.php:54. It is identical on the unchanged master and the listener correction. Ten earlier stable-version diagnostics are already fixed by upstream commits 20cfc18 and f2fba56. They are not part of this listener defect. The proposed upstream listener branch adds no analysis suppression or Binder API change.
- Ngôn ngữ chính
- PHP
- Star
- 60
- Fork
- 33
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue tương tự
-
Activity page icons previewĐang mởbug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
Automattic/static-site-importer#3129 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Group 2 - Data Storage | Tripal DBX | Chado Group 5 - Search | ElasticSearch | Views Priority - Medium
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
-
category::bug code priority::normal
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 85/100
e0ipso/simple_oauth_21#58 ·
Maintainer thường phản hồi trong vòng 1 ngày