Skip to content

Commit 4fa6fd5

Browse files
authored
Replace spatie/data-transfer-object with antwerpes/data-transfer-object (chiiya#35)
* Start replacing spatie dependency * Migrate to antwerpes/data-transfer-object * Use static method for legacy value mapping * Migrate remaining classes * Update dependencies
1 parent cfbe5e0 commit 4fa6fd5

File tree

200 files changed

+4582
-4693
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

200 files changed

+4582
-4693
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ node_modules
1818
service-credentials.json
1919
.env
2020
/tests/certs
21+
.phpunit.cache/

composer.json

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
"ext-zip": "*",
2626
"antwerpes/data-transfer-object": "^1.0",
2727
"google/auth": "^1.18",
28-
"spatie/data-transfer-object": "^3.7",
2928
"symfony/validator": "^7.1"
3029
},
3130
"require-dev": {

examples/google_generic.php

+25-25
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,6 @@
2929

3030
$class = new GenericClass(
3131
id: '1234567890123456789.generic-object',
32-
multipleDevicesAndHoldersAllowedStatus: MultipleDevicesAndHoldersAllowedStatus::MULTIPLE_HOLDERS,
33-
linksModuleData: new LinksModuleData(
34-
uris: [
35-
new Uri(uri: 'https://example.org/app', description: 'App'),
36-
new Uri(uri: 'https://example.org', description: 'Homepage'),
37-
]
38-
),
3932
imageModulesData: [
4033
new ImageModuleData(
4134
mainImage: Image::make('https://example.org/image.png')
@@ -46,53 +39,60 @@
4639
header: 'Lorem ipsum',
4740
body: 'Dolor sit amet'
4841
)
49-
]
42+
],
43+
linksModuleData: new LinksModuleData(
44+
uris: [
45+
new Uri(uri: 'https://example.org/app', description: 'App'),
46+
new Uri(uri: 'https://example.org', description: 'Homepage'),
47+
]
48+
),
49+
multipleDevicesAndHoldersAllowedStatus: MultipleDevicesAndHoldersAllowedStatus::MULTIPLE_HOLDERS
5050
);
5151
$repository->create($class);
5252

5353
$object = new GenericObject(
54-
classId: '1234567890123456789.generic-object',
55-
id: '1234567890123456789.'.Str::uuid()->toString(),
5654
cardTitle: LocalizedString::make('en', '::cardTitle::'),
57-
subheader: LocalizedString::make('en', '::subheader::'),
5855
header: LocalizedString::make('en', '::header::'),
56+
subheader: LocalizedString::make('en', '::subheader::'),
5957
logo: Image::make('https://example.org/logo.png'),
60-
heroImage: Image::make('https://example.org/hero-image.png'),
6158
hexBackgroundColor: '#333',
59+
notifications: new Notifications(
60+
upcomingNotification: new UpcomingNotification(
61+
enableNotification: true
62+
),
63+
),
64+
classId: '1234567890123456789.generic-object',
65+
id: '1234567890123456789.'.Str::uuid()->toString(),
66+
heroImage: Image::make('https://example.org/hero-image.png'),
6267
state: State::ACTIVE,
6368
barcode: new Barcode(
6469
type: BarcodeType::QR_CODE,
65-
renderEncoding: BarcodeRenderEncoding::UTF_8,
6670
value: '1464194291627',
71+
renderEncoding: BarcodeRenderEncoding::UTF_8,
6772
),
6873
validTimeInterval: new TimeInterval(
6974
start: new DateTime(date: now()),
7075
end: new DateTime(now()->addMonth())
7176
),
72-
notifications: new Notifications(
73-
upcomingNotification: new UpcomingNotification(
74-
enableNotification: true
75-
),
76-
),
7777
textModulesData: [
7878
new TextModuleData(
79-
id: 'key-1',
8079
header: 'label-1',
8180
body: 'value-1',
81+
id: 'key-1',
8282
),
8383
new TextModuleData(
84-
id: 'key-2',
8584
header: 'label-2',
8685
body: 'value-2',
86+
id: 'key-2',
8787
)
8888
],
8989
groupingInfo: new GroupingInfo(
9090
groupingId: 'group1'
9191
)
9292
);
9393

94-
$jwt = (new JWT([
95-
'iss' => $credentials->client_email,
96-
'key' => $credentials->private_key,
97-
'origins' => ['https://example.org'],
98-
]))->addOfferObject($object)->sign();
94+
$jwt = (new JWT(
95+
iss: $credentials->client_email,
96+
key: $credentials->private_key,
97+
origins: ['https://example.org'],
98+
))->addGenericObject($object)->sign();

examples/google_offer.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@
2424
$repository = new OfferClassRepository($client);
2525

