55 lines
1.3 KiB
PHP
55 lines
1.3 KiB
PHP
<?php
|
|
/**
|
|
* @package Plumrocket_CookieConsent
|
|
* @copyright Copyright (c) 2025 Plumrocket Inc. (https://plumrocket.com)
|
|
* @license https://plumrocket.com/license End-user License Agreement
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Plumrocket\CookieConsent\Plugin\Html;
|
|
|
|
use Magento\Framework\App\Response\Http;
|
|
use Plumrocket\CookieConsent\Block\Html\HeadScripts as HeadScriptsBlock;
|
|
use Plumrocket\CookieConsent\Helper\Config;
|
|
|
|
/**
|
|
* @since 2.0.4
|
|
*/
|
|
class HeadScripts
|
|
{
|
|
/**
|
|
* @var \Plumrocket\CookieConsent\Helper\Config
|
|
*/
|
|
private $config;
|
|
|
|
/**
|
|
* @param \Plumrocket\CookieConsent\Helper\Config $config
|
|
*/
|
|
public function __construct(
|
|
Config $config
|
|
) {
|
|
$this->config = $config;
|
|
}
|
|
|
|
/**
|
|
* @param \Magento\Framework\App\Response\Http $subject
|
|
* @return void
|
|
*/
|
|
public function beforeSendResponse(Http $subject): void
|
|
{
|
|
if (! $this->config->isModuleEnabled()) {
|
|
return;
|
|
}
|
|
|
|
$content = $subject->getContent();
|
|
if(! is_string($content) || strpos($content, HeadScriptsBlock::SCRIPT_TAG_REPLACEMENT) === false) {
|
|
return;
|
|
}
|
|
|
|
$subject->setContent(
|
|
str_replace(HeadScriptsBlock::SCRIPT_TAG_REPLACEMENT, 'script', $content)
|
|
);
|
|
}
|
|
}
|