48 lines
1.2 KiB
PHP
48 lines
1.2 KiB
PHP
<?php
|
|
/**
|
|
* @package Plumrocket_GlobalPrivacyControl
|
|
* @copyright Copyright (c) 2025 Plumrocket Inc.
|
|
* @license https://plumrocket.com/license End-user License Agreement
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Plumrocket\GlobalPrivacyControl\Plugin\Html;
|
|
|
|
use Magento\Framework\App\Response\Http;
|
|
use Plumrocket\GlobalPrivacyControl\Block\ComponentInit as ComponentInitBlock;
|
|
use Plumrocket\GlobalPrivacyControl\Helper\Config;
|
|
|
|
class ReplaceComponentInitScriptPlaceholderPlugin
|
|
{
|
|
/**
|
|
* @var \Plumrocket\GlobalPrivacyControl\Helper\Config
|
|
*/
|
|
private $config;
|
|
|
|
/**
|
|
* @param \Plumrocket\GlobalPrivacyControl\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
|
|
{
|
|
$content = $subject->getContent();
|
|
if(! is_string($content) || strpos($content, ComponentInitBlock::SCRIPT_TAG_REPLACEMENT) === false) {
|
|
return;
|
|
}
|
|
|
|
$subject->setContent(
|
|
str_replace(ComponentInitBlock::SCRIPT_TAG_REPLACEMENT, 'script', $content)
|
|
);
|
|
}
|
|
}
|