2626
$class = new OfferClass(
27-
id: '1234567890123456789.coupon-15',
28-
issuerName: 'ACME',
29-
reviewStatus: ReviewStatus::UNDER_REVIEW,
3027
title: '15% off purchases',
3128
redemptionChannel: RedemptionChannel::INSTORE,
3229
provider: 'ACME',
3330
titleImage: Image::make('https://example.org/title.png'),
3431
helpUri: Uri::make('https://example.org/help'),
3532
localizedDetails: LocalizedString::make('en', '::value::'),
33+
id: '1234567890123456789.coupon-15',
34+
issuerName: 'ACME',
35+
reviewStatus: ReviewStatus::UNDER_REVIEW,
3636
imageModulesData: [
3737
new ImageModuleData(mainImage: Image::make('https://example.org/wallet.png')),
3838
],
@@ -60,8 +60,8 @@ classId: '1234567890123456789.coupon-15',
6060
),
6161
);
6262

63-
$jwt = (new JWT([
64-
'iss' => $credentials->client_email,
65-
'key' => $credentials->private_key,
66-
'origins' => ['https://example.org'],
67-
]))->addOfferObject($object)->sign();
63+
$jwt = (new JWT(
64+
iss: $credentials->client_email,
65+
key: $credentials->private_key,
66+
origins: ['https://example.org'],
67+
))->addOfferObject($object)->sign();

phpunit.xml.dist

+11-29
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,13 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
5-
backupGlobals="false"
6-
backupStaticAttributes="false"
7-
bootstrap="vendor/autoload.php"
8-
colors="true"
9-
convertErrorsToExceptions="true"
10-
convertNoticesToExceptions="true"
11-
convertWarningsToExceptions="true"
12-
processIsolation="false"
13-
stopOnFailure="false"
14-
executionOrder="random"
15-
failOnWarning="true"
16-
failOnRisky="true"
17-
failOnEmptyTestSuite="true"
18-
beStrictAboutOutputDuringTests="true"
19-
verbose="true"
20-
>
21-
<testsuites>
22-
<testsuite name="Chiiya Test Suite">
23-
<directory>tests</directory>
24-
</testsuite>
25-
</testsuites>
26-
<coverage>
27-
<include>
28-
<directory suffix=".php">./src</directory>
29-
</include>
30-
</coverage>
2+
<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">
3+
<testsuites>
4+
<testsuite name="Chiiya Test Suite">
5+
<directory>tests</directory>
6+
</testsuite>
7+
</testsuites>
8+
<source>
9+
<include>
10+
<directory suffix=".php">./src</directory>
11+
</include>
12+
</source>
3113
</phpunit>

src/Apple/Components/AuxiliaryField.php

+13-10
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,20 @@
22

33
namespace Chiiya\Passes\Apple\Components;
44

5-
use Chiiya\Passes\Common\Validation\ValueIn;
6-
use Spatie\DataTransferObject\Attributes\Strict;
5+
use Symfony\Component\Validator\Constraints\Choice;
76

8-
#[Strict]
97
class AuxiliaryField extends SecondaryField
108
{
11-
/**
12-
* Optional.
13-
* A number you use to add a row to the auxiliary field in an event ticket pass type.
14-
* Set the value to 1 to add an auxiliary row. Each row displays up to four fields.
15-
*/
16-
#[ValueIn([0, 1])]
17-
public ?int $row;
9+
public function __construct(
10+
/**
11+
* Optional.
12+
* A number you use to add a row to the auxiliary field in an event ticket pass type.
13+
* Set the value to 1 to add an auxiliary row. Each row displays up to four fields.
14+
*/
15+
#[Choice([0, 1])]
16+
public ?int $row = null,
17+
...$args,
18+
) {
19+
parent::__construct(...$args);
20+
}
1821
}

src/Apple/Components/Barcode.php

+34-34
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,41 @@
44

55
use Chiiya\Passes\Apple\Enumerators\BarcodeFormat;
66
use Chiiya\Passes\Common\Component;
7-
use Chiiya\Passes\Common\Validation\Required;
8-
use Chiiya\Passes\Common\Validation\ValueIn;
9-
use Spatie\DataTransferObject\Attributes\Strict;
7+
use Symfony\Component\Validator\Constraints\Choice;
8+
use Symfony\Component\Validator\Constraints\NotBlank;
109

