-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
97,944 additions
and
58,492 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ checks: | |
build: | ||
environment: | ||
php: | ||
version: 7.3 | ||
version: 8.1 | ||
tests: | ||
override: | ||
- | ||
|
Binary file not shown.
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LauLamanApps\ApplePassbookBundle\Controller\V1\PassKit\Device; | ||
|
||
use LauLamanApps\ApplePassbookBundle\Controller\V1\PassKit\AuthenticationToken; | ||
use LauLamanApps\ApplePassbookBundle\Event\DeviceRegisteredEvent; | ||
use LauLamanApps\ApplePassbookBundle\Event\Status; | ||
use LogicException; | ||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
/** | ||
* @Route("/v1/devices/{deviceLibraryIdentifier}/registrations/{passTypeIdentifier}/{serialNumber}/", methods={"POST"}) | ||
*/ | ||
class RegisterController | ||
{ | ||
use AuthenticationToken; | ||
|
||
/** | ||
* @var EventDispatcherInterface | ||
*/ | ||
private $eventDispatcher; | ||
|
||
public function __construct(EventDispatcherInterface $eventDispatcher) | ||
{ | ||
$this->eventDispatcher = $eventDispatcher; | ||
} | ||
|
||
public function __invoke( | ||
Request $request, | ||
string $deviceLibraryIdentifier, | ||
string $passTypeIdentifier, | ||
string $serialNumber | ||
): JsonResponse { | ||
$event = new DeviceRegisteredEvent( | ||
$deviceLibraryIdentifier, | ||
$passTypeIdentifier, | ||
$serialNumber, | ||
$this->getAuthenticationToken($request), | ||
json_decode($request->getContent())->pushToken | ||
); | ||
|
||
/** @var Status $status */ | ||
$status = $this->eventDispatcher->dispatch($event)->getStatus(); | ||
|
||
if ($status->isUnhandled()) { | ||
throw new LogicException('DeviceRegisteredEvent was not handled. Please implement a listener for this event.'); | ||
} | ||
|
||
if ($status->isNotAuthorized()) { | ||
return new JsonResponse([], Response::HTTP_UNAUTHORIZED); | ||
} | ||
|
||
if ($status->isAlreadyRegistered()) { | ||
return new JsonResponse([], Response::HTTP_OK); | ||
} | ||
|
||
if ($status->isSuccessful()) { | ||
return new JsonResponse([], Response::HTTP_CREATED); | ||
} | ||
|
||
throw new LogicException('DeviceRegisteredEvent was not handled correctly. Unexpected status was set.'); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
src/Controller/V1/PassKit/Device/SerialNumbersController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LauLamanApps\ApplePassbookBundle\Controller\V1\PassKit\Device; | ||
|
||
use DateTimeImmutable; | ||
use LauLamanApps\ApplePassbookBundle\Controller\V1\PassKit\AuthenticationToken; | ||
use LauLamanApps\ApplePassbookBundle\Event\DeviceRequestUpdatedPassesEvent; | ||
use LogicException; | ||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
/** | ||
* @Route("/v1/devices/{deviceLibraryIdentifier}/registrations/{passTypeIdentifier}", methods={"GET"}) | ||
*/ | ||
class SerialNumbersController | ||
{ | ||
use AuthenticationToken; | ||
|
||
/** | ||
* @var EventDispatcherInterface | ||
*/ | ||
private $eventDispatcher; | ||
|
||
public function __construct(EventDispatcherInterface $eventDispatcher) | ||
{ | ||
$this->eventDispatcher = $eventDispatcher; | ||
} | ||
|
||
public function __invoke( | ||
string $deviceLibraryIdentifier, | ||
string $passTypeIdentifier | ||
): JsonResponse { | ||
$event = new DeviceRequestUpdatedPassesEvent($deviceLibraryIdentifier, $passTypeIdentifier); | ||
$this->eventDispatcher->dispatch($event); | ||
|
||
if ($event->getStatus()->isUnhandled()) { | ||
throw new LogicException('DeviceRequestUpdatedPassesEvent was not handled. Please implement a listener for this event.'); | ||
} | ||
|
||
if ($event->getStatus()->isNotFound()) { | ||
return new JsonResponse([], Response::HTTP_NO_CONTENT); | ||
} | ||
|
||
if ($event->getStatus()->isNotModified()) { | ||
return new JsonResponse([], Response::HTTP_NOT_MODIFIED); | ||
} | ||
|
||
if ($event->getStatus()->isSuccessful()) { | ||
return new JsonResponse([ | ||
'lastUpdated' => $event->getLastUpdated()->format(DateTimeImmutable::ATOM), | ||
'serialNumbers' => $event->getSerialNumbers() | ||
]); | ||
} | ||
|
||
throw new LogicException('DeviceRequestUpdatedPassesEvent was not handled correctly. Unexpected status was set.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LauLamanApps\ApplePassbookBundle\Controller\V1\PassKit\Device; | ||
|
||
use LauLamanApps\ApplePassbookBundle\Controller\V1\PassKit\AuthenticationToken; | ||
use LauLamanApps\ApplePassbookBundle\Event\DeviceUnregisteredEvent; | ||
use LauLamanApps\ApplePassbookBundle\Event\Status; | ||
use LogicException; | ||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
/** | ||
* @Route("/v1/devices/{deviceLibraryIdentifier}/registrations/{passTypeIdentifier}/{serialNumber}", methods={"DELETE"}) | ||
*/ | ||
class UnregisterController | ||
{ | ||
use AuthenticationToken; | ||
|
||
/** | ||
* @var EventDispatcherInterface | ||
*/ | ||
private $eventDispatcher; | ||
|
||
public function __construct(EventDispatcherInterface $eventDispatcher) | ||
{ | ||
$this->eventDispatcher = $eventDispatcher; | ||
} | ||
|
||
public function __invoke( | ||
Request $request, | ||
string $deviceLibraryIdentifier, | ||
string $passTypeIdentifier, | ||
string $serialNumber | ||
): JsonResponse { | ||
$event = new DeviceUnregisteredEvent( | ||
$deviceLibraryIdentifier, | ||
$passTypeIdentifier, | ||
$serialNumber, | ||
$this->getAuthenticationToken($request) | ||
); | ||
|
||
/** @var Status $status */ | ||
$status = $this->eventDispatcher->dispatch($event)->getStatus(); | ||
|
||
if ($status->isUnhandled()) { | ||
throw new LogicException('DeviceUnregisteredEvent was not handled. Please implement a listener for this event.'); | ||
} | ||
|
||
if ($status->isNotAuthorized()) { | ||
return new JsonResponse([], Response::HTTP_UNAUTHORIZED); | ||
} | ||
|
||
if ($status->isSuccessful()) { | ||
return new JsonResponse([], Response::HTTP_OK); | ||
} | ||
|
||
throw new LogicException('DeviceUnregisteredEvent was not handled correctly. Unexpected status was set.'); | ||
} | ||
} |
Oops, something went wrong.