-
Type: New Feature
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: None
In order to add a subscriber when creating a client, it is currently required to make call a method of the manager that is accessible through the client.
$client = new MongoDB\Client(); $client->getManager()->addSubscriber($subscriber);
This is difficult to use with Symfony Dependency Injection as we have to extend the Client class or use a service Factory.
Proposition: Add an option "subscriber" to the $driverOptions. It can be a Subscriber or a list<Subscriber>
if (isset($driverOptions['subscriber'])) { if ($driverOptions['subscriber'] instanceof Subscriber) { $this->manager->addSubscriber($driverOptions['subscriber']); } elseif (! is_array($driverOptions['subscriber'])) { throw InvalidArgumentException::invalidType('"subscriber" driver option', $driverOptions['subscriber'], Subscriber::class); } else { foreach ($driverOptions['subscriber'] as $subscriber) { if (! $subscriber instanceof Subscriber) { throw InvalidArgumentException::invalidType('"subscriber" driver option', $subscriber, Subscriber::class); } $this->manager->addSubscriber($subscriber); } } unset($driverOptions['subscriber']); }
Alternatively, add proxy methods to the Client class:
public function addSubscriber(Subscriber $subscriber): void { $this->manager->addSubscriber($subscriber); } public function removeSubscriber(Subscriber $subscriber): void { $this->manager->removeSubscriber($subscriber); }
That could be used with a simple call when declaring the MongoDB\Client service in Symfony.
- is related to
-
PHPLIB-1314 Create tutorial for APM
- Backlog