ltsecurityinc安防产品在线商城代码
This commit is contained in:
+108
@@ -0,0 +1,108 @@
|
||||
<?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\Block\Adminhtml\System\Config;
|
||||
|
||||
use Magento\Backend\Block\Template\Context;
|
||||
use Magento\Framework\App\ProductMetadataInterface;
|
||||
use Magento\Framework\Data\Form\Element\AbstractElement;
|
||||
use Magento\Config\Block\System\Config\Form\Field;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Framework\View\Helper\SecureHtmlRenderer;
|
||||
use Plumrocket\GlobalPrivacyControl\Service\WellKnownFileManager;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class WellKnownPreview extends Field
|
||||
{
|
||||
/**
|
||||
* @var \Plumrocket\GlobalPrivacyControl\Service\WellKnownFileManager
|
||||
*/
|
||||
private $wellKnownFileManager;
|
||||
|
||||
/**
|
||||
* @var \Psr\Log\LoggerInterface
|
||||
*/
|
||||
private $logger;
|
||||
|
||||
/**
|
||||
* @param \Magento\Backend\Block\Template\Context $context
|
||||
* @param \Magento\Framework\ObjectManagerInterface $objectManager
|
||||
* @param \Magento\Framework\App\ProductMetadataInterface $productMetadata
|
||||
* @param \Plumrocket\GlobalPrivacyControl\Service\WellKnownFileManager $wellKnownFileManager
|
||||
* @param \Psr\Log\LoggerInterface $logger
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
ObjectManagerInterface $objectManager,
|
||||
ProductMetadataInterface $productMetadata,
|
||||
WellKnownFileManager $wellKnownFileManager,
|
||||
LoggerInterface $logger,
|
||||
array $data = []
|
||||
) {
|
||||
/**
|
||||
* @TODO Refactor when leave support of Magento 2.3.7 and less
|
||||
*/
|
||||
if (version_compare($productMetadata->getVersion(), '2.4.0', '<')) {
|
||||
parent::__construct($context, $data);
|
||||
} else {
|
||||
parent::__construct($context, $data, $objectManager->get(SecureHtmlRenderer::class));
|
||||
}
|
||||
|
||||
$this->wellKnownFileManager = $wellKnownFileManager;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AbstractElement $element
|
||||
* @return string
|
||||
*/
|
||||
protected function _getElementHtml(AbstractElement $element): string
|
||||
{
|
||||
try {
|
||||
return $this->renderPre(
|
||||
$this->wellKnownFileManager->getContent()
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error('[Plumrocket_GlobalPrivacyControl] Unable to read the .well-known file content: ' . $e->getMessage(), ['exception' => $e]);
|
||||
|
||||
return $this->renderNotice(
|
||||
__('Unable to load file content. Please check the logs for more details.')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render formatted <pre> block with code.
|
||||
*
|
||||
* @param string $content
|
||||
* @return string
|
||||
*/
|
||||
private function renderPre(string $content): string
|
||||
{
|
||||
return '<pre class="code-box">' . $content . '</pre>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Render styled error notice.
|
||||
*
|
||||
* @param \Magento\Framework\Phrase|string $message
|
||||
* @return string
|
||||
*/
|
||||
private function renderNotice($message): string
|
||||
{
|
||||
return <<<HTML
|
||||
<div class="pr_notice pr_notice--error">
|
||||
<div class="pr-notice__content-wrapper">
|
||||
<div class="pr-notice__content">{$message}</div>
|
||||
</div>
|
||||
</div>
|
||||
HTML;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user