Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 45 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| AssetsController | |
0.00% |
0 / 45 |
|
0.00% |
0 / 4 |
156 | |
0.00% |
0 / 1 |
| assetsIcnsIndex | |
0.00% |
0 / 32 |
|
0.00% |
0 / 1 |
56 | |||
| folderAsset | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| userInitials | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
| favicon | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Olz\Controller; |
| 4 | |
| 5 | use Psr\Log\LoggerInterface; |
| 6 | use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
| 7 | use Symfony\Component\HttpFoundation\BinaryFileResponse; |
| 8 | use Symfony\Component\HttpFoundation\Request; |
| 9 | use Symfony\Component\HttpFoundation\Response; |
| 10 | use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
| 11 | use Symfony\Component\Routing\Annotation\Route; |
| 12 | |
| 13 | class AssetsController extends AbstractController { |
| 14 | #[Route('/assets/icns/')] |
| 15 | public function assetsIcnsIndex( |
| 16 | Request $request, |
| 17 | LoggerInterface $logger, |
| 18 | ): Response { |
| 19 | $assets_path = __DIR__.'/../../assets'; |
| 20 | $icns_entries = scandir("{$assets_path}/icns") ?: []; |
| 21 | $svg_icons = []; |
| 22 | foreach ($icns_entries as $entry) { |
| 23 | $is_svg_icon = preg_match('/^([a-zA-Z0-9_]+)_([0-9]+)\.svg$/i', $entry, $matches); |
| 24 | if (!$is_svg_icon) { |
| 25 | continue; |
| 26 | } |
| 27 | $icon_name = $matches[1]; |
| 28 | $icon_size = $matches[2]; |
| 29 | if (!isset($svg_icons[$icon_name])) { |
| 30 | $svg_icons[$icon_name] = []; |
| 31 | } |
| 32 | $svg_icons[$icon_name][$icon_size] = $entry; |
| 33 | } |
| 34 | $out = ''; |
| 35 | foreach ($svg_icons as $icon_name => $icon_by_size) { |
| 36 | $out .= "<div><h2>{$icon_name}</h2>"; |
| 37 | foreach ($icon_by_size as $icon_size => $icon) { |
| 38 | $out .= "<div><h3>{$icon_size}</h3>"; |
| 39 | $original_size = intval($icon_size); |
| 40 | $double_size = $original_size * 2; |
| 41 | $triple_size = $original_size * 3; |
| 42 | $icon_href = "/assets/icns/{$icon}"; |
| 43 | $out .= "<img src='{$icon_href}' style='width:{$original_size}px; margin:1px; border:1px solid black;'/>"; |
| 44 | $out .= "<img src='{$icon_href}' style='width:{$double_size}px; margin:1px; border:1px solid black;'/>"; |
| 45 | $out .= "<img src='{$icon_href}' style='width:{$triple_size}px; margin:1px; border:1px solid black;'/>"; |
| 46 | |
| 47 | $out .= "<div style='display:inline-block; background-color:rgb(200,200,200);'>"; |
| 48 | $out .= "<img src='{$icon_href}' style='width:{$original_size}px; margin:1px; border:1px solid black;'/>"; |
| 49 | $out .= "<img src='{$icon_href}' style='width:{$double_size}px; margin:1px; border:1px solid black;'/>"; |
| 50 | $out .= "<img src='{$icon_href}' style='width:{$triple_size}px; margin:1px; border:1px solid black;'/>"; |
| 51 | $out .= "</div>"; |
| 52 | |
| 53 | $out .= "</div>"; |
| 54 | } |
| 55 | $out .= "</div>"; |
| 56 | } |
| 57 | return new Response($out); |
| 58 | } |
| 59 | |
| 60 | #[Route('/assets/{folder}/{filename}.{ext}', requirements: [ |
| 61 | 'folder' => '[a-zA-Z0-9_-]+', |
| 62 | 'filename' => '[a-zA-Z0-9_-]+', |
| 63 | 'ext' => '[a-zA-Z0-9_-]+', |
| 64 | ])] |
| 65 | public function folderAsset( |
| 66 | Request $request, |
| 67 | LoggerInterface $logger, |
| 68 | string $folder, |
| 69 | string $filename, |
| 70 | string $ext, |
| 71 | ): Response { |
| 72 | $assets_path = __DIR__.'/../../assets'; |
| 73 | $path = "{$assets_path}/{$folder}/{$filename}.{$ext}"; |
| 74 | if (!is_file($path)) { |
| 75 | throw new NotFoundHttpException('No such asset.'); |
| 76 | } |
| 77 | return new BinaryFileResponse($path); |
| 78 | } |
| 79 | |
| 80 | #[Route('/assets/user_initials_{initials}.svg', requirements: ['initials' => '.{0,3}'])] |
| 81 | public function userInitials( |
| 82 | Request $request, |
| 83 | LoggerInterface $logger, |
| 84 | string $initials, |
| 85 | ): Response { |
| 86 | $assets_path = __DIR__.'/../../assets'; |
| 87 | $svg_content = file_get_contents("{$assets_path}/icns/user_initials.svg") ?: ''; |
| 88 | $out = str_replace('%INITIALS%', $initials, $svg_content); |
| 89 | $response = new Response($out); |
| 90 | $response->headers->set('Content-Type', 'image/svg+xml'); |
| 91 | return $response; |
| 92 | } |
| 93 | |
| 94 | #[Route('/favicon.ico')] |
| 95 | public function favicon( |
| 96 | Request $request, |
| 97 | LoggerInterface $logger |
| 98 | ): Response { |
| 99 | $assets_path = __DIR__.'/../../assets'; |
| 100 | return new BinaryFileResponse("{$assets_path}/favicon.ico"); |
| 101 | } |
| 102 | } |