Skip to content

Commit

Permalink
Add "Messenger auto_setup" checker (#300)
Browse files Browse the repository at this point in the history
Co-authored-by: Felix Schneider <69912882+schneider-felix@users.noreply.github.com>
  • Loading branch information
M-arcus and schneider-felix authored Dec 9, 2024
1 parent fc04ea7 commit bb7e1b4
Showing 1 changed file with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

declare(strict_types=1);

namespace Frosh\Tools\Components\Health\Checker\PerformanceChecker;

use Frosh\Tools\Components\Health\Checker\CheckerInterface;
use Frosh\Tools\Components\Health\HealthCollection;
use Frosh\Tools\Components\Health\SettingsResult;
use Symfony\Component\DependencyInjection\Attribute\Autowire;

class MessengerAutoSetupChecker implements PerformanceCheckerInterface, CheckerInterface
{
public function __construct(
#[Autowire(param: 'env(MESSENGER_TRANSPORT_DSN)')]
private readonly string $messageTransportDsn,
#[Autowire(param: 'env(MESSENGER_TRANSPORT_LOW_PRIORITY_DSN)')]
private readonly string $messageTransportDsnLowPriority,
#[Autowire(param: 'env(MESSENGER_TRANSPORT_FAILURE_DSN)')]
private readonly string $messageTransportDsnFailure,
) {}

public function collect(HealthCollection $collection): void
{
if ($this->isAutoSetupEnabled($this->messageTransportDsn) || $this->isAutoSetupEnabled($this->messageTransportDsnLowPriority) || $this->isAutoSetupEnabled($this->messageTransportDsnFailure)) {
$collection->add(
SettingsResult::info(
'messenger-auto-setup',
'Messenger auto_setup',
'enabled',
'disabled',
'https://developer.shopware.com/docs/guides/hosting/performance/performance-tweaks.html#disable-auto-setup',
),
);
}
}

private function isAutoSetupEnabled(string $messageTransportDsn): bool
{
$queryParams = \parse_url($messageTransportDsn, \PHP_URL_QUERY);

// Messenger DSN is invalid. Therefore, we can't really check
if ($queryParams === false) {
return false;
}

if ($queryParams === null) {
return true;
}

$query = [];
\parse_str($queryParams, $query);

$query += ['auto_setup' => true];

return filter_var($query['auto_setup'], \FILTER_VALIDATE_BOOL);
}
}

0 comments on commit bb7e1b4

Please sign in to comment.