Skip to content

Commit 2e83352

Browse files
committed
Introduce Color value object
1 parent afcb8b7 commit 2e83352

67 files changed

Lines changed: 350 additions & 200 deletions

File tree

Some content is hidden

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

src/Builder/CommonWalletBuilderTrait.php

Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
namespace Jolicode\WalletKit\Builder;
66

77
use Jolicode\WalletKit\Builder\Internal\BarcodeMapper;
8-
use Jolicode\WalletKit\Builder\Internal\ColorMapper;
98
use Jolicode\WalletKit\Builder\Internal\CommonWalletState;
109
use Jolicode\WalletKit\Builder\Internal\SamsungBarcodeMapper;
10+
use Jolicode\WalletKit\Common\Color;
1111
use Jolicode\WalletKit\Exception\ApplePlatformContextRequiredException;
1212
use Jolicode\WalletKit\Exception\GooglePlatformContextRequiredException;
1313
use Jolicode\WalletKit\Exception\SamsungPlatformContextRequiredException;
@@ -52,43 +52,23 @@ public function withGoogleBarcodeOverride(?GoogleBarcode $barcode): static
5252
return $this;
5353
}
5454

55-
public function withAppleBackgroundColor(?string $color): static
55+
public function withBackgroundColor(?Color $color): static
5656
{
57-
$this->common->appleBackgroundColor = $color;
57+
$this->common->backgroundColor = $color;
5858

5959
return $this;
6060
}
6161

62-
public function withGoogleHexBackgroundColor(?string $hex): static
62+
public function withForegroundColor(?Color $color): static
6363
{
64-
$this->common->googleHexBackgroundColor = $hex;
64+
$this->common->foregroundColor = $color;
6565

6666
return $this;
6767
}
6868

69-
/**
70-
* Sets Apple background from RGB and, when parsable, derives Google hex automatically unless hex was set explicitly.
71-
*/
72-
public function withBackgroundColorRgb(string $appleRgb): static
73-
{
74-
$this->common->appleBackgroundColor = $appleRgb;
75-
if (null === $this->common->googleHexBackgroundColor) {
76-
$this->common->googleHexBackgroundColor = ColorMapper::appleRgbToGoogleHex($appleRgb);
77-
}
78-
79-
return $this;
80-
}
81-
82-
public function withAppleForegroundColor(?string $color): static
69+
public function withLabelColor(?Color $color): static
8370
{
84-
$this->common->appleForegroundColor = $color;
85-
86-
return $this;
87-
}
88-
89-
public function withAppleLabelColor(?string $color): static
90-
{
91-
$this->common->appleLabelColor = $color;
71+
$this->common->labelColor = $color;
9272

9373
return $this;
9474
}
@@ -211,10 +191,9 @@ protected function primaryGoogleBarcode(): ?GoogleBarcode
211191
return BarcodeMapper::fromFirstAppleBarcode($this->common->appleBarcodes);
212192
}
213193

214-
protected function resolvedGoogleHex(): ?string
194+
protected function resolvedBackgroundColor(): ?Color
215195
{
216-
return $this->common->googleHexBackgroundColor
217-
?? ColorMapper::appleRgbToGoogleHex($this->common->appleBackgroundColor);
196+
return $this->common->backgroundColor;
218197
}
219198

220199
protected function resolvedGoogleReviewStatus(): ReviewStatusEnum
@@ -279,9 +258,9 @@ protected function createApplePass(\Jolicode\WalletKit\Pass\Apple\Model\PassType
279258
appLaunchURL: $this->common->appLaunchURL,
280259
webServiceURL: $this->common->webServiceURL,
281260
authenticationToken: $this->common->authenticationToken,
282-
backgroundColor: $this->common->appleBackgroundColor,
283-
foregroundColor: $this->common->appleForegroundColor,
284-
labelColor: $this->common->appleLabelColor,
261+
backgroundColor: $this->common->backgroundColor,
262+
foregroundColor: $this->common->foregroundColor,
263+
labelColor: $this->common->labelColor,
285264
groupingIdentifier: $this->common->groupingIdentifier,
286265
expirationDate: $this->common->appleExpirationDate,
287266
voided: $this->common->appleVoided,
@@ -295,12 +274,6 @@ protected function primarySamsungBarcode(): ?SamsungBarcode
295274
return SamsungBarcodeMapper::fromFirstAppleBarcode($this->common->appleBarcodes);
296275
}
297276

