Skip to content

Commit f170802

Browse files
committed
more phpcs
1 parent fb6ecc7 commit f170802

File tree

5 files changed

+93
-86
lines changed

5 files changed

+93
-86
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Monitor;
4+
5+
// start-command-subscriber
6+
class MyCommandSubscriber implements MongoDB\Driver\Monitoring\CommandSubscriber
7+
{
8+
/** @param resource $stream */
9+
public function __construct(private $stream)
10+
{
11+
}
12+
13+
public function commandStarted(MongoDB\Driver\Monitoring\CommandStartedEvent $event): void
14+
{
15+
fwrite($this->stream, sprintf(
16+
'Started command #%d "%s": %s%s',
17+
$event->getRequestId(),
18+
$event->getCommandName(),
19+
MongoDB\BSON\Document::fromPHP($event->getCommand())->toCanonicalExtendedJSON(),
20+
PHP_EOL,
21+
));
22+
}
23+
24+
public function commandSucceeded(MongoDB\Driver\Monitoring\CommandSucceededEvent $event): void
25+
{
26+
}
27+
28+
public function commandFailed(MongoDB\Driver\Monitoring\CommandFailedEvent $event): void
29+
{
30+
}
31+
}
32+
// end-command-subscriber
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
namespace Monitor;
4+
5+
// start-sdam-subscriber
6+
class MySDAMSubscriber implements MongoDB\Driver\Monitoring\SDAMSubscriber
7+
{
8+
/** @param resource $stream */
9+
public function __construct(private $stream)
10+
{
11+
}
12+
13+
public function serverOpening(MongoDB\Driver\Monitoring\ServerOpeningEvent $event): void
14+
{
15+
fprintf(
16+
$this->stream,
17+
'Server opening on %s:%s\n',
18+
$event->getHost(),
19+
$event->getPort(),
20+
PHP_EOL,
21+
);
22+
}
23+
24+
public function serverClosed(MongoDB\Driver\Monitoring\ServerClosedEvent $event): void
25+
{
26+
}
27+
28+
public function serverChanged(MongoDB\Driver\Monitoring\ServerChangedEvent $event): void
29+
{
30+
}
31+
32+
public function serverHeartbeatFailed(MongoDB\Driver\Monitoring\ServerHeartbeatFailedEvent $event): void
33+
{
34+
}
35+
36+
public function serverHeartbeatStarted(MongoDB\Driver\Monitoring\ServerHeartbeatStartedEvent $event): void
37+
{
38+
}
39+
40+
public function serverHeartbeatSucceeded(MongoDB\Driver\Monitoring\ServerHeartbeatSucceededEvent $event): void
41+
{
42+
}
43+
44+
public function topologyChanged(MongoDB\Driver\Monitoring\TopologyChangedEvent $event): void
45+
{
46+
}
47+
48+
public function topologyClosed(MongoDB\Driver\Monitoring\TopologyClosedEvent $event): void
49+
{
50+
}
51+
52+
public function topologyOpening(MongoDB\Driver\Monitoring\TopologyOpeningEvent $event): void
53+
{
54+
}
55+
}
56+
// end-sdam-subscriber

source/includes/monitoring-logging/logging.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
// end-monolog-logger
1414

