Skip to content

Commit 02c9ce7

Browse files
authored
Deprecate APM\Command::getServer(), add getPort and getHost instead (#2773)
CommandSucceededEvent|CommandFailedEvent::getServer() has been deprecated in ext-mongodb 1.20 and removed in 2.0.0. For backward compatibility: we keep this method in MongoDB ODM, but throw an exception the extension is not compatible. I'm not adding a trigger_deprecation as this is already triggered by the extension method call. The new methods getPort() and getHost() are added as proxy to extension methods that are always available in the required ext-mongodb 1.21+. This is not covered by tests, I can add tests on CommandLogger before merging.
1 parent 3783f0e commit 02c9ce7

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

lib/Doctrine/ODM/MongoDB/APM/Command.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
use MongoDB\Driver\Server;
1212
use Throwable;
1313

14+
use function method_exists;
15+
1416
final class Command
1517
{
1618
private CommandStartedEvent $startedEvent;
@@ -70,11 +72,26 @@ public function getRequestId(): string
7072
return $this->startedEvent->getRequestId();
7173
}
7274

75+
/** @deprecated This method is failing with MongoDB Extension v2.0+, use getHost and getPort instead. */
7376
public function getServer(): Server
7477
{
78+
if (! method_exists($this->finishedEvent, 'getServer')) {
79+
throw new LogicException('getServer() is not available in MongoDB Extension v2.0+');
80+
}
81+
7582
return $this->finishedEvent->getServer();
7683
}
7784

85+
public function getPort(): int
86+
{
87+
return $this->finishedEvent->getPort();
88+
}
89+
90+
public function getHost(): string
91+
{
92+
return $this->finishedEvent->getHost();
93+
}
94+
7895
public function getReply(): object
7996
{
8097
return $this->finishedEvent->getReply();

0 commit comments

Comments
 (0)