Skip to content

Commit 9897bdb

Browse files
authored
Allow logger to be a service reference (#899)
1 parent 19cb313 commit 9897bdb

File tree

7 files changed

+40
-6
lines changed

7 files changed

+40
-6
lines changed

phpstan-baseline.neon

+21-1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ parameters:
7070
count: 2
7171
path: src/DependencyInjection/SentryExtension.php
7272

73+
-
74+
message: "#^Cannot access offset 'logger' on mixed\\.$#"
75+
count: 1
76+
path: src/DependencyInjection/SentryExtension.php
77+
7378
-
7479
message: "#^Cannot access offset 'traces_sampler' on mixed\\.$#"
7580
count: 1
@@ -92,7 +97,7 @@ parameters:
9297

9398
-
9499
message: "#^Parameter \\#1 \\$id of class Symfony\\\\Component\\\\DependencyInjection\\\\Reference constructor expects string, mixed given\\.$#"
95-
count: 9
100+
count: 10
96101
path: src/DependencyInjection/SentryExtension.php
97102

98103
-
@@ -165,6 +170,21 @@ parameters:
165170
count: 1
166171
path: src/EventListener/LoginListener.php
167172

173+
-
174+
message: "#^Instanceof between Throwable and Symfony\\\\Component\\\\Messenger\\\\Exception\\\\DelayedMessageHandlingException will always evaluate to false\\.$#"
175+
count: 1
176+
path: src/EventListener/MessengerListener.php
177+
178+
-
179+
message: "#^Instanceof between Throwable and Symfony\\\\Component\\\\Messenger\\\\Exception\\\\HandlerFailedException will always evaluate to false\\.$#"
180+
count: 1
181+
path: src/EventListener/MessengerListener.php
182+
183+
-
184+
message: "#^Result of && is always false\\.$#"
185+
count: 2
186+
path: src/EventListener/MessengerListener.php
187+
168188
-
169189
message: "#^Call to an undefined method Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\KernelEvent\\:\\:isMasterRequest\\(\\)\\.$#"
170190
count: 1

src/DependencyInjection/SentryExtension.php

+4
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ private function registerConfiguration(ContainerBuilder $container, array $confi
9494
});
9595
}
9696

97+
if (isset($options['logger'])) {
98+
$options['logger'] = new Reference($options['logger']);
99+
}
100+
97101
if (isset($options['traces_sampler'])) {
98102
$options['traces_sampler'] = new Reference($options['traces_sampler']);
99103
}

tests/DependencyInjection/Fixtures/php/full.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
'attach_metric_code_locations' => true,
2222
'context_lines' => 0,
2323
'environment' => 'development',
24-
'logger' => 'php',
24+
'logger' => Sentry\Logger\DebugStdOutLogger::class,
2525
'spotlight' => true,
2626
'spotlight_url' => 'http://localhost:8969',
2727
'release' => '4.0.x-dev',

tests/DependencyInjection/Fixtures/xml/full.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
attach-metric-code-locations="true"
2121
context-lines="0"
2222
environment="development"
23-
logger="php"
23+
logger="Sentry\Logger\DebugStdOutLogger"
2424
spotlight="true"
2525
spotlight-url="http://localhost:8969"
2626
release="4.0.x-dev"

tests/DependencyInjection/Fixtures/yml/full.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ sentry:
1616
attach_metric_code_locations: true
1717
context_lines: 0
1818
environment: development
19-
logger: php
19+
logger: Sentry\Logger\DebugStdOutLogger
2020
spotlight: true
2121
spotlight_url: http://localhost:8969
2222
release: 4.0.x-dev

tests/DependencyInjection/SentryExtensionTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use PHPUnit\Framework\TestCase;
1010
use Psr\Log\NullLogger;
1111
use Sentry\ClientInterface;
12+
use Sentry\Logger\DebugStdOutLogger;
1213
use Sentry\Options;
1314
use Sentry\SentryBundle\DependencyInjection\SentryExtension;
1415
use Sentry\SentryBundle\EventListener\ConsoleListener;
@@ -211,7 +212,7 @@ public function testClientIsCreatedFromOptions(): void
211212
'attach_metric_code_locations' => true,
212213
'context_lines' => 0,
213214
'environment' => 'development',
214-
'logger' => 'php',
215+
'logger' => new Reference(DebugStdOutLogger::class),
215216
'spotlight' => true,
216217
'spotlight_url' => 'http://localhost:8969',
217218
'release' => '4.0.x-dev',

tests/EventListener/Fixtures/UserWithIdentifierStub.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,29 @@
99
final class UserWithIdentifierStub implements UserInterface
1010
{
1111
/**
12-
* @var string
12+
* @var non-empty-string
1313
*/
1414
private $username;
1515

16+
/**
17+
* @param non-empty-string $username
18+
*/
1619
public function __construct(string $username = 'foo_user')
1720
{
1821
$this->username = $username;
1922
}
2023

24+
/**
25+
* @return non-empty-string
26+
*/
2127
public function getUserIdentifier(): string
2228
{
2329
return $this->getUsername();
2430
}
2531

32+
/**
33+
* @return non-empty-string
34+
*/
2635
public function getUsername(): string
2736
{
2837
return $this->username;

0 commit comments

Comments
 (0)