1515
// start-custom-logger
16-
use Psr\Log\AbstractLogger;
17-
18-
class MyLogger extends AbstractLogger
16+
class MyLogger extends Psr\Log\AbstractLogger
1917
{
2018
public array $logs = [];
2119

source/includes/monitoring-logging/monitor.php

Lines changed: 2 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -2,87 +2,8 @@
22

33
require __DIR__ . '/vendor/autoload.php';
44

5-
// start-command-subscriber
6-
class MyCommandSubscriber implements MongoDB\Driver\Monitoring\CommandSubscriber
7-
{
8-
/** @param resource $stream */
9-
public function __construct(private $stream)
10-
{
11-
}
12-
13-
public function commandStarted(MongoDB\Driver\Monitoring\CommandStartedEvent $event): void
14-
{
15-
fwrite($this->stream, sprintf(
16-
'Started command #%d "%s": %s%s',
17-
$event->getRequestId(),
18-
$event->getCommandName(),
19-
MongoDB\BSON\Document::fromPHP($event->getCommand())->toCanonicalExtendedJSON(),
20-
PHP_EOL,
21-
));
22-
}
23-
24-
public function commandSucceeded(MongoDB\Driver\Monitoring\CommandSucceededEvent $event): void
25-
{
26-
}
27-
28-
public function commandFailed(MongoDB\Driver\Monitoring\CommandFailedEvent $event): void
29-
{
30-
}
31-
}
32-
// end-command-subscriber
33-
34-
// start-sdam-subscriber
35-
class MySDAMSubscriber implements MongoDB\Driver\Monitoring\SDAMSubscriber
36-
{
37-
/** @param resource $stream */
38-
public function __construct(private $stream)
39-
{
40-
}
41-
42-
public function serverOpening(MongoDB\Driver\Monitoring\ServerOpeningEvent $event): void
43-
{
44-
fprintf(
45-
$this->stream,
46-
'Server opening on %s:%s\n',
47-
$event->getHost(),
48-
$event->getPort(),
49-
PHP_EOL,
50-
);
51-
}
52-
53-
public function serverClosed(MongoDB\Driver\Monitoring\ServerClosedEvent $event): void
54-
{
55-
}
56-
57-
public function serverChanged(MongoDB\Driver\Monitoring\ServerChangedEvent $event): void
58-
{
59-
}
60-
61-
public function serverHeartbeatFailed(MongoDB\Driver\Monitoring\ServerHeartbeatFailedEvent $event): void
62-
{
63-
}
64-
65-
public function serverHeartbeatStarted(MongoDB\Driver\Monitoring\ServerHeartbeatStartedEvent $event): void
66-
{
67-
}
68-
69-
public function serverHeartbeatSucceeded(MongoDB\Driver\Monitoring\ServerHeartbeatSucceededEvent $event): void
70-
{
71-
}
72-
73-
public function topologyChanged(MongoDB\Driver\Monitoring\TopologyChangedEvent $event): void
74-
{
75-
}
76-
77-
public function topologyClosed(MongoDB\Driver\Monitoring\TopologyClosedEvent $event): void
78-
{
79-
}
80-
81-
public function topologyOpening(MongoDB\Driver\Monitoring\TopologyOpeningEvent $event): void
82-
{
83-
}
84-
}
85-
// end-sdam-subscriber
5+
use Monitor\MyCommandSubscriber;
6+
use Monitor\MySdamSubscriber;
867

878
$uri = getenv('MONGODB_URI') ?: throw new RuntimeException('Set the MONGODB_URI variable to your connection URI');
889
$client = new MongoDB\Client($uri);

source/monitoring-logging/monitoring.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ the ``CommandSubscriber`` interface. The class defines each ``CommandSubscriber`
126126
and includes custom logic for the ``commandStarted()`` method, which prints details
127127
about each new command that the server receives:
128128

129-
.. literalinclude:: /includes/monitoring-logging/monitor.php
129+
.. literalinclude:: /includes/monitoring-logging/MyCommandSubscriber.php
130130
:start-after: start-command-subscriber
131131
:end-before: end-command-subscriber
132132
:language: php
@@ -193,7 +193,7 @@ the ``SDAMSubscriber`` interface. The class defines each ``SDAMSubscriber`` meth
193193
and includes custom logic for the ``serverOpening()`` method, which prints details
194194
about servers added to the topology:
195195

196-
.. literalinclude:: /includes/monitoring-logging/monitor.php
196+
.. literalinclude:: /includes/monitoring-logging/MySdamSubscriber.php
197197
:start-after: start-sdam-subscriber
198198
:end-before: end-sdam-subscriber
199199
:language: php

0 commit comments

Comments
 (0)