28 lines
1.7 KiB
PHP
28 lines
1.7 KiB
PHP
<?php
|
|
/** Готовые доменные SVG, без генерации логотипа при запросе страницы. */
|
|
declare(strict_types=1);
|
|
function prelandBrand(string $root, string $domain): array
|
|
{
|
|
$catalog = json_decode(file_get_contents($root . '/release/brands.json'), true, 512, JSON_THROW_ON_ERROR);
|
|
if (!isset($catalog[$domain])) throw new RuntimeException('Для домена не утверждён бренд: ' . $domain);
|
|
$brand = $catalog[$domain];
|
|
if (array_keys($brand['logos']) !== ['docs/logo.svg', 'docs/logo-alt.svg']) throw new RuntimeException('Нужна полная пара SVG');
|
|
foreach ($brand['logos'] as $target => $record) {
|
|
if (!preg_match('~^brands/' . preg_quote($domain, '~') . '/(?:light|dark)\.svg$~D', $record['file'])) throw new RuntimeException('Некорректный путь бренда');
|
|
$body = str_replace("\r\n", "\n", file_get_contents($root . '/' . $record['file']));
|
|
if (hash('sha256', $body) !== $record['sha256'] || str_contains($body, '<text') || !str_contains($body, '<title>' . $brand['label'] . '</title>')) throw new RuntimeException('Не совпал утверждённый готовый SVG: ' . $target);
|
|
}
|
|
return $brand;
|
|
}
|
|
|
|
function prelandBrandState(array $actual, array $brand): int
|
|
{
|
|
$expected = array_map(static fn(array $record): string => $record['sha256'], $brand['logos']);
|
|
if ($actual === $expected) return 0;
|
|
if (array_keys($actual) !== array_keys($expected)) return 1;
|
|
foreach ($expected as $path => $hash) {
|
|
if ($actual[$path] !== $hash && $actual[$path] !== ($brand['replace_from'][$path] ?? null)) return 1;
|
|
}
|
|
return 10;
|
|
}
|