Skip to content

Commit

Permalink
Merge pull request #89 from hervehobbes/master
Browse files Browse the repository at this point in the history
Added NFC support
  • Loading branch information
eymengunay authored Nov 28, 2021
2 parents c6286a3 + f6e43c5 commit 4a1f776
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 1 deletion.
42 changes: 41 additions & 1 deletion src/Passbook/Pass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -73,14 +74,22 @@ class Pass implements PassInterface
*
* @var ImageInterface[]
*/
protected $images = [];
protected $images = array();

/**
* Beacons where the pass is relevant.
*
* @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
Expand Down Expand Up @@ -176,6 +185,8 @@ class Pass implements PassInterface
* @var string
*/
protected $logoText;



/**
* If true, the strip image is displayed without a shine effect.
Expand Down Expand Up @@ -283,6 +294,7 @@ public function toArray()
'description',
'formatVersion',
'beacons',
'nfc',
'locations',
'maxDistance',
'relevantDate',
Expand Down Expand Up @@ -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}
*/
Expand Down Expand Up @@ -568,6 +598,16 @@ public function setBarcode(BarcodeInterface $barcode)
return $this;
}

/**
* {@inheritdoc}
*/
public function setNfc(NfcInterface $nfc)
{
$this->nfc = $nfc;
return $this;
}


/**
* {@inheritdoc}
*/
Expand Down
78 changes: 78 additions & 0 deletions src/Passbook/Pass/Nfc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

/*
* This file is part of the Passbook package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Passbook\Pass;

/**
* NFC
*/
class Nfc implements NfcInterface
{
/**
* NFC message
* @var string
*/
protected $message = '';

/**
* Encryption Public Key
* @var string
*/
protected $encryptionPublicKey = '';

public function __construct($message, $encryptionPublicKey)
{
$this->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;
}
}

46 changes: 46 additions & 0 deletions src/Passbook/Pass/NfcInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/*
* This file is part of the Passbook package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Passbook\Pass;

use Passbook\ArrayableInterface;

/**
* NfcInterface
*/
interface NfcInterface extends ArrayableInterface
{
/**
* Sets NFC message
*
* @param string
*/
public function setMessage($message);

/**
* Gets NFC message
*
* @return string
*/
public function getMessage();

/**
* Sets encryption Public Key
*
* @param string
*/
public function setEncryptionPublicKey($encryptionPublicKey);

/**
* Gets encryptionPublicKey
*
* @return string
*/
public function getEncryptionPublicKey();
}
22 changes: 22 additions & 0 deletions src/Passbook/PassInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Passbook\Pass\BarcodeInterface;
use Passbook\Pass\BeaconInterface;
use Passbook\Pass\NfcInterface;
use Passbook\Pass\Image;
use Passbook\Pass\ImageInterface;
use Passbook\Pass\LocalizationInterface;
Expand Down Expand Up @@ -118,6 +119,17 @@ public function addBeacon(BeaconInterface $beacon);
* {@inheritdoc}
*/
public function getBeacons();

/**
* {@inheritdoc}
*/
public function addNfc(NfcInterface $nfc);

/**
* {@inheritdoc}
*/
public function getNfc();


/**
* {@inheritdoc}
Expand Down Expand Up @@ -216,6 +228,16 @@ public function setLogoText($logoText);
* {@inheritdoc}
*/
public function getLogoText();

/**
* {@inheritdoc}
*/
public function setSharingProhibited($sharingProhibited);

/**
* {@inheritdoc}
*/
public function getSharingProhibited();

/**
* {@inheritdoc}
Expand Down
23 changes: 23 additions & 0 deletions src/Passbook/PassValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Passbook\Pass\Barcode;
use Passbook\Pass\Beacon;
use Passbook\Pass\Nfc;
use Passbook\Pass\Location;

/**
Expand Down Expand Up @@ -37,6 +38,8 @@ class PassValidator implements PassValidatorInterface
const BEACON_PROXIMITY_UUID_REQUIRED = 'beacon proximityUUID is required';
const BEACON_MAJOR_INVALID = 'beacon major is invalid; must be 16-bit unsigned integer';
const BEACON_MINOR_INVALID = 'beacon minor is invalid; must be 16-bit unsigned integer';
const NFC_MESSAGE_REQUIRED = 'NFC message is required';
const NFC_ENCRYPTION_PUBLIC_KEY_REQUIRED = 'NFC encryption public key is required';
const WEB_SERVICE_URL_INVALID = 'webServiceURL is invalid; must start with https (or http for development)';
const WEB_SERVICE_AUTHENTICATION_TOKEN_REQUIRED = 'authenticationToken required with webServiceURL and cannot be blank';
const WEB_SERVICE_AUTHENTICATION_TOKEN_INVALID = 'authenticationToken is invalid; must be at least 16 characters';
Expand All @@ -54,6 +57,7 @@ public function validate(PassInterface $pass)

$this->validateRequiredFields($pass);
$this->validateBeaconKeys($pass);
$this->validateNfcKeys($pass);
$this->validateLocationKeys($pass);
$this->validateBarcodeKeys($pass);
$this->validateWebServiceKeys($pass);
Expand Down Expand Up @@ -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())) {
Expand All @@ -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();
Expand Down

0 comments on commit 4a1f776

Please sign in to comment.