Skip to content

Commit dae2edc

Browse files
committed
allow to set a separate delivery address
Change-Id: Iaf90a2b6e7cf0e4af2f486170d7079f1c4300152
1 parent 41f3b74 commit dae2edc

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

dto.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@ class User {
44
private string $firstName;
55
private string $lastName;
66

7-
private Address $address;
7+
private Address $invoiceAddress;
8+
private Address|null $deliveryAddress = null;
89

910
public function __construct(array $data) {
1011
$this->firstName = $data['firstName'];
1112
$this->lastName = $data['lastName'];
12-
$this->address = new Address($data['address']);
13+
$this->invoiceAddress = new Address($data['invoiceAddress']);
14+
if (empty($data['deliveryAddress']['street'])) {
15+
$this->deliveryAddress = new Address($data['deliveryAddress']);
16+
}
1317
}
1418

1519
public function getFirstName(): string {
@@ -20,8 +24,12 @@ public function getLastName(): string {
2024
return $this->lastName;
2125
}
2226

23-
public function getAddress(): Address {
24-
return $this->address;
27+
public function getInvoiceAddress(): Address {
28+
return $this->invoiceAddress;
29+
}
30+
31+
public function getDeliveryAddress(): Address {
32+
return $this->deliveryAddress ?: $this->invoiceAddress;
2533
}
2634
}
2735

index.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,14 @@
1212
<form>
1313
<label>first name <input name="firstName"/></label><br>
1414
<label>last name <input name="lastName"/></label><br>
15-
<label>street <input name="address[street]"/></label><br>
16-
<label>zip <input name="address[zip]"/></label><br>
17-
<label>city <input name="address[city]"/></label><br>
15+
<h2>invoice address</h2>
16+
<label>street <input name="invoiceAddress[street]"/></label><br>
17+
<label>zip <input name="invoiceAddress[zip]"/></label><br>
18+
<label>city <input name="invoiceAddress[city]"/></label><br>
19+
<h2>delivery address (optional)</h2>
20+
<label>street <input name="deliveryAddress[street]"/></label><br>
21+
<label>zip <input name="deliveryAddress[zip]"/></label><br>
22+
<label>city <input name="deliveryAddress[city]"/></label><br>
1823
<button type="submit">submit</button>
1924
</form>
2025
</body>
@@ -28,9 +33,15 @@
2833
<head><title>commit hygiene example</title></head>
2934
<body>
3035
<h1><?= htmlspecialchars($user->getFirstName() . ' ' . $user->getLastName(), ENT_HTML5) ?></h1>
36+
<h2>invoice address</h2>
3137
<p>
32-
<?= htmlspecialchars($user->getAddress()->getStreet(), ENT_HTML5) ?><br>
33-
<span style="font-size: larger"><?= htmlspecialchars($user->getAddress()->getZip(), ENT_HTML5) ?></span> <?= htmlspecialchars($user->getAddress()->getCity(), ENT_HTML5) ?>
38+
<?= htmlspecialchars($user->getInvoiceAddress()->getStreet(), ENT_HTML5) ?><br>
39+
<span style="font-size: larger"><?= htmlspecialchars($user->getInvoiceAddress()->getZip(), ENT_HTML5) ?></span> <?= htmlspecialchars($user->getInvoiceAddress()->getCity(), ENT_HTML5) ?>
40+
</p>
41+
<h2>delivery address</h2>
42+
<p>
43+
<?= htmlspecialchars($user->getDeliveryAddress()->getStreet(), ENT_HTML5) ?><br>
44+
<span style="font-size: larger"><?= htmlspecialchars($user->getDeliveryAddress()->getZip(), ENT_HTML5) ?></span> <?= htmlspecialchars($user->getDeliveryAddress()->getCity(), ENT_HTML5) ?>
3445
</p>
3546
</body>
3647
</html>

0 commit comments

Comments
 (0)