11-
#[Strict]
1210
class Barcode extends Component
1311
{
14-
/**
15-
* Optional.
16-
* For example, a human-readable version of the barcode data in case
17-
* the barcode doesn't scan.
18-
*/
19-
public ?string $altText;
20-
21-
/**
22-
* Required.
23-
* Barcode format. The barcode format PKBarcodeFormatCode128 isn’t supported for watchOS.
24-
*
25-
* @see BarcodeFormat
26-
*/
27-
#[Required]
28-
#[ValueIn([BarcodeFormat::QR, BarcodeFormat::AZTEC, BarcodeFormat::GS1_128, BarcodeFormat::PDF417])]
29-
public ?string $format;
30-
31-
/**
32-
* Required.
33-
* Message or payload to be displayed as a barcode.
34-
*/
35-
#[Required]
36-
public ?string $message;
37-
38-
/**
39-
* Required.
40-
* Text encoding that is used to convert the message from the string representation to a data
41-
* representation to render the barcode.
42-
*/
43-
public ?string $messageEncoding = 'iso-8859-1';
12+
public function __construct(
13+
/**
14+
* Required.
15+
* Barcode format. The barcode format PKBarcodeFormatCode128 isn’t supported for watchOS.
16+
*
17+
* @see BarcodeFormat
18+
*/
19+
#[NotBlank]
20+
#[Choice([BarcodeFormat::QR, BarcodeFormat::AZTEC, BarcodeFormat::GS1_128, BarcodeFormat::PDF417])]
21+
public string $format,
22+
/**
23+
* Required.
24+
* Message or payload to be displayed as a barcode.
25+
*/
26+
#[NotBlank]
27+
public string $message,
28+
/**
29+
* Required.
30+
* Text encoding that is used to convert the message from the string representation to a data
31+
* representation to render the barcode.
32+
*/
33+
#[NotBlank]
34+
public string $messageEncoding = 'iso-8859-1',
35+
/**
36+
* Optional.
37+
* For example, a human-readable version of the barcode data in case
38+
* the barcode doesn't scan.
39+
*/
40+
public ?string $altText = null,
41+
) {
42+
parent::__construct();
43+
}
4444
}

src/Apple/Components/Beacon.php

+29-30
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,39 @@
33
namespace Chiiya\Passes\Apple\Components;
44

55
use Chiiya\Passes\Common\Component;
6-
use Chiiya\Passes\Common\Validation\NumberBetween;
7-
use Chiiya\Passes\Common\Validation\Required;
8-
use Spatie\DataTransferObject\Attributes\Strict;
6+
use Symfony\Component\Validator\Constraints\NotBlank;
7+
use Symfony\Component\Validator\Constraints\Range;
98

109
/**
1110
* @since iOS v7.0
1211
*/
13-
#[Strict]
1412
class Beacon extends Component
1513
{
16-
/**
17-
* Optional.
18-
* Major identifier of a Bluetooth Low Energy location beacon.
19-
*/
20-
#[NumberBetween(0, 65535)]
21-
public ?int $major;
22-
23-
/**
24-
* Optional.
25-
* Minor identifier of a Bluetooth Low Energy location beacon.
26-
*/
27-
#[NumberBetween(0, 65535)]
28-
public ?int $minor;
29-
30-
/**
31-
* Required.
32-
* Unique identifier of a Bluetooth Low Energy location beacon.
33-
*/
34-
#[Required]
35-
public ?string $proximityUUID;
36-
37-
/**
38-
* Optional.
39-
* Text displayed on the lock screen when the pass is currently relevant.
40-
*/
41-
public ?string $relevantText;
14+
public function __construct(
15+
/**
16+
* Required.
17+
* Unique identifier of a Bluetooth Low Energy location beacon.
18+
*/
19+
#[NotBlank]
20+
public string $proximityUUID,
21+
/**
22+
* Optional.
23+
* Major identifier of a Bluetooth Low Energy location beacon.
24+
*/
25+
#[Range(min: 0, max: 65535)]
26+
public ?int $major = null,
27+
/**
28+
* Optional.
29+
* Minor identifier of a Bluetooth Low Energy location beacon.
30+
*/
31+
#[Range(min: 0, max: 65535)]
32+
public ?int $minor = null,
33+
/**
34+
* Optional.
35+
* Text displayed on the lock screen when the pass is currently relevant.
36+
*/
37+
public ?string $relevantText = null,
38+
) {
39+
parent::__construct();
40+
}
4241
}

src/Apple/Components/CurrencyAmount.php

+14-13
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@
33
namespace Chiiya\Passes\Apple\Components;
44

55
use Chiiya\Passes\Common\Component;
6-
use Spatie\DataTransferObject\Attributes\Strict;
76

8-
#[Strict]
97
class CurrencyAmount extends Component
108
{
11-
/**
12-
* Optional.
13-
* The amount of money.
14-
*/
15-
public ?string $amount;
16-
17-
/**
18-
* Optional.
19-
* The currency code for amount.
20-
*/
21-
public ?string $currencyCode;
9+
public function __construct(
10+
/**
11+
* Optional.
12+
* The amount of money.
13+
*/
14+
public ?string $amount = null,
15+
/**
16+
* Optional.
17+
* The currency code for amount.
18+
*/
19+
public ?string $currencyCode = null,
20+
) {
21+
parent::__construct();
22+
}
2223
}

0 commit comments

Comments
 (0)