Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace spatie/data-transfer-object with antwerpes/data-transfer-object #35

Merged
merged 5 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ node_modules
service-credentials.json
.env
/tests/certs
.phpunit.cache/
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"ext-zip": "*",
"antwerpes/data-transfer-object": "^1.0",
"google/auth": "^1.18",
"spatie/data-transfer-object": "^3.7",
"symfony/validator": "^7.1"
},
"require-dev": {
Expand Down
50 changes: 25 additions & 25 deletions examples/google_generic.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@

$class = new GenericClass(
id: '1234567890123456789.generic-object',
multipleDevicesAndHoldersAllowedStatus: MultipleDevicesAndHoldersAllowedStatus::MULTIPLE_HOLDERS,
linksModuleData: new LinksModuleData(
uris: [
new Uri(uri: 'https://example.org/app', description: 'App'),
new Uri(uri: 'https://example.org', description: 'Homepage'),
]
),
imageModulesData: [
new ImageModuleData(
mainImage: Image::make('https://example.org/image.png')
Expand All @@ -46,53 +39,60 @@
header: 'Lorem ipsum',
body: 'Dolor sit amet'
)
]
],
linksModuleData: new LinksModuleData(
uris: [
new Uri(uri: 'https://example.org/app', description: 'App'),
new Uri(uri: 'https://example.org', description: 'Homepage'),
]
),
multipleDevicesAndHoldersAllowedStatus: MultipleDevicesAndHoldersAllowedStatus::MULTIPLE_HOLDERS
);
$repository->create($class);

$object = new GenericObject(
classId: '1234567890123456789.generic-object',
id: '1234567890123456789.'.Str::uuid()->toString(),
cardTitle: LocalizedString::make('en', '::cardTitle::'),
subheader: LocalizedString::make('en', '::subheader::'),
header: LocalizedString::make('en', '::header::'),
subheader: LocalizedString::make('en', '::subheader::'),
logo: Image::make('https://example.org/logo.png'),
heroImage: Image::make('https://example.org/hero-image.png'),
hexBackgroundColor: '#333',
notifications: new Notifications(
upcomingNotification: new UpcomingNotification(
enableNotification: true
),
),
classId: '1234567890123456789.generic-object',
id: '1234567890123456789.'.Str::uuid()->toString(),
heroImage: Image::make('https://example.org/hero-image.png'),
state: State::ACTIVE,
barcode: new Barcode(
type: BarcodeType::QR_CODE,
renderEncoding: BarcodeRenderEncoding::UTF_8,
value: '1464194291627',
renderEncoding: BarcodeRenderEncoding::UTF_8,
),
validTimeInterval: new TimeInterval(
start: new DateTime(date: now()),
end: new DateTime(now()->addMonth())
),
notifications: new Notifications(
upcomingNotification: new UpcomingNotification(
enableNotification: true
),
),
textModulesData: [
new TextModuleData(
id: 'key-1',
header: 'label-1',
body: 'value-1',
id: 'key-1',
),
new TextModuleData(
id: 'key-2',
header: 'label-2',
body: 'value-2',
id: 'key-2',
)
],
groupingInfo: new GroupingInfo(
groupingId: 'group1'
)
);

$jwt = (new JWT([
'iss' => $credentials->client_email,
'key' => $credentials->private_key,
'origins' => ['https://example.org'],
]))->addOfferObject($object)->sign();
$jwt = (new JWT(
iss: $credentials->client_email,
key: $credentials->private_key,
origins: ['https://example.org'],
))->addGenericObject($object)->sign();
16 changes: 8 additions & 8 deletions examples/google_offer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
$repository = new OfferClassRepository($client);

$class = new OfferClass(
id: '1234567890123456789.coupon-15',
issuerName: 'ACME',
reviewStatus: ReviewStatus::UNDER_REVIEW,
title: '15% off purchases',
redemptionChannel: RedemptionChannel::INSTORE,
provider: 'ACME',
titleImage: Image::make('https://example.org/title.png'),
helpUri: Uri::make('https://example.org/help'),
localizedDetails: LocalizedString::make('en', '::value::'),
id: '1234567890123456789.coupon-15',
issuerName: 'ACME',
reviewStatus: ReviewStatus::UNDER_REVIEW,
imageModulesData: [
new ImageModuleData(mainImage: Image::make('https://example.org/wallet.png')),
],
Expand Down Expand Up @@ -60,8 +60,8 @@ classId: '1234567890123456789.coupon-15',
),
);

$jwt = (new JWT([
'iss' => $credentials->client_email,
'key' => $credentials->private_key,
'origins' => ['https://example.org'],
]))->addOfferObject($object)->sign();
$jwt = (new JWT(
iss: $credentials->client_email,
key: $credentials->private_key,
origins: ['https://example.org'],
))->addOfferObject($object)->sign();
40 changes: 11 additions & 29 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,31 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
executionOrder="random"
failOnWarning="true"
failOnRisky="true"
failOnEmptyTestSuite="true"
beStrictAboutOutputDuringTests="true"
verbose="true"
>
<testsuites>
<testsuite name="Chiiya Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.3/phpunit.xsd" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" executionOrder="random" failOnWarning="true" failOnRisky="true" failOnEmptyTestSuite="true" beStrictAboutOutputDuringTests="true" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="Chiiya Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
23 changes: 13 additions & 10 deletions src/Apple/Components/AuxiliaryField.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@

