diff --git a/Builder/BikeBuilder.php b/Builder/BikeBuilder.php new file mode 100644 index 0000000..bb63fdf --- /dev/null +++ b/Builder/BikeBuilder.php @@ -0,0 +1,43 @@ +bike->setPart('engine', new Parts\Engine()); + } + + public function addWheel() + { + $this->bike->setPart('forwardWheel', new Parts\Wheel()); + $this->bike->setPart('rearWheel', new Parts\Wheel()); + } + + public function createVehicle() + { + $this->bike = new Parts\Bike(); + } + + public function getVehicle() + { + return $this->bike; + } + +} \ No newline at end of file diff --git a/Builder/Builder.php b/Builder/Builder.php new file mode 100644 index 0000000..a696936 --- /dev/null +++ b/Builder/Builder.php @@ -0,0 +1,33 @@ +car->setPart('rightdoor', new Parts\Door()); + $this->car->setPart('leftDoor', new Parts\Door()); + } + + public function addEngine() + { + $this->car->setPart('engine', new Parts\Engine()); + } + + public function addWheel() + { + $this->car->setPart('wheelLF', new Parts\Wheel()); + $this->car->setPart('wheelRF', new Parts\Wheel()); + $this->car->setPart('wheelLR', new Parts\Wheel()); + $this->car->setPart('wheelRR', new Parts\Wheel()); + } + + public function createVehicle() + { + $this->car = new Parts\Car(); + } + + public function getVehicle() + { + return $this->car; + } + +} \ No newline at end of file diff --git a/Builder/Director.php b/Builder/Director.php new file mode 100644 index 0000000..7a55a0d --- /dev/null +++ b/Builder/Director.php @@ -0,0 +1,32 @@ +createVehicle(); + $builder->addDoors(); + $builder->addEngine(); + $builder->addWheel(); + + return $builder->getVehicle(); + } + +} \ No newline at end of file diff --git a/Builder/Parts/Bike.php b/Builder/Parts/Bike.php new file mode 100644 index 0000000..b10ad1f --- /dev/null +++ b/Builder/Parts/Bike.php @@ -0,0 +1,15 @@ +data[$key] = $value; + } + +} \ No newline at end of file diff --git a/Builder/Parts/Wheel.php b/Builder/Parts/Wheel.php new file mode 100644 index 0000000..d2b8950 --- /dev/null +++ b/Builder/Parts/Wheel.php @@ -0,0 +1,8 @@ +director = new Director(); + } + + public function getBuilder() + { + return array( + array(new CarBuilder()), + array(new BikeBuilder()) + ); + } + + /** + * Here we test the build process. Notice that the client don't know + * anything about the contrete builder. + * + * @dataProvider getBuilder + */ + public function testBuild(\DesignPatterns\Builder\Builder $builder) + { + $newVehicle = $this->director->build($builder); + $this->assertInstanceOf('DesignPatterns\Builder\Parts\Vehicle', $newVehicle); + } + +} \ No newline at end of file