298-
protected function resolvedSamsungHexColor(): ?string
299-
{
300-
return $this->common->googleHexBackgroundColor
301-
?? ColorMapper::appleRgbToGoogleHex($this->common->appleBackgroundColor);
302-
}
303-
304277
/**
305278
* Builds the Samsung {@see Card} envelope shared by all verticals.
306279
*/

src/Builder/EventTicket/EventTicketWalletBuilder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function build(): BuiltWalletPass
7575
issuerName: $this->context->googleIssuerName(),
7676
eventName: $this->eventName,
7777
reviewStatus: $this->resolvedGoogleReviewStatus(),
78-
hexBackgroundColor: $this->resolvedGoogleHex(),
78+
hexBackgroundColor: $this->resolvedBackgroundColor(),
7979
linksModuleData: $this->common->linksModuleData,
8080
appLinkData: $this->common->appLinkData,
8181
);
@@ -87,7 +87,7 @@ classId: $g->classId,
8787
ticketHolderName: $this->ticketHolderName,
8888
ticketNumber: $this->ticketNumber,
8989
barcode: $this->primaryGoogleBarcode(),
90-
hexBackgroundColor: $this->resolvedGoogleHex(),
90+
hexBackgroundColor: $this->resolvedBackgroundColor(),
9191
validTimeInterval: $this->common->validTimeInterval,
9292
linksModuleData: $this->common->linksModuleData,
9393
appLinkData: $this->common->appLinkData,
@@ -114,7 +114,7 @@ classId: $g->classId,
114114
holderName: $this->ticketHolderName,
115115
seatNumber: null,
116116
barcode: $this->primarySamsungBarcode(),
117-
bgColor: $this->resolvedSamsungHexColor(),
117+
bgColor: $this->resolvedBackgroundColor(),
118118
);
119119
$samsungCard = $this->createSamsungCard(CardTypeEnum::TICKET, CardSubTypeEnum::PERFORMANCES, $attributes);
120120
}

src/Builder/Flight/FlightWalletBuilder.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Jolicode\WalletKit\Builder\GoogleVerticalEnum;
1010
use Jolicode\WalletKit\Builder\GoogleWalletPair;
1111
use Jolicode\WalletKit\Builder\WalletPlatformContext;
12+
use Jolicode\WalletKit\Common\Color;
1213
use Jolicode\WalletKit\Pass\Android\Model\Flight\AirportInfo;
1314
use Jolicode\WalletKit\Pass\Android\Model\Flight\BoardingAndSeatingInfo;
1415
use Jolicode\WalletKit\Pass\Android\Model\Flight\FlightClass;
@@ -81,7 +82,7 @@ public function build(): BuiltWalletPass
8182
origin: $this->origin,
8283
destination: $this->destination,
8384
flightHeader: $this->flightHeader,
84-
hexBackgroundColor: $this->resolvedGoogleHex(),
85+
hexBackgroundColor: $this->resolvedBackgroundColor(),
8586
linksModuleData: $this->common->linksModuleData,
8687
appLinkData: $this->common->appLinkData,
8788
);
@@ -94,7 +95,7 @@ classId: $g->classId,
9495
reservationInfo: $this->reservationInfo,
9596
boardingAndSeatingInfo: $this->boardingAndSeatingInfo,
9697
barcode: $this->primaryGoogleBarcode(),
97-
hexBackgroundColor: $this->resolvedGoogleHex(),
98+
hexBackgroundColor: $this->resolvedBackgroundColor(),
9899
validTimeInterval: $this->common->validTimeInterval,
99100
linksModuleData: $this->common->linksModuleData,
100101
appLinkData: $this->common->appLinkData,
@@ -110,7 +111,7 @@ classId: $g->classId,
110111
$attributes = new BoardingPassAttributes(
111112
title: 'Flight ' . ($this->flightHeader->flightNumber ?? ''),
112113
providerName: $this->context->hasApple() ? $this->context->apple->organizationName : ($this->context->hasGoogle() ? $this->context->googleIssuerName() : ''),
113-
bgColor: $this->resolvedSamsungHexColor() ?? '#000000',
114+
bgColor: $this->resolvedBackgroundColor() ?? Color::fromHex('#000000'),
114115
appLinkLogo: $s->appLinkLogo ?? '',
115116
appLinkName: $s->appLinkName ?? '',
116117
appLinkData: $s->appLinkData ?? '',

src/Builder/Generic/GenericWalletBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function build(): BuiltWalletPass
8282
classId: $g->classId,
8383
genericType: $this->genericType,
8484
cardTitle: $cardTitle,
85-
hexBackgroundColor: $this->resolvedGoogleHex(),
85+
hexBackgroundColor: $this->resolvedBackgroundColor(),
8686
barcode: $this->primaryGoogleBarcode(),
8787
validTimeInterval: $this->common->validTimeInterval,
8888
linksModuleData: $this->common->linksModuleData,
@@ -105,7 +105,7 @@ classId: $g->classId,
105105
appLinkLogo: $s->appLinkLogo ?? '',
106106
appLinkName: $s->appLinkName ?? '',
107107
appLinkData: $s->appLinkData ?? '',
108-
bgColor: $this->resolvedSamsungHexColor(),
108+
bgColor: $this->resolvedBackgroundColor(),
109109
serial1: $this->primarySamsungBarcode(),
110110
groupingId: $this->common->groupingIdentifier,
111111
);