namespace Chiiya\Passes\Apple\Components;

use Chiiya\Passes\Common\Validation\ValueIn;
use Spatie\DataTransferObject\Attributes\Strict;
use Symfony\Component\Validator\Constraints\Choice;

#[Strict]
class AuxiliaryField extends SecondaryField
{
/**
* Optional.
* A number you use to add a row to the auxiliary field in an event ticket pass type.
* Set the value to 1 to add an auxiliary row. Each row displays up to four fields.
*/
#[ValueIn([0, 1])]
public ?int $row;
public function __construct(
/**
* Optional.
* A number you use to add a row to the auxiliary field in an event ticket pass type.
* Set the value to 1 to add an auxiliary row. Each row displays up to four fields.
*/
#[Choice([0, 1])]
public ?int $row = null,
...$args,
) {
parent::__construct(...$args);
}
}
68 changes: 34 additions & 34 deletions src/Apple/Components/Barcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,41 @@

use Chiiya\Passes\Apple\Enumerators\BarcodeFormat;
use Chiiya\Passes\Common\Component;
use Chiiya\Passes\Common\Validation\Required;
use Chiiya\Passes\Common\Validation\ValueIn;
use Spatie\DataTransferObject\Attributes\Strict;
use Symfony\Component\Validator\Constraints\Choice;
use Symfony\Component\Validator\Constraints\NotBlank;

#[Strict]
class Barcode extends Component
{
/**
* Optional.
* For example, a human-readable version of the barcode data in case
* the barcode doesn't scan.
*/
public ?string $altText;

/**
* Required.
* Barcode format. The barcode format PKBarcodeFormatCode128 isn’t supported for watchOS.
*
* @see BarcodeFormat
*/
#[Required]
#[ValueIn([BarcodeFormat::QR, BarcodeFormat::AZTEC, BarcodeFormat::GS1_128, BarcodeFormat::PDF417])]
public ?string $format;

/**
* Required.
* Message or payload to be displayed as a barcode.
*/
#[Required]
public ?string $message;

/**
* Required.
* Text encoding that is used to convert the message from the string representation to a data
* representation to render the barcode.
*/
public ?string $messageEncoding = 'iso-8859-1';
public function __construct(
/**
* Required.
* Barcode format. The barcode format PKBarcodeFormatCode128 isn’t supported for watchOS.
*
* @see BarcodeFormat
*/
#[NotBlank]
#[Choice([BarcodeFormat::QR, BarcodeFormat::AZTEC, BarcodeFormat::GS1_128, BarcodeFormat::PDF417])]
public string $format,
/**
* Required.
* Message or payload to be displayed as a barcode.
*/
#[NotBlank]
public string $message,
/**
* Required.
* Text encoding that is used to convert the message from the string representation to a data
* representation to render the barcode.
*/
#[NotBlank]
public string $messageEncoding = 'iso-8859-1',
/**
* Optional.
* For example, a human-readable version of the barcode data in case
* the barcode doesn't scan.
*/
public ?string $altText = null,
) {
parent::__construct();
}
}
59 changes: 29 additions & 30 deletions src/Apple/Components/Beacon.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,39 @@
namespace Chiiya\Passes\Apple\Components;

use Chiiya\Passes\Common\Component;
use Chiiya\Passes\Common\Validation\NumberBetween;
use Chiiya\Passes\Common\Validation\Required;
use Spatie\DataTransferObject\Attributes\Strict;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Range;

/**
* @since iOS v7.0
*/
#[Strict]
class Beacon extends Component
{
/**
* Optional.
* Major identifier of a Bluetooth Low Energy location beacon.
*/
#[NumberBetween(0, 65535)]
public ?int $major;

/**
* Optional.
* Minor identifier of a Bluetooth Low Energy location beacon.
*/
#[NumberBetween(0, 65535)]
public ?int $minor;

/**
* Required.
* Unique identifier of a Bluetooth Low Energy location beacon.
*/
#[Required]
public ?string $proximityUUID;

/**
* Optional.
* Text displayed on the lock screen when the pass is currently relevant.
*/
public ?string $relevantText;
public function __construct(
/**
* Required.
* Unique identifier of a Bluetooth Low Energy location beacon.
*/
#[NotBlank]
public string $proximityUUID,
/**
* Optional.
* Major identifier of a Bluetooth Low Energy location beacon.
*/
#[Range(min: 0, max: 65535)]
public ?int $major = null,
/**
* Optional.
* Minor identifier of a Bluetooth Low Energy location beacon.
*/
#[Range(min: 0, max: 65535)]
public ?int $minor = null,
/**
* Optional.
* Text displayed on the lock screen when the pass is currently relevant.
*/
public ?string $relevantText = null,
) {
parent::__construct();
}
}
27 changes: 14 additions & 13 deletions src/Apple/Components/CurrencyAmount.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@
namespace Chiiya\Passes\Apple\Components;

use Chiiya\Passes\Common\Component;
use Spatie\DataTransferObject\Attributes\Strict;

#[Strict]
class CurrencyAmount extends Component
{
/**
* Optional.
* The amount of money.
*/
public ?string $amount;

/**
* Optional.
* The currency code for amount.
*/
public ?string $currencyCode;
public function __construct(
/**
* Optional.
* The amount of money.
*/
public ?string $amount = null,
/**
* Optional.
* The currency code for amount.
*/
public ?string $currencyCode = null,
) {
parent::__construct();
}
}
Loading
Loading