|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Oc\GeoCache\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use Endroid\QrCode\ErrorCorrectionLevel; |
|
6
|
|
|
use Endroid\QrCode\LabelAlignment; |
|
7
|
|
|
use Endroid\QrCode\QrCode; |
|
8
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
|
9
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
10
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
11
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
12
|
|
|
|
|
13
|
|
|
class QrCodeController extends Controller |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @param Request $request |
|
17
|
|
|
* @return Response |
|
18
|
|
|
* @Route("/api/geocache/qrCodes") |
|
19
|
|
|
*/ |
|
20
|
|
|
public function getReportsAction(Request $request) |
|
21
|
|
|
{ |
|
22
|
|
|
$wp = $request->get('wp'); |
|
23
|
|
|
|
|
24
|
|
|
if (preg_match('/(OC|GC)[A-Za-z0-9]{1,5}/', $wp) !== 1) { |
|
25
|
|
|
die('the waypoint is not valid!'); |
|
|
|
|
|
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
$qrCode = new QrCode('https://www.opencaching.de/' . $wp); |
|
29
|
|
|
$qrCode->setSize(300); |
|
30
|
|
|
|
|
31
|
|
|
$qrCode |
|
32
|
|
|
->setWriterByName('png') |
|
33
|
|
|
->setMargin(10) |
|
34
|
|
|
->setEncoding('UTF-8') |
|
35
|
|
|
->setErrorCorrectionLevel(ErrorCorrectionLevel::HIGH) |
|
36
|
|
|
->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0]) |
|
37
|
|
|
->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255]) |
|
38
|
|
|
->setLabel('www.opencaching.de', 16, null, LabelAlignment::CENTER) |
|
39
|
|
|
->setLogoPath(__DIR__ . '/../../../../theme/img/logo/oc-logo.png') |
|
40
|
|
|
->setLogoWidth(250) |
|
41
|
|
|
->setValidateResult(false); |
|
42
|
|
|
|
|
43
|
|
|
return new Response( |
|
44
|
|
|
$qrCode->writeString(), Response::HTTP_OK, ['Content-Type' => $qrCode->getContentType()] |
|
45
|
|
|
); |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|
An exit expression should only be used in rare cases. For example, if you write a short command line script.
In most cases however, using an
exitexpression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.