Skip to content

Commit b1f6b8d

Browse files
authored
Add "Disable Symfony Secrets" checker (#298)
* Add "Disable Symfony Secrets" checker * Add check if symfony secrets are in use
1 parent ec8e624 commit b1f6b8d

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Frosh\Tools\Components\Health\Checker\PerformanceChecker;
6+
7+
use Frosh\Tools\Components\Health\Checker\CheckerInterface;
8+
use Frosh\Tools\Components\Health\HealthCollection;
9+
use Frosh\Tools\Components\Health\SettingsResult;
10+
use Symfony\Bundle\FrameworkBundle\Secrets\AbstractVault;
11+
use Symfony\Component\DependencyInjection\Attribute\Autowire;
12+
13+
class DisableSymfonySecretsChecker implements PerformanceCheckerInterface, CheckerInterface
14+
{
15+
public function __construct(
16+
#[Autowire(param: 'framework.secrets.enabled')]
17+
private readonly bool $secretsEnabled,
18+
#[Autowire(service: 'secrets.vault')]
19+
private readonly AbstractVault $vault,
20+
#[Autowire(service: 'secrets.local_vault')]
21+
private readonly ?AbstractVault $localVault = null,
22+
) {}
23+
24+
public function collect(HealthCollection $collection): void
25+
{
26+
if ($this->secretsEnabled && !$this->areSecretsInUse()) {
27+
$collection->add(
28+
SettingsResult::info(
29+
'symfony-secrets',
30+
'Disable Symfony Secrets',
31+
'enabled',
32+
'disabled',
33+
'https://developer.shopware.com/docs/guides/hosting/performance/performance-tweaks.html#disable-symfony-secrets',
34+
),
35+
);
36+
}
37+
}
38+
39+
private function areSecretsInUse(): bool
40+
{
41+
return count($this->vault->list()) > 0 || ($this->localVault instanceof AbstractVault && count($this->localVault->list()) > 0);
42+
}
43+
}

src/DependencyInjection/SymfonyConfigCompilerPass.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,9 @@ public function process(ContainerBuilder $container): void
4343
if (!$container->hasParameter('shopware.cache.tagging.each_theme_config')) {
4444
$container->setParameter('shopware.cache.tagging.each_theme_config', true);
4545
}
46+
47+
if (!$container->hasParameter('framework.secrets.enabled')) {
48+
$container->setParameter('framework.secrets.enabled', true);
49+
}
4650
}
4751
}

0 commit comments

Comments
 (0)