Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Spomky committed Dec 17, 2023
1 parent 5797893 commit 5daa066
Showing 1 changed file with 51 additions and 56 deletions.
107 changes: 51 additions & 56 deletions src/Command/GenerateManifestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private function storeShortcutIcon(
$publicFolder,
$assetFolder,
'shortcut-icon',
['shortcut-icon', $purpose]
['shortcut-icon', $purpose, $sizes]
);

return ($purpose !== null)
Expand All @@ -202,7 +202,7 @@ private function storeIcon(
string $sizes,
?string $purpose
): array {
$fileData = $this->storeFile($data, $publicUrl, $publicFolder, $assetFolder, 'icon', ['icon', $purpose]);
$fileData = $this->storeFile($data, $publicUrl, $publicFolder, $assetFolder, 'icon', ['icon', $purpose, $sizes]);

return ($purpose !== null)
? $fileData + [
Expand Down Expand Up @@ -237,33 +237,31 @@ private function processIcons(
return self::FAILURE;
}
foreach ($this->config['icons'] as $icon) {
$minSize = min($icon['sizes']);
$maxSize = max($icon['sizes']);
if ($minSize === 0 && $maxSize !== 0) {
$io->error('The icon size 0 ("any") must not be mixed with other sizes');
return self::FAILURE;
}
$data = file_get_contents($icon['src']);
if ($data === false) {
$io->error(sprintf('Unable to read the icon "%s"', $icon['src']));
return self::FAILURE;
}
if ($maxSize !== 0) {
$data = $this->imageProcessor->process($data, $maxSize, $maxSize, $icon['format'] ?? null);
foreach ($icon['sizes'] as $size) {
if (!is_int($size) || $size < 0) {
$io->error('The icon size must be a positive integer');
return self::FAILURE;
}
$data = file_get_contents($icon['src']);
if ($data === false) {
$io->error(sprintf('Unable to read the icon "%s"', $icon['src']));
return self::FAILURE;
}
if ($size !== 0) {
$data = $this->imageProcessor->process($data, $size, $size, $icon['format'] ?? null);
}
$sizes = $size === 0 ? 'any' : $size . 'x' . $size;

$iconManifest = $this->storeIcon(
$data,
$publicUrl,
$publicFolder,
$assetFolder,
$sizes,
$icon['purpose'] ?? null
);
$manifest['icons'][] = $iconManifest;
}
$sizes = $maxSize === 0 ? 'any' : implode(
' ',
array_map(static fn (int $size): string => $size . 'x' . $size, $icon['sizes'])
);
$iconManifest = $this->storeIcon(
$data,
$publicUrl,
$publicFolder,
$assetFolder,
$sizes,
$icon['purpose'] ?? null
);
$manifest['icons'][] = $iconManifest;
}

return $manifest;
Expand Down Expand Up @@ -343,35 +341,32 @@ private function processShortcutIcons(
return self::FAILURE;
}
foreach ($shortcutConfig['icons'] as $icon) {
$minSize = min($icon['sizes']);
$maxSize = max($icon['sizes']);
if ($minSize === 0 && $maxSize !== 0) {
$io->error('The icon size 0 ("any") must not be mixed with other sizes');
return self::FAILURE;
}

$data = file_get_contents($icon['src']);
if ($data === false) {
$io->error(sprintf('Unable to read the screenshot "%s"', $icon['src']));
return self::FAILURE;
}
if ($maxSize !== 0) {
$data = $this->imageProcessor->process($data, $maxSize, $maxSize, $icon['format'] ?? null);
foreach ($icon['sizes'] as $size) {
if (!is_int($size) || $size < 0) {
$io->error('The icon size must be a positive integer');
return self::FAILURE;
}

$data = file_get_contents($icon['src']);
if ($data === false) {
$io->error(sprintf('Unable to read the screenshot "%s"', $icon['src']));
return self::FAILURE;
}
if ($size !== 0) {
$data = $this->imageProcessor->process($data, $size, $size, $icon['format'] ?? null);
}
$sizes = $size === 0 ? 'any' : $size . 'x' . $size;

$iconManifest = $this->storeShortcutIcon(
$data,
$publicUrl,
$publicFolder,
$assetFolder,
$sizes,
$icon['purpose'] ?? null
);
$shortcut['icons'][] = $iconManifest;
}
$sizes = $maxSize === 0 ? 'any' : implode(
' ',
array_map(static fn (int $size): string => $size . 'x' . $size, $icon['sizes'])
);

$iconManifest = $this->storeShortcutIcon(
$data,
$publicUrl,
$publicFolder,
$assetFolder,
$sizes,
$icon['purpose'] ?? null
);
$shortcut['icons'][] = $iconManifest;
}
}
$manifest['shortcuts'][] = $shortcut;
Expand Down

0 comments on commit 5daa066

Please sign in to comment.