Files
MageSail/Magesail/Block/Adminhtml/Nginx/Map.php
T
snxraven 4ec4791f27
CI / php (push) Successful in 2m57s
feat(admin): copy buttons and shared clipboard helper
- Add magesail-clipboard.js (clipboard API + execCommand fallback)
- Tunnel: copy store code, key, Holesail command, log tail; wire polling UI
- How-To: copy per code block; Howto block + magesail-howto-copy.js
- NGINX map: copy raw map from textarea; translations in Map block
- Document copy UX in docs/admin-ui.md
2026-03-21 04:03:13 -05:00

102 lines
3.7 KiB
PHP

<?php
declare(strict_types=1);
namespace MageSail\Magesail\Block\Adminhtml\Nginx;
use Magento\Backend\Block\Template;
use Magento\Backend\Block\Template\Context;
use Magento\Framework\Serialize\Serializer\Json;
use MageSail\Magesail\Model\NginxGlobalMapManager;
class Map extends Template
{
public function __construct(
Context $context,
private readonly NginxGlobalMapManager $nginxMapManager,
private readonly Json $json,
array $data = []
) {
parent::__construct($context, $data);
}
public function getMapFilePath(): ?string
{
return $this->nginxMapManager->getMapFilePath();
}
public function getMapContent(): string
{
try {
return $this->nginxMapManager->readMapFile();
} catch (\Exception) {
return '';
}
}
public function getMapUrl(): string
{
return $this->getUrl('*/*/map');
}
public function getFormKey(): string
{
return $this->formKey->getFormKey();
}
/**
* @return array<string, mixed>
*/
public function getNginxMapInitConfig(): array
{
return [
'mapUrl' => $this->getMapUrl(),
'formKey' => $this->getFormKey(),
'mapConfigured' => $this->getMapFilePath() !== null,
'translations' => [
'msgLoadingBlocks' => (string) __('Loading map blocks…'),
'msgParseFailed' => (string) __(
'Could not parse the map file. Click Parse & Load Blocks to retry.'
),
'parseSuccess' => (string) __('Map file parsed successfully.'),
'parseFailed' => (string) __('Failed to parse map file'),
'addEntry' => (string) __('Add Entry'),
'colHostname' => (string) __('Hostname'),
'colValue' => (string) __('Value'),
'colComment' => (string) __('Comment'),
'colActions' => (string) __('Actions'),
'delete' => (string) __('Delete'),
'saveBlocksValidate' => (string) __('Save Blocks & Validate'),
'switchRaw' => (string) __('Switch to Raw Editor'),
'invalidHeader' => (string) __('Invalid map block header format'),
'blocksSaved' => (string) __('Blocks saved successfully.'),
'saveBlocksFailed' => (string) __('Failed to save blocks'),
'validationPrefix' => (string) __('Warning:'),
'nginxValidationFailed' => (string) __('NGINX validation failed'),
'rawSaved' => (string) __('Raw content saved.'),
'saveFailed' => (string) __('Failed to save'),
'operationOk' => (string) __('Operation completed successfully.'),
'operationFailed' => (string) __('Operation failed'),
'nginxValidated' => (string) __('NGINX configuration validated.'),
'nginxReloaded' => (string) __('NGINX reloaded.'),
'diagPath' => (string) __('Path:'),
'diagNotConfigured' => (string) __('Not configured'),
'diagExists' => (string) __('Exists:'),
'diagReadable' => (string) __('Readable:'),
'diagWritable' => (string) __('Writable:'),
'yes' => (string) __('Yes'),
'no' => (string) __('No'),
'diagIssue' => (string) __('Issue:'),
'copyRawMap' => (string) __('Copy raw map'),
'copied' => (string) __('Copied!'),
'copyFailed' => (string) __('Copy failed'),
],
];
}
public function getNginxMapInitJson(): string
{
return $this->json->serialize($this->getNginxMapInitConfig());
}
}