Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 56 |
|
0.00% |
0 / 15 |
CRAP | |
0.00% |
0 / 1 |
| Panini2024Controller | |
0.00% |
0 / 56 |
|
0.00% |
0 / 15 |
380 | |
0.00% |
0 / 1 |
| index | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| all | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| masks | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| single | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| pdf3x5 | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
| pdf4x4 | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
| zipDuplicatesGrid4x4 | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
12 | |||
| pdfOlz | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| pdfHistory | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| pdfDresses | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| pdfMaps | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| pdfBook | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| pdfBack | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| setLimits | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| pdfResponse | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Olz\Apps\Panini2024; |
| 4 | |
| 5 | use Olz\Apps\Panini2024\Components\OlzPanini2024\OlzPanini2024; |
| 6 | use Olz\Apps\Panini2024\Components\OlzPanini2024All\OlzPanini2024All; |
| 7 | use Olz\Apps\Panini2024\Components\OlzPanini2024Masks\OlzPanini2024Masks; |
| 8 | use Olz\Apps\Panini2024\Utils\Panini2024UtilsTrait; |
| 9 | use Psr\Log\LoggerInterface; |
| 10 | use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
| 11 | use Symfony\Component\HttpFoundation\Request; |
| 12 | use Symfony\Component\HttpFoundation\Response; |
| 13 | use Symfony\Component\Routing\Annotation\Route; |
| 14 | |
| 15 | class Panini2024Controller extends AbstractController { |
| 16 | use Panini2024UtilsTrait; |
| 17 | |
| 18 | #[Route('/apps/panini24')] |
| 19 | public function index( |
| 20 | Request $request, |
| 21 | LoggerInterface $logger, |
| 22 | OlzPanini2024 $olzPanini2024, |
| 23 | ): Response { |
| 24 | $html_out = $olzPanini2024->getHtml([]); |
| 25 | return new Response($html_out); |
| 26 | } |
| 27 | |
| 28 | #[Route('/apps/panini24/all')] |
| 29 | public function all( |
| 30 | Request $request, |
| 31 | LoggerInterface $logger, |
| 32 | OlzPanini2024All $olzPanini2024All, |
| 33 | ): Response { |
| 34 | $html_out = $olzPanini2024All->getHtml([]); |
| 35 | return new Response($html_out); |
| 36 | } |
| 37 | |
| 38 | #[Route('/apps/panini24/mask/{mask}')] |
| 39 | public function masks( |
| 40 | Request $request, |
| 41 | LoggerInterface $logger, |
| 42 | OlzPanini2024Masks $olzPanini2024Masks, |
| 43 | string $mask, |
| 44 | ): Response { |
| 45 | $html_out = $olzPanini2024Masks->getHtml(['mask' => $mask]); |
| 46 | return new Response($html_out); |
| 47 | } |
| 48 | |
| 49 | #[Route('/apps/panini24/single/{id}.jpg', requirements: ['id' => '\d+'])] |
| 50 | public function single( |
| 51 | Request $request, |
| 52 | LoggerInterface $logger, |
| 53 | int $id, |
| 54 | ): Response { |
| 55 | $out = $this->paniniUtils()->renderSingle($id); |
| 56 | $response = new Response($out); |
| 57 | $response->headers->set('Content-Type', 'image/jpeg'); |
| 58 | return $response; |
| 59 | } |
| 60 | |
| 61 | #[Route('/apps/panini24/pdf/3x5/{spec}.pdf')] |
| 62 | public function pdf3x5( |
| 63 | Request $request, |
| 64 | LoggerInterface $logger, |
| 65 | string $spec, |
| 66 | ): Response { |
| 67 | $this->setLimits(); |
| 68 | [$pages, $options] = $this->paniniUtils()->parseSpec($spec, /* num_per_page= */ 12); |
| 69 | $pdf_out = $this->paniniUtils()->render3x5Pages($pages, $options); |
| 70 | if (!$pdf_out) { |
| 71 | return new Response("Must adhere to spec: (random-N | ID,ID,ID,ID,ID,ID,ID,ID,ID,ID,ID,ID) [-grid]"); |
| 72 | } |
| 73 | return $this->pdfResponse($pdf_out); |
| 74 | } |
| 75 | |
| 76 | #[Route('/apps/panini24/pdf/4x4/{spec}.pdf')] |
| 77 | public function pdf4x4( |
| 78 | Request $request, |
| 79 | LoggerInterface $logger, |
| 80 | string $spec, |
| 81 | ): Response { |
| 82 | $this->setLimits(); |
| 83 | [$pages, $options] = $this->paniniUtils()->parseSpec($spec, /* num_per_page= */ 16); |
| 84 | $pdf_out = $this->paniniUtils()->render4x4Pages($pages, $options); |
| 85 | if (!$pdf_out) { |
| 86 | return new Response("Must adhere to spec: (random-N | ID,ID,ID,ID,ID,ID,ID,ID,ID,ID,ID,ID,ID,ID,ID,ID) [-grid]"); |
| 87 | } |
| 88 | return $this->pdfResponse($pdf_out); |
| 89 | } |
| 90 | |
| 91 | #[Route('/apps/panini24/pdf/4x4/{spec}.zip')] |
| 92 | public function zipDuplicatesGrid4x4( |
| 93 | Request $request, |
| 94 | LoggerInterface $logger, |
| 95 | string $spec, |
| 96 | ): Response { |
| 97 | $this->setLimits(); |
| 98 | if ($spec !== 'duplicates' && $spec !== 'duplicates-grid') { |
| 99 | return new Response("Must be 'duplicates' or 'duplicates-grid'"); |
| 100 | } |
| 101 | $options = [ |
| 102 | 'grid' => $spec === 'duplicates-grid', |
| 103 | ]; |
| 104 | $zip_out = $this->paniniUtils()->render4x4Zip($options); |
| 105 | $response = new Response($zip_out); |
| 106 | $response->headers->set('Content-Type', 'application/zip'); |
| 107 | $response->headers->set('Content-Disposition', "attachment;filename={$spec}.zip"); |
| 108 | return $response; |
| 109 | } |
| 110 | |
| 111 | #[Route('/apps/panini24/pdf/olz.pdf')] |
| 112 | public function pdfOlz( |
| 113 | Request $request, |
| 114 | LoggerInterface $logger, |
| 115 | ): Response { |
| 116 | $this->setLimits(); |
| 117 | $pdf_out = $this->paniniUtils()->renderOlzPages(); |
| 118 | return $this->pdfResponse($pdf_out); |
| 119 | } |
| 120 | |
| 121 | #[Route('/apps/panini24/pdf/history.pdf')] |
| 122 | public function pdfHistory( |
| 123 | Request $request, |
| 124 | LoggerInterface $logger, |
| 125 | ): Response { |
| 126 | $this->setLimits(); |
| 127 | $pdf_out = $this->paniniUtils()->renderHistoryPages(); |
| 128 | return $this->pdfResponse($pdf_out); |
| 129 | } |
| 130 | |
| 131 | #[Route('/apps/panini24/pdf/dresses.pdf')] |
| 132 | public function pdfDresses( |
| 133 | Request $request, |
| 134 | LoggerInterface $logger, |
| 135 | ): Response { |
| 136 | $this->setLimits(); |
| 137 | $pdf_out = $this->paniniUtils()->renderDressesPages(); |
| 138 | return $this->pdfResponse($pdf_out); |
| 139 | } |
| 140 | |
| 141 | #[Route('/apps/panini24/pdf/maps.pdf')] |
| 142 | public function pdfMaps( |
| 143 | Request $request, |
| 144 | LoggerInterface $logger, |
| 145 | ): Response { |
| 146 | $this->setLimits(); |
| 147 | $pdf_out = $this->paniniUtils()->renderMapsPages(); |
| 148 | return $this->pdfResponse($pdf_out); |
| 149 | } |
| 150 | |
| 151 | #[Route('/apps/panini24/pdf/book.pdf')] |
| 152 | public function pdfBook( |
| 153 | Request $request, |
| 154 | LoggerInterface $logger, |
| 155 | ): Response { |
| 156 | $this->setLimits(); |
| 157 | $pdf_out = $this->paniniUtils()->renderBookPages(); |
| 158 | return $this->pdfResponse($pdf_out); |
| 159 | } |
| 160 | |
| 161 | #[Route('/apps/panini24/pdf/back.pdf')] |
| 162 | public function pdfBack( |
| 163 | Request $request, |
| 164 | LoggerInterface $logger, |
| 165 | ): Response { |
| 166 | $this->setLimits(); |
| 167 | $pdf_out = $this->paniniUtils()->renderBackPages(); |
| 168 | return $this->pdfResponse($pdf_out); |
| 169 | } |
| 170 | |
| 171 | private function setLimits(): void { |
| 172 | ini_set('memory_limit', '500M'); |
| 173 | set_time_limit(4000); |
| 174 | } |
| 175 | |
| 176 | private function pdfResponse(string $pdf_out): Response { |
| 177 | $response = new Response($pdf_out); |
| 178 | $response->headers->set('Content-Type', 'application/pdf'); |
| 179 | return $response; |
| 180 | } |
| 181 | } |