|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace LauLamanApps\ApplePassbookBundle\Controller\V1\PassKit; |
|
6
|
|
|
|
|
7
|
|
|
use LauLamanApps\ApplePassbook\Build\Compiler; |
|
8
|
|
|
use LauLamanApps\ApplePassbookBundle\Event\RetrieveUpdatedPassbookEvent; |
|
9
|
|
|
use LogicException; |
|
10
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
|
11
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
12
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
13
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
14
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
15
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @Route("/v1/passes/{passTypeIdentifier}/{serialNumber}") |
|
19
|
|
|
*/ |
|
20
|
|
|
class PassbookController extends AbstractController |
|
21
|
|
|
{ |
|
22
|
|
|
use AuthenticationToken; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var EventDispatcherInterface |
|
26
|
|
|
*/ |
|
27
|
|
|
private $eventDispatcher; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var Compiler |
|
31
|
|
|
*/ |
|
32
|
|
|
private $compiler; |
|
33
|
|
|
|
|
34
|
5 |
|
public function __construct(Compiler $compiler, EventDispatcherInterface $eventDispatcher) |
|
35
|
|
|
{ |
|
36
|
5 |
|
$this->eventDispatcher = $eventDispatcher; |
|
37
|
5 |
|
$this->compiler = $compiler; |
|
38
|
5 |
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @Route("", methods={"GET"}) |
|
42
|
|
|
*/ |
|
43
|
5 |
|
public function getUpdatedPassbook(Request $request, string $passTypeIdentifier, string $serialNumber): Response |
|
44
|
|
|
{ |
|
45
|
5 |
|
$event = new RetrieveUpdatedPassbookEvent( |
|
46
|
5 |
|
$passTypeIdentifier, |
|
47
|
|
|
$serialNumber, |
|
48
|
5 |
|
$this->getAuthenticationToken($request) |
|
49
|
|
|
); |
|
50
|
5 |
|
$this->eventDispatcher->dispatch($event); |
|
|
|
|
|
|
51
|
|
|
|
|
52
|
5 |
|
if ($event->getStatus()->isUnhandled()) { |
|
53
|
1 |
|
throw new LogicException('RetrieveUpdatedPassbookEvent was not handled. Please implement a listener for this event.'); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
4 |
|
if ($event->getStatus()->isNotAuthorized()) { |
|
57
|
1 |
|
return new JsonResponse([], Response::HTTP_UNAUTHORIZED); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
3 |
|
if ($event->getStatus()->isNotModified()) { |
|
61
|
1 |
|
return new JsonResponse([], Response::HTTP_NOT_MODIFIED); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
2 |
|
if ($event->getStatus()->isSuccessful()) { |
|
65
|
1 |
|
$data = $this->compiler->compile($event->getPassbook()); |
|
|
|
|
|
|
66
|
1 |
|
$lastModified = $event->getLastModified(); |
|
67
|
1 |
|
$lastModified = $lastModified->setTimezone(new \DateTimeZone('GMT')); |
|
68
|
|
|
|
|
69
|
1 |
|
$response = new Response($data); |
|
70
|
1 |
|
$response->headers->set('Content-Description', 'File Transfer'); |
|
71
|
1 |
|
$response->headers->set('Content-Type', 'application/vnd.apple.pkpass'); |
|
72
|
1 |
|
$response->headers->set('Content-Disposition', 'filename="pass.pkpass"'); |
|
73
|
1 |
|
$response->headers->set('Last-Modified', $lastModified->format('D, d M Y H:i:s \G\M\T')); |
|
74
|
|
|
|
|
75
|
1 |
|
return $response; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
1 |
|
throw new LogicException('RetrieveUpdatedPassbookEvent was not handled correctly. Unexpected status was set.'); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: