Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow logger to be a service reference #899

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ parameters:
count: 2
path: src/DependencyInjection/SentryExtension.php

-
message: "#^Cannot access offset 'logger' on mixed\\.$#"
count: 1
path: src/DependencyInjection/SentryExtension.php

-
message: "#^Cannot access offset 'traces_sampler' on mixed\\.$#"
count: 1
Expand All @@ -92,7 +97,7 @@ parameters:

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

-
Expand Down Expand Up @@ -165,6 +170,21 @@ parameters:
count: 1
path: src/EventListener/LoginListener.php

-
message: "#^Instanceof between Throwable and Symfony\\\\Component\\\\Messenger\\\\Exception\\\\DelayedMessageHandlingException will always evaluate to false\\.$#"
count: 1
path: src/EventListener/MessengerListener.php

-
message: "#^Instanceof between Throwable and Symfony\\\\Component\\\\Messenger\\\\Exception\\\\HandlerFailedException will always evaluate to false\\.$#"
count: 1
path: src/EventListener/MessengerListener.php

-
message: "#^Result of && is always false\\.$#"
count: 2
path: src/EventListener/MessengerListener.php

-
message: "#^Call to an undefined method Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\KernelEvent\\:\\:isMasterRequest\\(\\)\\.$#"
count: 1
Expand Down
4 changes: 4 additions & 0 deletions src/DependencyInjection/SentryExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ private function registerConfiguration(ContainerBuilder $container, array $confi
});
}

if (isset($options['logger'])) {
$options['logger'] = new Reference($options['logger']);
}

if (isset($options['traces_sampler'])) {
$options['traces_sampler'] = new Reference($options['traces_sampler']);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/DependencyInjection/Fixtures/php/full.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
'attach_metric_code_locations' => true,
'context_lines' => 0,
'environment' => 'development',
'logger' => 'php',
'logger' => Sentry\Logger\DebugStdOutLogger::class,
'spotlight' => true,
'spotlight_url' => 'http://localhost:8969',
'release' => '4.0.x-dev',
Expand Down
2 changes: 1 addition & 1 deletion tests/DependencyInjection/Fixtures/xml/full.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
attach-metric-code-locations="true"
context-lines="0"
environment="development"
logger="php"
logger="Sentry\Logger\DebugStdOutLogger"
spotlight="true"
spotlight-url="http://localhost:8969"
release="4.0.x-dev"
Expand Down
2 changes: 1 addition & 1 deletion tests/DependencyInjection/Fixtures/yml/full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ sentry:
attach_metric_code_locations: true
context_lines: 0
environment: development
logger: php
logger: Sentry\Logger\DebugStdOutLogger
spotlight: true
spotlight_url: http://localhost:8969
release: 4.0.x-dev
Expand Down
3 changes: 2 additions & 1 deletion tests/DependencyInjection/SentryExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use PHPUnit\Framework\TestCase;
use Psr\Log\NullLogger;
use Sentry\ClientInterface;
use Sentry\Logger\DebugStdOutLogger;
use Sentry\Options;
use Sentry\SentryBundle\DependencyInjection\SentryExtension;
use Sentry\SentryBundle\EventListener\ConsoleListener;
Expand Down Expand Up @@ -211,7 +212,7 @@ public function testClientIsCreatedFromOptions(): void
'attach_metric_code_locations' => true,
'context_lines' => 0,
'environment' => 'development',
'logger' => 'php',
'logger' => new Reference(DebugStdOutLogger::class),
'spotlight' => true,
'spotlight_url' => 'http://localhost:8969',
'release' => '4.0.x-dev',
Expand Down
11 changes: 10 additions & 1 deletion tests/EventListener/Fixtures/UserWithIdentifierStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,29 @@
final class UserWithIdentifierStub implements UserInterface
{
/**
* @var string
* @var non-empty-string
*/
private $username;

/**
* @param non-empty-string $username
*/
public function __construct(string $username = 'foo_user')
{
$this->username = $username;
}

/**
* @return non-empty-string
*/
public function getUserIdentifier(): string
{
return $this->getUsername();
}

/**
* @return non-empty-string
*/
public function getUsername(): string
{
return $this->username;
Expand Down
Loading