diff --git a/src/Passbook/Pass.php b/src/Passbook/Pass.php index a12ba56..2b1f4ba 100644 --- a/src/Passbook/Pass.php +++ b/src/Passbook/Pass.php @@ -14,6 +14,7 @@ use DateTime; use Passbook\Pass\BarcodeInterface; use Passbook\Pass\BeaconInterface; +use Passbook\Pass\NfcInterface; use Passbook\Pass\ImageInterface; use Passbook\Pass\LocalizationInterface; use Passbook\Pass\LocationInterface; @@ -73,7 +74,7 @@ class Pass implements PassInterface * * @var ImageInterface[] */ - protected $images = []; + protected $images = array(); /** * Beacons where the pass is relevant. @@ -81,6 +82,14 @@ class Pass implements PassInterface * @var array */ protected $beacons = []; + + /** + * NFC where the pass is relevant. + * + * @var array + */ + protected $nfc = []; + /** * A list of iTunes Store item identifiers (also known as Adam IDs) for the @@ -176,6 +185,8 @@ class Pass implements PassInterface * @var string */ protected $logoText; + + /** * If true, the strip image is displayed without a shine effect. @@ -283,6 +294,7 @@ public function toArray() 'description', 'formatVersion', 'beacons', + 'nfc', 'locations', 'maxDistance', 'relevantDate', @@ -521,6 +533,24 @@ public function getBeacons() return $this->beacons; } + /** + * {@inheritdoc} + */ + public function addNfc(NfcInterface $nfc) + { + $this->nfc[] = $nfc; + return $this; + } + + /** + * {@inheritdoc} + */ + public function getNfc() + { + return $this->nfc; + } + + /** * {@inheritdoc} */ @@ -568,6 +598,16 @@ public function setBarcode(BarcodeInterface $barcode) return $this; } + /** + * {@inheritdoc} + */ + public function setNfc(NfcInterface $nfc) + { + $this->nfc = $nfc; + return $this; + } + + /** * {@inheritdoc} */ diff --git a/src/Passbook/Pass/Nfc.php b/src/Passbook/Pass/Nfc.php new file mode 100644 index 0000000..3c0f67f --- /dev/null +++ b/src/Passbook/Pass/Nfc.php @@ -0,0 +1,78 @@ +setMessage($message); + $this->setEncryptionPublicKey($encryptionPublicKey); + } + + /** + * {@inheritdoc} + */ + public function setMessage($message) + { + $this->message = $message; + return $this; + } + + /** + * {@inheritdoc} + */ + public function setEncryptionPublicKey($encryptionPublicKey) + { + $this->encryptionPublicKey = $encryptionPublicKey; + return $this; + } + + public function toArray() + { + $array = [ + 'message' => $this->getMessage(), + 'encryptionPublicKey' => $this->getEncryptionPublicKey() + ]; + return $array; + } + + /** + * {@inheritdoc} + */ + public function getMessage() + { + return $this->message; + } + + /** + * {@inheritdoc} + */ + public function getEncryptionPublicKey() + { + return $this->encryptionPublicKey; + } +} + diff --git a/src/Passbook/Pass/NfcInterface.php b/src/Passbook/Pass/NfcInterface.php new file mode 100644 index 0000000..80b00ab --- /dev/null +++ b/src/Passbook/Pass/NfcInterface.php @@ -0,0 +1,46 @@ +validateRequiredFields($pass); $this->validateBeaconKeys($pass); + $this->validateNfcKeys($pass); $this->validateLocationKeys($pass); $this->validateBarcodeKeys($pass); $this->validateWebServiceKeys($pass); @@ -109,6 +113,14 @@ private function validateBeaconKeys(PassInterface $pass) } } + private function validateNfcKeys(PassInterface $pass) + { + $nfcs = $pass->getNfc(); + foreach ($nfcs as $nfc) { + $this->validateNfc($nfc); + } + } + private function validateBeacon(Beacon $beacon) { if ($this->isBlankOrNull($beacon->getProximityUUID())) { @@ -128,6 +140,17 @@ private function validateBeacon(Beacon $beacon) } } + private function validateNfc(Nfc $nfc) + { + if ($this->isBlankOrNull($nfc->getMessage())) { + $this->addError(self::NFC_MESSAGE_REQUIRED); + } + + if ($this->isBlankOrNull($nfc->getEncryptionPublicKey())) { + $this->addError(self::NFC_ENCRYPTION_PUBLIC_KEY_REQUIRED); + } + } + private function validateLocationKeys(PassInterface $pass) { $locations = $pass->getLocations();