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