80 lines
2.1 KiB
PHP
80 lines
2.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace MageSail\Magesail\Block\Adminhtml;
|
|
|
|
use Magento\Backend\Block\Template;
|
|
use Magento\Backend\Block\Template\Context;
|
|
|
|
/**
|
|
* Exposes composer.json metadata for the About page.
|
|
*/
|
|
class About extends Template
|
|
{
|
|
private const COMPOSER_REL = 'composer.json';
|
|
|
|
private const COPYRIGHT_NOTICE = 'Copyright (C) 2026 LIVEPORT P2P SOLUTIONS PVT. LTD.';
|
|
|
|
/** @var array<string, mixed>|null */
|
|
private ?array $composerData = null;
|
|
|
|
public function __construct(
|
|
Context $context,
|
|
array $data = []
|
|
) {
|
|
parent::__construct($context, $data);
|
|
}
|
|
|
|
/**
|
|
* @return array{name: string, version: string, description: string, license: string}
|
|
*/
|
|
public function getPackageInfo(): array
|
|
{
|
|
$data = $this->loadComposer();
|
|
$license = $data['license'] ?? '';
|
|
if (\is_array($license)) {
|
|
$license = implode(', ', $license);
|
|
}
|
|
return [
|
|
'name' => (string) ($data['name'] ?? 'magesail/magesail'),
|
|
'version' => (string) ($data['version'] ?? ''),
|
|
'description' => (string) ($data['description'] ?? ''),
|
|
'license' => (string) $license,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
private function loadComposer(): array
|
|
{
|
|
if ($this->composerData !== null) {
|
|
return $this->composerData;
|
|
}
|
|
$path = dirname(__DIR__, 2) . '/' . self::COMPOSER_REL;
|
|
if (!\is_readable($path)) {
|
|
$this->composerData = [];
|
|
return $this->composerData;
|
|
}
|
|
$raw = file_get_contents($path);
|
|
if ($raw === false) {
|
|
$this->composerData = [];
|
|
return $this->composerData;
|
|
}
|
|
try {
|
|
/** @var array<string, mixed> $decoded */
|
|
$decoded = json_decode($raw, true, 512, JSON_THROW_ON_ERROR);
|
|
$this->composerData = $decoded;
|
|
} catch (\JsonException) {
|
|
$this->composerData = [];
|
|
}
|
|
return $this->composerData;
|
|
}
|
|
|
|
public function getCopyrightNotice(): string
|
|
{
|
|
return self::COPYRIGHT_NOTICE;
|
|
}
|
|
}
|