-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuilders.php
More file actions
74 lines (63 loc) · 2.71 KB
/
Copy pathBuilders.php
File metadata and controls
74 lines (63 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
require_once 'Products.php';
interface Builder {
public function reset(): void;
public function setType(string $type): void;
public function setSeats(int $seats): void;
public function setEngine(string $engine): void;
public function setTripComputer(bool $hasTripComputer): void;
public function setGPS(bool $hasGPS): void;
}
class CarBuilder implements Builder {
private Car $car;
public function __construct() {
$this->reset();
}
public function reset(): void {
$this->car = new Car();
}
public function setType(string $type): void { $this->car->type = $type; }
public function setSeats(int $seats): void { $this->car->seats = $seats; }
public function setEngine(string $engine): void { $this->car->engine = $engine; }
public function setTripComputer(bool $hasTripComputer): void { $this->car->hasTripComputer = $hasTripComputer; }
public function setGPS(bool $hasGPS): void { $this->car->hasGPS = $hasGPS; }
public function getResult(): Car {
$product = $this->car;
$this->reset();
return $product;
}
}
class CarManualBuilder implements Builder {
private Manual $manual;
public function __construct() {
$this->reset();
}
public function reset(): void {
$this->manual = new Manual();
}
public function setType(string $type): void {
$this->manual->type = $type . " Manual";
$this->manual->content .= "Посібник користувача для моделі: {$type}.\n";
}
public function setSeats(int $seats): void {
$this->manual->content .= "Інструкція з безпеки: Даний автомобіль розрахований на {$seats} місць. Пристебніть ремені.\n";
}
public function setEngine(string $engine): void {
$this->manual->content .= "Технічне обслуговування двигуна: Конфігурація двигуна — {$engine}. Перевіряйте рівень мастила кожні 10 000 км.\n";
}
public function setTripComputer(bool $hasTripComputer): void {
if ($hasTripComputer) {
$this->manual->content .= "Бортовий комп'ютер: Для активації головного меню натисніть кнопку 'Menu' на кермі.\n";
}
}
public function setGPS(bool $hasGPS): void {
if ($hasGPS) {
$this->manual->content .= "Навігація: Перед початком руху оновіть карти через Wi-Fi.\n";
}
}
public function getResult(): Manual {
$product = $this->manual;
$this->reset();
return $product;
}
}