Skip to content

Commit

Permalink
Compression method check: Merge checks into one class
Browse files Browse the repository at this point in the history
  • Loading branch information
M-arcus committed Sep 2, 2024
1 parent fdf4ed7 commit 398ace5
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 114 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

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 CompressionMethodChecker implements PerformanceCheckerInterface, CheckerInterface
{
public const DOCUMENTATION_URL = 'https://developer.shopware.com/docs/guides/hosting/performance/performance-tweaks.html#using-zstd-instead-of-gzip-for-compression';

public function __construct(
#[Autowire('%kernel.shopware_version%')]
public readonly string $shopwareVersion,
#[Autowire('%shopware.cache.cache_compression%')]
public readonly bool $cacheCompressionEnabled,
#[Autowire('%shopware.cache.cache_compression_method%')]
public readonly string $cacheCompressionMethod,
#[Autowire('%shopware.cart.compress%')]
public readonly bool $cartCompressionEnabled,
#[Autowire('%shopware.cart.compression_method%')]
public readonly string $cartCompressionMethod,
) {}

public function collect(HealthCollection $collection): void
{
if (\version_compare('6.6.4.0', $this->shopwareVersion, '>')) {
return;
}

$this->checkCompression($collection, 'Cache', $this->cacheCompressionEnabled, $this->cacheCompressionMethod);
$this->checkCompression($collection, 'Cart', $this->cartCompressionEnabled, $this->cartCompressionMethod);
}

private function checkCompression(HealthCollection $collection, string $functionality, bool $enabled, string $method): void
{
if (!$enabled) {
$collection->add(
SettingsResult::warning(
strtolower($functionality) . '-compress',
$functionality . ' compression',
'disabled',
'enabled',
self::DOCUMENTATION_URL,
),
);

return;
}

if ($method === 'gzip') {
$collection->add(
SettingsResult::warning(
strtolower($functionality) . '-compression-method',
$functionality . ' compression method',
'gzip',
'zstd',
self::DOCUMENTATION_URL,
),
);

return;
}

if ($method === 'zstd' && !extension_loaded('zstd')) {
$collection->add(
SettingsResult::error(
strtolower($functionality) . '-compression-method-extension-zstd',
'PHP extension zstd for ' . $functionality . ' compression method',
'disabled',
'enabled',
self::DOCUMENTATION_URL,
),
);
}
}
}

0 comments on commit 398ace5

Please sign in to comment.