src/Builder/GiftCard/GiftCardWalletBuilder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function build(): BuiltWalletPass
6565
id: $g->classId,
6666
issuerName: $this->context->googleIssuerName(),
6767
reviewStatus: $this->resolvedGoogleReviewStatus(),
68-
hexBackgroundColor: $this->resolvedGoogleHex(),
68+
hexBackgroundColor: $this->resolvedBackgroundColor(),
6969
linksModuleData: $this->common->linksModuleData,
7070
appLinkData: $this->common->appLinkData,
7171
);
@@ -77,7 +77,7 @@ classId: $g->classId,
7777
cardNumber: $this->cardNumber,
7878
pin: $this->pin,
7979
barcode: $this->primaryGoogleBarcode(),
80-
hexBackgroundColor: $this->resolvedGoogleHex(),
80+
hexBackgroundColor: $this->resolvedBackgroundColor(),
8181
validTimeInterval: $this->common->validTimeInterval,
8282
linksModuleData: $this->common->linksModuleData,
8383
appLinkData: $this->common->appLinkData,
@@ -97,7 +97,7 @@ classId: $g->classId,
9797
appLinkName: $s->appLinkName ?? '',
9898
appLinkData: $s->appLinkData ?? '',
9999
barcode: $this->primarySamsungBarcode(),
100-
bgColor: $this->resolvedSamsungHexColor(),
100+
bgColor: $this->resolvedBackgroundColor(),
101101
amount: $this->cardNumber,
102102
);
103103
$samsungCard = $this->createSamsungCard(CardTypeEnum::GIFT_CARD, CardSubTypeEnum::OTHERS, $attributes);

src/Builder/Internal/ColorMapper.php

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/Builder/Internal/CommonWalletState.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Jolicode\WalletKit\Builder\Internal;
66

7+
use Jolicode\WalletKit\Common\Color;
78
use Jolicode\WalletKit\Pass\Android\Model\Shared\AppLinkData;
89
use Jolicode\WalletKit\Pass\Android\Model\Shared\Barcode as GoogleBarcode;
910
use Jolicode\WalletKit\Pass\Android\Model\Shared\LinksModuleData;
@@ -21,13 +22,11 @@ final class CommonWalletState
2122

2223
public ?GoogleBarcode $googleBarcodeOverride = null;
2324

24-
public ?string $appleBackgroundColor = null;
25+
public ?Color $backgroundColor = null;
2526

26-
public ?string $googleHexBackgroundColor = null;
27+
public ?Color $foregroundColor = null;
2728

28-
public ?string $appleForegroundColor = null;
29-
30-
public ?string $appleLabelColor = null;
29+
public ?Color $labelColor = null;
3130

3231
public ?string $groupingIdentifier = null;
3332

src/Builder/Loyalty/LoyaltyWalletBuilder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function build(): BuiltWalletPass
6363
issuerName: $this->context->googleIssuerName(),
6464
reviewStatus: $this->resolvedGoogleReviewStatus(),
6565
programName: $this->programName,
66-
hexBackgroundColor: $this->resolvedGoogleHex(),
66+
hexBackgroundColor: $this->resolvedBackgroundColor(),
6767
linksModuleData: $this->common->linksModuleData,
6868
appLinkData: $this->common->appLinkData,
6969
);
@@ -75,7 +75,7 @@ classId: $g->classId,
7575
accountName: $this->accountName,
7676
accountId: $this->accountId,
7777
barcode: $this->primaryGoogleBarcode(),
78-
hexBackgroundColor: $this->resolvedGoogleHex(),
78+
hexBackgroundColor: $this->resolvedBackgroundColor(),
7979
validTimeInterval: $this->common->validTimeInterval,
8080
linksModuleData: $this->common->linksModuleData,
8181
appLinkData: $this->common->appLinkData,
@@ -95,7 +95,7 @@ classId: $g->classId,
9595
appLinkName: $s->appLinkName ?? '',
9696
appLinkData: $s->appLinkData ?? '',
9797
barcode: $this->primarySamsungBarcode(),
98-
bgColor: $this->resolvedSamsungHexColor(),
98+
bgColor: $this->resolvedBackgroundColor(),
9999
merchantName: $this->programName,
100100
);
101101
$samsungCard = $this->createSamsungCard(CardTypeEnum::LOYALTY, CardSubTypeEnum::OTHERS, $attributes);

