forked from DesignPatternsPHP/DesignPatternsPHP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TruckBuilder.php
44 lines (36 loc) · 1.05 KB
/
TruckBuilder.php
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
<?php
namespace DesignPatterns\Creational\Builder;
use DesignPatterns\Creational\Builder\Parts\Vehicle;
class TruckBuilder implements BuilderInterface
{
/**
* @var Parts\Truck
*/
private $truck;
public function addDoors()
{
$this->truck->setPart('rightDoor', new Parts\Door());
$this->truck->setPart('leftDoor', new Parts\Door());
}
public function addEngine()
{
$this->truck->setPart('truckEngine', new Parts\Engine());
}
public function addWheel()
{
$this->truck->setPart('wheel1', new Parts\Wheel());
$this->truck->setPart('wheel2', new Parts\Wheel());
$this->truck->setPart('wheel3', new Parts\Wheel());
$this->truck->setPart('wheel4', new Parts\Wheel());
$this->truck->setPart('wheel5', new Parts\Wheel());
$this->truck->setPart('wheel6', new Parts\Wheel());
}
public function createVehicle()
{
$this->truck = new Parts\Truck();
}
public function getVehicle(): Vehicle
{
return $this->truck;
}
}