-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "Messenger auto_setup" checker (#300)
Co-authored-by: Felix Schneider <69912882+schneider-felix@users.noreply.github.com>
- Loading branch information
1 parent
fc04ea7
commit bb7e1b4
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
src/Components/Health/Checker/PerformanceChecker/MessengerAutoSetupChecker.php
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,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); | ||
} | ||
} |