src/Builder/Offer/OfferWalletBuilder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function build(): BuiltWalletPass
5454
provider: $this->provider,
5555
redemptionChannel: $this->redemptionChannel,
5656
reviewStatus: $this->resolvedGoogleReviewStatus(),
57-
hexBackgroundColor: $this->resolvedGoogleHex(),
57+
hexBackgroundColor: $this->resolvedBackgroundColor(),
5858
linksModuleData: $this->common->linksModuleData,
5959
appLinkData: $this->common->appLinkData,
6060
);
@@ -64,7 +64,7 @@ public function build(): BuiltWalletPass
6464
classId: $g->classId,
6565
state: $this->resolvedGoogleObjectState(),
6666
barcode: $this->primaryGoogleBarcode(),
67-
hexBackgroundColor: $this->resolvedGoogleHex(),
67+
hexBackgroundColor: $this->resolvedBackgroundColor(),
6868
validTimeInterval: $this->common->validTimeInterval,
6969
linksModuleData: $this->common->linksModuleData,
7070
appLinkData: $this->common->appLinkData,
@@ -87,7 +87,7 @@ classId: $g->classId,
8787
expiry: $now + 86400000 * 365,
8888
brandName: $this->provider,
8989
barcode: $this->primarySamsungBarcode(),
90-
bgColor: $this->resolvedSamsungHexColor(),
90+
bgColor: $this->resolvedBackgroundColor(),
9191
);
9292
$samsungCard = $this->createSamsungCard(CardTypeEnum::COUPON, CardSubTypeEnum::OTHERS, $attributes);
9393
}

src/Builder/Transit/TransitWalletBuilder.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Jolicode\WalletKit\Builder\GoogleVerticalEnum;
1010
use Jolicode\WalletKit\Builder\GoogleWalletPair;
1111
use Jolicode\WalletKit\Builder\WalletPlatformContext;
12+
use Jolicode\WalletKit\Common\Color;
1213
use Jolicode\WalletKit\Pass\Android\Model\Transit\TransitClass;
1314
use Jolicode\WalletKit\Pass\Android\Model\Transit\TransitObject;
1415
use Jolicode\WalletKit\Pass\Android\Model\Transit\TransitTypeEnum as GoogleTransitTypeEnum;
@@ -64,7 +65,7 @@ public function build(): BuiltWalletPass
6465
issuerName: $this->context->googleIssuerName(),
6566
reviewStatus: $this->resolvedGoogleReviewStatus(),
6667
transitType: $this->googleTransitType,
67-
hexBackgroundColor: $this->resolvedGoogleHex(),
68+
hexBackgroundColor: $this->resolvedBackgroundColor(),
6869
linksModuleData: $this->common->linksModuleData,
6970
appLinkData: $this->common->appLinkData,
7071
);
@@ -76,7 +77,7 @@ classId: $g->classId,
7677
tripType: $this->tripType,
7778
ticketNumber: $this->ticketNumber,
7879
barcode: $this->primaryGoogleBarcode(),
79-
hexBackgroundColor: $this->resolvedGoogleHex(),
80+
hexBackgroundColor: $this->resolvedBackgroundColor(),
8081
validTimeInterval: $this->common->validTimeInterval,
8182
linksModuleData: $this->common->linksModuleData,
8283
appLinkData: $this->common->appLinkData,
@@ -93,7 +94,7 @@ classId: $g->classId,
9394
$attributes = new BoardingPassAttributes(
9495
title: 'Transit',
9596
providerName: $this->context->hasApple() ? $this->context->apple->organizationName : ($this->context->hasGoogle() ? $this->context->googleIssuerName() : ''),
96-
bgColor: $this->resolvedSamsungHexColor() ?? '#000000',
97+
bgColor: $this->resolvedBackgroundColor() ?? Color::fromHex('#000000'),
9798
appLinkLogo: $s->appLinkLogo ?? '',
9899
appLinkName: $s->appLinkName ?? '',
99100
appLinkData: $s->appLinkData ?? '',

0 commit comments

Comments
 (0)