54 lines
1.7 KiB
PHP
54 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace KupShop\MetricsBundle\StatusProviders;
|
|
|
|
use KupShop\KupShopBundle\Context\ContextManager;
|
|
use KupShop\KupShopBundle\Context\LanguageContext;
|
|
use KupShop\KupShopBundle\Metrics\AbstractStatusProvider;
|
|
use KupShop\KupShopBundle\Metrics\StatusSample;
|
|
use Symfony\Contracts\Service\Attribute\Required;
|
|
|
|
class UrlGeneratorStatusProvider extends AbstractStatusProvider
|
|
{
|
|
protected LanguageContext $languageContext;
|
|
protected ContextManager $contextManager;
|
|
|
|
public function getData(): StatusSample|iterable
|
|
{
|
|
$status = 1;
|
|
$languages = $this->languageContext->getSupported();
|
|
|
|
if (empty($languages)) {
|
|
return new StatusSample('url_generator', 0);
|
|
}
|
|
|
|
foreach ($languages as $language) {
|
|
$this->contextManager->activateContexts([LanguageContext::class => $language->getId()], function () use (&$status) {
|
|
// Test URL generated using Symfony url generator matches URL generated using translation
|
|
// using createScriptURL to support language prefix url
|
|
$url = path('kupshop_content_cart_cart_1');
|
|
$translated = createScriptURL(['s' => 'cart']);
|
|
|
|
if ($url !== $translated) {
|
|
$status = 0;
|
|
}
|
|
});
|
|
}
|
|
yield new StatusSample('url_generator', $status);
|
|
}
|
|
|
|
#[Required]
|
|
public function setLanguageContext(LanguageContext $languageContext): void
|
|
{
|
|
$this->languageContext = $languageContext;
|
|
}
|
|
|
|
#[Required]
|
|
public function setContextManager(ContextManager $contextManager): void
|
|
{
|
|
$this->contextManager = $contextManager;
|
|
}
|
|
}
|