2020-08-17 23:46:58 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
final class QrCodeGetController extends AbstractController
|
|
|
|
{
|
2020-08-23 12:37:39 +02:00
|
|
|
protected string $route = '/api/v1/fingerprint/{fingerprintId}/qr';
|
2020-08-17 23:46:58 +02:00
|
|
|
|
2020-08-23 12:37:39 +02:00
|
|
|
private int $fingerprintId;
|
2020-08-17 23:46:58 +02:00
|
|
|
|
2020-08-23 12:37:39 +02:00
|
|
|
public function __construct(string $url)
|
|
|
|
{
|
|
|
|
parent::__construct($url);
|
2020-08-17 23:46:58 +02:00
|
|
|
|
2020-08-23 12:37:39 +02:00
|
|
|
$this->fingerprintId = (int)$this->getUrlParamInt('fingerprintId');
|
|
|
|
}
|
2020-08-17 23:46:58 +02:00
|
|
|
|
2020-08-23 12:37:39 +02:00
|
|
|
public function handle(): void
|
|
|
|
{
|
|
|
|
$filename = Setting::PATH_QR_CODES . (string)$this->fingerprintId . '.svg';
|
2020-08-17 23:46:58 +02:00
|
|
|
|
2020-08-23 12:37:39 +02:00
|
|
|
if (!is_file($filename)) {
|
|
|
|
$this->response = new ApiJsonResponse(ServerStatus::BAD_REQUEST);
|
|
|
|
$this->response->setParameter('success', false);
|
|
|
|
$this->response->setMessage(sprintf('No QR code for fingerprint id %d found!', $this->fingerprintId));
|
2020-08-17 23:46:58 +02:00
|
|
|
|
2020-08-23 12:37:39 +02:00
|
|
|
return;
|
|
|
|
}
|
2020-08-17 23:46:58 +02:00
|
|
|
|
2020-08-23 12:37:39 +02:00
|
|
|
try {
|
2020-08-20 16:23:49 +02:00
|
|
|
$this->response = new ApiSvgResponse();
|
|
|
|
|
|
|
|
$file = @fopen($filename, 'r');
|
|
|
|
$this->response->setContent(@fread($file, @filesize($filename)));
|
|
|
|
@fclose($file);
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
$this->response = new ApiJsonResponse(ServerStatus::INTERNAL_ERROR);
|
|
|
|
$this->response->setParameter('success', false);
|
|
|
|
$this->response->setMessage($e->getMessage());
|
|
|
|
}
|
2020-08-23 12:37:39 +02:00
|
|
|
}
|
2020-08-17 23:46:58 +02:00
|
|
|
}
|