-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PHPORM-56 Replace Collection proxy class with Driver monitoring
- Loading branch information
Showing
17 changed files
with
93 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace MongoDB\Laravel; | ||
|
||
use MongoDB\Driver\Monitoring\CommandFailedEvent; | ||
use MongoDB\Driver\Monitoring\CommandStartedEvent; | ||
use MongoDB\Driver\Monitoring\CommandSubscriber as CommandSubscriberInterface; | ||
use MongoDB\Driver\Monitoring\CommandSucceededEvent; | ||
|
||
use function get_object_vars; | ||
use function json_encode; | ||
|
||
use const JSON_THROW_ON_ERROR; | ||
|
||
/** @internal */ | ||
final class CommandSubscriber implements CommandSubscriberInterface | ||
{ | ||
/** @var array<string, CommandStartedEvent> */ | ||
private array $commands = []; | ||
|
||
public function __construct(private Connection $connection) | ||
{ | ||
} | ||
|
||
public function commandStarted(CommandStartedEvent $event) | ||
{ | ||
$this->commands[$event->getOperationId()] = $event; | ||
} | ||
|
||
public function commandFailed(CommandFailedEvent $event) | ||
{ | ||
$this->logQuery($event); | ||
} | ||
|
||
public function commandSucceeded(CommandSucceededEvent $event) | ||
{ | ||
$this->logQuery($event); | ||
} | ||
|
||
private function logQuery(CommandSucceededEvent|CommandFailedEvent $event): void | ||
{ | ||
$startedEvent = $this->commands[$event->getOperationId()]; | ||
unset($this->commands[$event->getOperationId()]); | ||
|
||
$command = clone $startedEvent->getCommand(); | ||
unset($command->lsid, $command->txnNumber); | ||
foreach (get_object_vars($command) as $key => $value) { | ||
if ($key[0] === '$') { | ||
unset($command->{$key}); | ||
} | ||
} | ||
|
||
$this->connection->logQuery(json_encode($command, JSON_THROW_ON_ERROR), [], $event->getDurationMicros()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.