-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add compression checker for cart and cache
- Loading branch information
Showing
3 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
src/Components/Health/Checker/PerformanceChecker/AbstractCompressionChecker.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,68 @@ | ||
<?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; | ||
|
||
abstract class AbstractCompressionChecker 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( | ||
private readonly string $shopwareVersion, | ||
private readonly string $functionality, | ||
private readonly bool $enabled, | ||
private readonly string $method, | ||
) {} | ||
|
||
public function collect(HealthCollection $collection): void | ||
{ | ||
if (\version_compare('6.6.4.0', $this->shopwareVersion, '>')) { | ||
return; | ||
} | ||
|
||
if (!$this->enabled) { | ||
$collection->add( | ||
SettingsResult::warning( | ||
strtolower($this->functionality) . '-compress', | ||
$this->functionality . ' compression', | ||
'disabled', | ||
'enabled', | ||
self::DOCUMENTATION_URL, | ||
), | ||
); | ||
|
||
return; | ||
} | ||
|
||
if ($this->method === 'gzip') { | ||
$collection->add( | ||
SettingsResult::warning( | ||
strtolower($this->functionality) . '-compression-method', | ||
$this->functionality . ' compression method', | ||
'gzip', | ||
'zstd', | ||
self::DOCUMENTATION_URL, | ||
), | ||
); | ||
|
||
return; | ||
} | ||
|
||
if ($this->method === 'zstd' && !extension_loaded('zstd')) { | ||
$collection->add( | ||
SettingsResult::error( | ||
$this->functionality . '-compression-method-extension-zstd', | ||
'PHP extension zstd for ' . $this->functionality . ' compression method', | ||
'disabled', | ||
'enabled', | ||
self::DOCUMENTATION_URL, | ||
), | ||
); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/Components/Health/Checker/PerformanceChecker/CacheCompressionChecker.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,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Frosh\Tools\Components\Health\Checker\PerformanceChecker; | ||
|
||
use Symfony\Component\DependencyInjection\Attribute\Autowire; | ||
|
||
class CacheCompressionChecker extends AbstractCompressionChecker | ||
{ | ||
public function __construct( | ||
#[Autowire('%kernel.shopware_version%')] | ||
string $shopwareVersion, | ||
#[Autowire('Cache')] | ||
string $functionality, | ||
#[Autowire('%shopware.cache.cache_compression%')] | ||
bool $enabled, | ||
#[Autowire('%shopware.cache.cache_compression_method%')] | ||
string $method, | ||
) { | ||
parent::__construct($shopwareVersion, $functionality, $enabled, $method); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/Components/Health/Checker/PerformanceChecker/CartCompressionChecker.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,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Frosh\Tools\Components\Health\Checker\PerformanceChecker; | ||
|
||
use Symfony\Component\DependencyInjection\Attribute\Autowire; | ||
|
||
class CartCompressionChecker extends AbstractCompressionChecker | ||
{ | ||
public function __construct( | ||
#[Autowire('%kernel.shopware_version%')] | ||
string $shopwareVersion, | ||
#[Autowire('Cart')] | ||
string $functionality, | ||
#[Autowire('%shopware.cart.compress%')] | ||
bool $enabled, | ||
#[Autowire('%shopware.cart.compression_method%')] | ||
string $method, | ||
) { | ||
parent::__construct($shopwareVersion, $functionality, $enabled, $method); | ||
} | ||
} |