From 10fc66b5fa00488e3965ddd1dd4793f2555aa814 Mon Sep 17 00:00:00 2001 From: Bert Van de Casteele Date: Sat, 25 Feb 2017 17:54:46 +0100 Subject: [PATCH 01/28] Added SimpleFactory example --- .gitignore | 5 ++++ .../php/creational/SimpleFactory.php | 9 +++++++ .../php/creational/autoload.php | 7 ++++++ .../php/creational/src/SimpleFactory/Door.php | 10 ++++++++ .../src/SimpleFactory/DoorFactory.php | 12 ++++++++++ .../src/SimpleFactory/WoodenDoor.php | 24 +++++++++++++++++++ 6 files changed, 67 insertions(+) create mode 100644 .gitignore create mode 100644 examples-per-language/php/creational/SimpleFactory.php create mode 100644 examples-per-language/php/creational/autoload.php create mode 100644 examples-per-language/php/creational/src/SimpleFactory/Door.php create mode 100644 examples-per-language/php/creational/src/SimpleFactory/DoorFactory.php create mode 100644 examples-per-language/php/creational/src/SimpleFactory/WoodenDoor.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..b38118ad --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +# IntelliJ project files +.idea +*.iml +out +gen diff --git a/examples-per-language/php/creational/SimpleFactory.php b/examples-per-language/php/creational/SimpleFactory.php new file mode 100644 index 00000000..882f0009 --- /dev/null +++ b/examples-per-language/php/creational/SimpleFactory.php @@ -0,0 +1,9 @@ +getWidth() . PHP_EOL; +echo 'Height: ' . $door->getHeight() . PHP_EOL; \ No newline at end of file diff --git a/examples-per-language/php/creational/autoload.php b/examples-per-language/php/creational/autoload.php new file mode 100644 index 00000000..580cf4ba --- /dev/null +++ b/examples-per-language/php/creational/autoload.php @@ -0,0 +1,7 @@ +width = $width; + $this->height = $height; + } + + public function getWidth() { + return $this->width; + } + + public function getHeight() { + return $this->height; + } +} \ No newline at end of file From 369e83a898d0f46c92036a9e2f55fbea5fefe504 Mon Sep 17 00:00:00 2001 From: Bert Van de Casteele Date: Sat, 25 Feb 2017 18:17:21 +0100 Subject: [PATCH 02/28] Added FactoryMethod example --- .../php/creational/FactoryMethod.php | 12 ++++++++++++ .../src/FactoryMethod/CommunityExecutive.php | 11 +++++++++++ .../creational/src/FactoryMethod/Developer.php | 11 +++++++++++ .../src/FactoryMethod/DevelopmentManager.php | 11 +++++++++++ .../src/FactoryMethod/HiringManager.php | 17 +++++++++++++++++ .../src/FactoryMethod/Interviewer.php | 8 ++++++++ .../src/FactoryMethod/MarketingManager.php | 11 +++++++++++ 7 files changed, 81 insertions(+) create mode 100644 examples-per-language/php/creational/FactoryMethod.php create mode 100644 examples-per-language/php/creational/src/FactoryMethod/CommunityExecutive.php create mode 100644 examples-per-language/php/creational/src/FactoryMethod/Developer.php create mode 100644 examples-per-language/php/creational/src/FactoryMethod/DevelopmentManager.php create mode 100644 examples-per-language/php/creational/src/FactoryMethod/HiringManager.php create mode 100644 examples-per-language/php/creational/src/FactoryMethod/Interviewer.php create mode 100644 examples-per-language/php/creational/src/FactoryMethod/MarketingManager.php diff --git a/examples-per-language/php/creational/FactoryMethod.php b/examples-per-language/php/creational/FactoryMethod.php new file mode 100644 index 00000000..0fb030fa --- /dev/null +++ b/examples-per-language/php/creational/FactoryMethod.php @@ -0,0 +1,12 @@ +takeInterview(); + +$marketingManager = new MarketingManager(); +$marketingManager->takeInterview(); \ No newline at end of file diff --git a/examples-per-language/php/creational/src/FactoryMethod/CommunityExecutive.php b/examples-per-language/php/creational/src/FactoryMethod/CommunityExecutive.php new file mode 100644 index 00000000..836f1d3f --- /dev/null +++ b/examples-per-language/php/creational/src/FactoryMethod/CommunityExecutive.php @@ -0,0 +1,11 @@ +makeInterviewer(); + $interviewer->askQuestions(); + } +} \ No newline at end of file diff --git a/examples-per-language/php/creational/src/FactoryMethod/Interviewer.php b/examples-per-language/php/creational/src/FactoryMethod/Interviewer.php new file mode 100644 index 00000000..6e6e550b --- /dev/null +++ b/examples-per-language/php/creational/src/FactoryMethod/Interviewer.php @@ -0,0 +1,8 @@ + Date: Sat, 25 Feb 2017 18:34:22 +0100 Subject: [PATCH 03/28] Added Abstract Factory example --- .../php/creational/AbstractFactoryMethod.php | 23 +++++++++++++++++++ .../src/AbstractFactory/Carpenter.php | 11 +++++++++ .../creational/src/AbstractFactory/Door.php | 9 ++++++++ .../src/AbstractFactory/DoorFactory.php | 10 ++++++++ .../src/AbstractFactory/DoorFittingExpert.php | 8 +++++++ .../src/AbstractFactory/IronDoor.php | 11 +++++++++ .../src/AbstractFactory/IronDoorFactory.php | 15 ++++++++++++ .../creational/src/AbstractFactory/Welder.php | 11 +++++++++ .../src/AbstractFactory/WoodenDoor.php | 11 +++++++++ .../src/AbstractFactory/WoodenDoorFactory.php | 15 ++++++++++++ 10 files changed, 124 insertions(+) create mode 100644 examples-per-language/php/creational/AbstractFactoryMethod.php create mode 100644 examples-per-language/php/creational/src/AbstractFactory/Carpenter.php create mode 100644 examples-per-language/php/creational/src/AbstractFactory/Door.php create mode 100644 examples-per-language/php/creational/src/AbstractFactory/DoorFactory.php create mode 100644 examples-per-language/php/creational/src/AbstractFactory/DoorFittingExpert.php create mode 100644 examples-per-language/php/creational/src/AbstractFactory/IronDoor.php create mode 100644 examples-per-language/php/creational/src/AbstractFactory/IronDoorFactory.php create mode 100644 examples-per-language/php/creational/src/AbstractFactory/Welder.php create mode 100644 examples-per-language/php/creational/src/AbstractFactory/WoodenDoor.php create mode 100644 examples-per-language/php/creational/src/AbstractFactory/WoodenDoorFactory.php diff --git a/examples-per-language/php/creational/AbstractFactoryMethod.php b/examples-per-language/php/creational/AbstractFactoryMethod.php new file mode 100644 index 00000000..46fe3f99 --- /dev/null +++ b/examples-per-language/php/creational/AbstractFactoryMethod.php @@ -0,0 +1,23 @@ +makeDoor(); +$expert = $woodenDoorFactory->makeFittingExpert(); + +$door->getDescription(); +$expert->getDescription(); + +$ironFactory = new IronDoorFactory(); + +$door = $ironFactory->makeDoor(); +$expert = $ironFactory->makeFittingExpert(); + +$door->getDescription(); +$expert->getDescription(); + diff --git a/examples-per-language/php/creational/src/AbstractFactory/Carpenter.php b/examples-per-language/php/creational/src/AbstractFactory/Carpenter.php new file mode 100644 index 00000000..a1c176a9 --- /dev/null +++ b/examples-per-language/php/creational/src/AbstractFactory/Carpenter.php @@ -0,0 +1,11 @@ + Date: Sat, 25 Feb 2017 20:28:54 +0100 Subject: [PATCH 04/28] Added Builder example --- .../php/creational/Builder.php | 13 ++++++ .../php/creational/src/Builder/Burger.php | 21 +++++++++ .../creational/src/Builder/BurgerBuilder.php | 43 +++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 examples-per-language/php/creational/Builder.php create mode 100644 examples-per-language/php/creational/src/Builder/Burger.php create mode 100644 examples-per-language/php/creational/src/Builder/BurgerBuilder.php diff --git a/examples-per-language/php/creational/Builder.php b/examples-per-language/php/creational/Builder.php new file mode 100644 index 00000000..c432fef8 --- /dev/null +++ b/examples-per-language/php/creational/Builder.php @@ -0,0 +1,13 @@ +addPepperoni() + ->addLettuce() + ->addTomato() + ->build(); + +var_dump($burger); \ No newline at end of file diff --git a/examples-per-language/php/creational/src/Builder/Burger.php b/examples-per-language/php/creational/src/Builder/Burger.php new file mode 100644 index 00000000..54503579 --- /dev/null +++ b/examples-per-language/php/creational/src/Builder/Burger.php @@ -0,0 +1,21 @@ +size = $builder->size; + $this->cheese = $builder->cheese; + $this->pepperoni = $builder->pepperoni; + $this->lettuce = $builder->lettuce; + $this->tomato = $builder->tomato; + } +} \ No newline at end of file diff --git a/examples-per-language/php/creational/src/Builder/BurgerBuilder.php b/examples-per-language/php/creational/src/Builder/BurgerBuilder.php new file mode 100644 index 00000000..6ade7929 --- /dev/null +++ b/examples-per-language/php/creational/src/Builder/BurgerBuilder.php @@ -0,0 +1,43 @@ +size = $size; + } + + public function addCheese() { + $this->cheese = true; + return $this; + } + + public function addPepperoni() { + $this->pepperoni = true; + return $this; + } + + public function addLettuce() { + $this->lettuce = true; + return $this; + } + + public function addTomato() { + $this->tomato = true; + return $this; + } + + // Finishes the build process. + public function build() { + return new Burger($this); + } + +} \ No newline at end of file From 2c1f11306863dfdeb557d8d4a5fea0271adc534f Mon Sep 17 00:00:00 2001 From: Bert Van de Casteele Date: Sat, 25 Feb 2017 20:35:10 +0100 Subject: [PATCH 05/28] Added Prototype example --- .../php/creational/Prototype.php | 17 +++++++++ .../php/creational/src/Prototype/Sheep.php | 38 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 examples-per-language/php/creational/Prototype.php create mode 100644 examples-per-language/php/creational/src/Prototype/Sheep.php diff --git a/examples-per-language/php/creational/Prototype.php b/examples-per-language/php/creational/Prototype.php new file mode 100644 index 00000000..9332b36b --- /dev/null +++ b/examples-per-language/php/creational/Prototype.php @@ -0,0 +1,17 @@ +getName() . PHP_EOL; +echo $original->getCategory() . PHP_EOL; + +$cloned = clone $original; +$cloned->setName('Dolly'); +echo $cloned->getName() . PHP_EOL; +echo $cloned->getCategory() . PHP_EOL; + +echo 'Remember, you can use the magic method __clone to modify the behaviour of cloning the object!'; + diff --git a/examples-per-language/php/creational/src/Prototype/Sheep.php b/examples-per-language/php/creational/src/Prototype/Sheep.php new file mode 100644 index 00000000..74d92fb0 --- /dev/null +++ b/examples-per-language/php/creational/src/Prototype/Sheep.php @@ -0,0 +1,38 @@ +name = $name; + $this->category = $category; + } + + public function getName() { + return $this->name; + } + + /** + * @param string $name + */ + public function setName($name) { + $this->name = $name; + } + + /** + * @param string $category + */ + public function setCategory($category) { + $this->category = $category; + } + + public function getCategory() { + return $this->category; + } + +} \ No newline at end of file From e85ad075b3658198658805435c289981fe5ba94d Mon Sep 17 00:00:00 2001 From: Bert Van de Casteele Date: Sat, 25 Feb 2017 20:43:17 +0100 Subject: [PATCH 06/28] Added Singleton example --- .../php/creational/Singleton.php | 11 +++++++ .../creational/src/Singleton/President.php | 32 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 examples-per-language/php/creational/Singleton.php create mode 100644 examples-per-language/php/creational/src/Singleton/President.php diff --git a/examples-per-language/php/creational/Singleton.php b/examples-per-language/php/creational/Singleton.php new file mode 100644 index 00000000..432fe28c --- /dev/null +++ b/examples-per-language/php/creational/Singleton.php @@ -0,0 +1,11 @@ + Date: Sat, 25 Feb 2017 22:11:48 +0100 Subject: [PATCH 07/28] Added Adapter example --- .../php/structural/Adapter.php | 13 +++++++++++++ .../php/structural/autoload.php | 7 +++++++ .../php/structural/src/Adapter/AfricanLion.php | 10 ++++++++++ .../php/structural/src/Adapter/AsianLion.php | 10 ++++++++++ .../php/structural/src/Adapter/Hunter.php | 12 ++++++++++++ .../php/structural/src/Adapter/Lion.php | 8 ++++++++ .../php/structural/src/Adapter/WildDog.php | 12 ++++++++++++ .../structural/src/Adapter/WildDogAdapter.php | 17 +++++++++++++++++ 8 files changed, 89 insertions(+) create mode 100644 examples-per-language/php/structural/Adapter.php create mode 100644 examples-per-language/php/structural/autoload.php create mode 100644 examples-per-language/php/structural/src/Adapter/AfricanLion.php create mode 100644 examples-per-language/php/structural/src/Adapter/AsianLion.php create mode 100644 examples-per-language/php/structural/src/Adapter/Hunter.php create mode 100644 examples-per-language/php/structural/src/Adapter/Lion.php create mode 100644 examples-per-language/php/structural/src/Adapter/WildDog.php create mode 100644 examples-per-language/php/structural/src/Adapter/WildDogAdapter.php diff --git a/examples-per-language/php/structural/Adapter.php b/examples-per-language/php/structural/Adapter.php new file mode 100644 index 00000000..f7dfd65f --- /dev/null +++ b/examples-per-language/php/structural/Adapter.php @@ -0,0 +1,13 @@ +hunt($wildDogAdapter); \ No newline at end of file diff --git a/examples-per-language/php/structural/autoload.php b/examples-per-language/php/structural/autoload.php new file mode 100644 index 00000000..580cf4ba --- /dev/null +++ b/examples-per-language/php/structural/autoload.php @@ -0,0 +1,7 @@ +dog = $dog; + } + + public function roar() { + $this->dog->bark(); + } +} \ No newline at end of file From 6fa88a82a221dd2b8f7c3f17711c12adb58a4e4b Mon Sep 17 00:00:00 2001 From: Bert Van de Casteele Date: Sat, 25 Feb 2017 22:35:34 +0100 Subject: [PATCH 08/28] Added Bridge example --- examples-per-language/php/structural/Bridge.php | 15 +++++++++++++++ .../php/structural/src/Bridge/About.php | 16 ++++++++++++++++ .../php/structural/src/Bridge/AquaTheme.php | 11 +++++++++++ .../php/structural/src/Bridge/Careers.php | 16 ++++++++++++++++ .../php/structural/src/Bridge/DarkTheme.php | 11 +++++++++++ .../php/structural/src/Bridge/LightTheme.php | 11 +++++++++++ .../php/structural/src/Bridge/Theme.php | 9 +++++++++ .../php/structural/src/Bridge/WebPage.php | 11 +++++++++++ 8 files changed, 100 insertions(+) create mode 100644 examples-per-language/php/structural/Bridge.php create mode 100644 examples-per-language/php/structural/src/Bridge/About.php create mode 100644 examples-per-language/php/structural/src/Bridge/AquaTheme.php create mode 100644 examples-per-language/php/structural/src/Bridge/Careers.php create mode 100644 examples-per-language/php/structural/src/Bridge/DarkTheme.php create mode 100644 examples-per-language/php/structural/src/Bridge/LightTheme.php create mode 100644 examples-per-language/php/structural/src/Bridge/Theme.php create mode 100644 examples-per-language/php/structural/src/Bridge/WebPage.php diff --git a/examples-per-language/php/structural/Bridge.php b/examples-per-language/php/structural/Bridge.php new file mode 100644 index 00000000..7dfab062 --- /dev/null +++ b/examples-per-language/php/structural/Bridge.php @@ -0,0 +1,15 @@ +getContent() . PHP_EOL; +echo $careers->getContent() . PHP_EOL; \ No newline at end of file diff --git a/examples-per-language/php/structural/src/Bridge/About.php b/examples-per-language/php/structural/src/Bridge/About.php new file mode 100644 index 00000000..58161b19 --- /dev/null +++ b/examples-per-language/php/structural/src/Bridge/About.php @@ -0,0 +1,16 @@ +theme = $theme; + } + + public function getContent() { + return 'About page in ' . $this->theme->getColor(); + } +} \ No newline at end of file diff --git a/examples-per-language/php/structural/src/Bridge/AquaTheme.php b/examples-per-language/php/structural/src/Bridge/AquaTheme.php new file mode 100644 index 00000000..612247aa --- /dev/null +++ b/examples-per-language/php/structural/src/Bridge/AquaTheme.php @@ -0,0 +1,11 @@ +theme = $theme; + } + + public function getContent() { + return 'Careers page in ' . $this->theme->getColor(); + } +} \ No newline at end of file diff --git a/examples-per-language/php/structural/src/Bridge/DarkTheme.php b/examples-per-language/php/structural/src/Bridge/DarkTheme.php new file mode 100644 index 00000000..3d991d02 --- /dev/null +++ b/examples-per-language/php/structural/src/Bridge/DarkTheme.php @@ -0,0 +1,11 @@ + Date: Sat, 25 Feb 2017 22:57:49 +0100 Subject: [PATCH 09/28] Added Composite example --- .../php/structural/Composite.php | 17 ++++++++++ .../php/structural/src/Composite/Designer.php | 28 +++++++++++++++++ .../structural/src/Composite/Developer.php | 31 +++++++++++++++++++ .../php/structural/src/Composite/Employee.php | 13 ++++++++ .../structural/src/Composite/Organization.php | 25 +++++++++++++++ 5 files changed, 114 insertions(+) create mode 100644 examples-per-language/php/structural/Composite.php create mode 100644 examples-per-language/php/structural/src/Composite/Designer.php create mode 100644 examples-per-language/php/structural/src/Composite/Developer.php create mode 100644 examples-per-language/php/structural/src/Composite/Employee.php create mode 100644 examples-per-language/php/structural/src/Composite/Organization.php diff --git a/examples-per-language/php/structural/Composite.php b/examples-per-language/php/structural/Composite.php new file mode 100644 index 00000000..83574948 --- /dev/null +++ b/examples-per-language/php/structural/Composite.php @@ -0,0 +1,17 @@ +addEmployee($john); +$organization->addEmployee($jane); + +echo 'Net salaries ' . $organization->getNetSalaries() . PHP_EOL; \ No newline at end of file diff --git a/examples-per-language/php/structural/src/Composite/Designer.php b/examples-per-language/php/structural/src/Composite/Designer.php new file mode 100644 index 00000000..47a6bdf1 --- /dev/null +++ b/examples-per-language/php/structural/src/Composite/Designer.php @@ -0,0 +1,28 @@ +name = $name; + $this->salary = $salary; + } + + public function getName() { + return $this->name; + } + + public function setSalary($salary) { + $this->salary = $salary; + } + + public function getSalary() { + return $this->salary; + } + + public function getRoles() { + return $this->roles; + } +} \ No newline at end of file diff --git a/examples-per-language/php/structural/src/Composite/Developer.php b/examples-per-language/php/structural/src/Composite/Developer.php new file mode 100644 index 00000000..b2c69aa8 --- /dev/null +++ b/examples-per-language/php/structural/src/Composite/Developer.php @@ -0,0 +1,31 @@ +name = $name; + $this->salary = $salary; + } + + public function getName() { + return $this->name; + } + + public function setSalary($salary) { + $this->salary = $salary; + } + + public function getSalary() { + return $this->salary; + } + + public function getRoles() { + return $this->roles; + } +} \ No newline at end of file diff --git a/examples-per-language/php/structural/src/Composite/Employee.php b/examples-per-language/php/structural/src/Composite/Employee.php new file mode 100644 index 00000000..177e8cfe --- /dev/null +++ b/examples-per-language/php/structural/src/Composite/Employee.php @@ -0,0 +1,13 @@ +employees[] = $employee; + } + + public function getNetSalaries() { + $netSalary = 0; + + /** @var Employee $employee */ + foreach ($this->employees as $employee) { + $netSalary += $employee->getSalary(); + } + + return $netSalary; + } + +} \ No newline at end of file From 316fcd2a27dd8196e0e692b91d6f1fa5c8a6e317 Mon Sep 17 00:00:00 2001 From: Bert Van de Casteele Date: Sun, 26 Feb 2017 16:36:57 +0100 Subject: [PATCH 10/28] Added Decorator example --- .../php/structural/Decorator.php | 24 +++++++++++++++++++ .../php/structural/src/Decorator/Coffee.php | 11 +++++++++ .../structural/src/Decorator/MilkCoffee.php | 22 +++++++++++++++++ .../structural/src/Decorator/SimpleCoffee.php | 15 ++++++++++++ .../src/Decorator/VanillaCoffee.php | 22 +++++++++++++++++ .../structural/src/Decorator/WhipCoffee.php | 22 +++++++++++++++++ 6 files changed, 116 insertions(+) create mode 100644 examples-per-language/php/structural/Decorator.php create mode 100644 examples-per-language/php/structural/src/Decorator/Coffee.php create mode 100644 examples-per-language/php/structural/src/Decorator/MilkCoffee.php create mode 100644 examples-per-language/php/structural/src/Decorator/SimpleCoffee.php create mode 100644 examples-per-language/php/structural/src/Decorator/VanillaCoffee.php create mode 100644 examples-per-language/php/structural/src/Decorator/WhipCoffee.php diff --git a/examples-per-language/php/structural/Decorator.php b/examples-per-language/php/structural/Decorator.php new file mode 100644 index 00000000..18dda301 --- /dev/null +++ b/examples-per-language/php/structural/Decorator.php @@ -0,0 +1,24 @@ +getCost() . PHP_EOL; +echo $someCoffee->getDescription() . PHP_EOL; + +$someCoffee = new MilkCoffee($someCoffee); +echo $someCoffee->getCost() . PHP_EOL; +echo $someCoffee->getDescription() . PHP_EOL; + +$someCoffee = new WhipCoffee($someCoffee); +echo $someCoffee->getCost() . PHP_EOL; +echo $someCoffee->getDescription() . PHP_EOL; + +$someCoffee = new VanillaCoffee($someCoffee); +echo $someCoffee->getCost() . PHP_EOL; +echo $someCoffee->getDescription() . PHP_EOL; \ No newline at end of file diff --git a/examples-per-language/php/structural/src/Decorator/Coffee.php b/examples-per-language/php/structural/src/Decorator/Coffee.php new file mode 100644 index 00000000..e7c02461 --- /dev/null +++ b/examples-per-language/php/structural/src/Decorator/Coffee.php @@ -0,0 +1,11 @@ +coffee = $coffee; + } + + public function getCost() { + return $this->coffee->getCost() + 2; + } + + public function getDescription() { + return $this->coffee->getDescription() . ', milk'; + } +} \ No newline at end of file diff --git a/examples-per-language/php/structural/src/Decorator/SimpleCoffee.php b/examples-per-language/php/structural/src/Decorator/SimpleCoffee.php new file mode 100644 index 00000000..153e115b --- /dev/null +++ b/examples-per-language/php/structural/src/Decorator/SimpleCoffee.php @@ -0,0 +1,15 @@ +coffee = $coffee; + } + + public function getCost() { + return $this->coffee->getCost() + 3; + } + + public function getDescription() { + return $this->coffee->getDescription() . ', vanilla'; + } +} \ No newline at end of file diff --git a/examples-per-language/php/structural/src/Decorator/WhipCoffee.php b/examples-per-language/php/structural/src/Decorator/WhipCoffee.php new file mode 100644 index 00000000..a50989fd --- /dev/null +++ b/examples-per-language/php/structural/src/Decorator/WhipCoffee.php @@ -0,0 +1,22 @@ +coffee = $coffee; + } + + public function getCost() { + return $this->coffee->getCost() + 5; + } + + public function getDescription() { + return $this->coffee->getDescription() . ', whip'; + } +} \ No newline at end of file From 444b2f55d95249f7b601a3dd87ffcce02de750f2 Mon Sep 17 00:00:00 2001 From: Bert Van de Casteele Date: Sun, 26 Feb 2017 17:06:24 +0100 Subject: [PATCH 11/28] Added Facade example --- .../php/structural/Facade.php | 11 ++++++ .../php/structural/src/Facade/Computer.php | 36 +++++++++++++++++++ .../structural/src/Facade/ComputerFacade.php | 28 +++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 examples-per-language/php/structural/Facade.php create mode 100644 examples-per-language/php/structural/src/Facade/Computer.php create mode 100644 examples-per-language/php/structural/src/Facade/ComputerFacade.php diff --git a/examples-per-language/php/structural/Facade.php b/examples-per-language/php/structural/Facade.php new file mode 100644 index 00000000..e3d3c5d3 --- /dev/null +++ b/examples-per-language/php/structural/Facade.php @@ -0,0 +1,11 @@ +turnOn(); +$computer->turnOff(); \ No newline at end of file diff --git a/examples-per-language/php/structural/src/Facade/Computer.php b/examples-per-language/php/structural/src/Facade/Computer.php new file mode 100644 index 00000000..8106555c --- /dev/null +++ b/examples-per-language/php/structural/src/Facade/Computer.php @@ -0,0 +1,36 @@ +computer = $computer; + } + + public function turnOn() { + $this->computer->getElectricShock(); + $this->computer->makeSound(); + $this->computer->showLoadingScreen(); + $this->computer->bam(); + } + + public function turnOff() { + $this->computer->closeEverything(); + $this->computer->pullCurrent(); + $this->computer->sooth(); + } + + +} \ No newline at end of file From 404217e57d93b17fd8bdb5c71885886a5b1f84ca Mon Sep 17 00:00:00 2001 From: Bert Van de Casteele Date: Sun, 26 Feb 2017 17:25:48 +0100 Subject: [PATCH 12/28] Added Flyweight example, added own implementation to demonstrate the concept more clearly. --- .../php/structural/Flyweight.php | 17 +++++++++++ .../php/structural/src/Flyweight/KarakTea.php | 9 ++++++ .../php/structural/src/Flyweight/TeaMaker.php | 21 +++++++++++++ .../php/structural/src/Flyweight/TeaShop.php | 30 +++++++++++++++++++ 4 files changed, 77 insertions(+) create mode 100644 examples-per-language/php/structural/Flyweight.php create mode 100644 examples-per-language/php/structural/src/Flyweight/KarakTea.php create mode 100644 examples-per-language/php/structural/src/Flyweight/TeaMaker.php create mode 100644 examples-per-language/php/structural/src/Flyweight/TeaShop.php diff --git a/examples-per-language/php/structural/Flyweight.php b/examples-per-language/php/structural/Flyweight.php new file mode 100644 index 00000000..5ce010ce --- /dev/null +++ b/examples-per-language/php/structural/Flyweight.php @@ -0,0 +1,17 @@ +takeOrder('less sugar', 1); +$shop->takeOrder('more milk', 2); +$shop->takeOrder('without sugar', 5); +$shop->takeOrder('without sugar', 3); +$shop->takeOrder('less sugar', 3); + +$shop->serve(); \ No newline at end of file diff --git a/examples-per-language/php/structural/src/Flyweight/KarakTea.php b/examples-per-language/php/structural/src/Flyweight/KarakTea.php new file mode 100644 index 00000000..ea6c17b1 --- /dev/null +++ b/examples-per-language/php/structural/src/Flyweight/KarakTea.php @@ -0,0 +1,9 @@ +availableTea[$preference])) { + $this->availableTea[$preference] = new KarakTea(); + echo 'The tea ' . $preference . ' was not available and was freshly made' . PHP_EOL; + } else { + echo 'The tea ' . $preference . ' was already made, so we served that' . PHP_EOL; + } + + return $this->availableTea[$preference]; + } + +} \ No newline at end of file diff --git a/examples-per-language/php/structural/src/Flyweight/TeaShop.php b/examples-per-language/php/structural/src/Flyweight/TeaShop.php new file mode 100644 index 00000000..dfbeda2f --- /dev/null +++ b/examples-per-language/php/structural/src/Flyweight/TeaShop.php @@ -0,0 +1,30 @@ +teaMaker = $teaMaker; + } + + /** + * @param string $teaType + * @param int $table + */ + public function takeOrder($teaType, $table) { + $this->orders[$table] = $this->teaMaker->make($teaType); + } + + public function serve() { + foreach ($this->orders as $table => $order) { + echo "Serving tea to table # " . $table . PHP_EOL; + } + } + + +} \ No newline at end of file From 7ed5d2d27ff71d7db202d257640ac9e0caa1e0ed Mon Sep 17 00:00:00 2001 From: Bert Van de Casteele Date: Sun, 26 Feb 2017 17:35:23 +0100 Subject: [PATCH 13/28] Added Proxy example, with one small addition --- .../php/structural/Proxy.php | 12 +++++++ .../php/structural/src/Proxy/Door.php | 11 ++++++ .../php/structural/src/Proxy/LabDoor.php | 15 ++++++++ .../php/structural/src/Proxy/Security.php | 34 +++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 examples-per-language/php/structural/Proxy.php create mode 100644 examples-per-language/php/structural/src/Proxy/Door.php create mode 100644 examples-per-language/php/structural/src/Proxy/LabDoor.php create mode 100644 examples-per-language/php/structural/src/Proxy/Security.php diff --git a/examples-per-language/php/structural/Proxy.php b/examples-per-language/php/structural/Proxy.php new file mode 100644 index 00000000..4d756157 --- /dev/null +++ b/examples-per-language/php/structural/Proxy.php @@ -0,0 +1,12 @@ +open('invalid'); + +$door->open('$ecr@t'); +$door->close(); \ No newline at end of file diff --git a/examples-per-language/php/structural/src/Proxy/Door.php b/examples-per-language/php/structural/src/Proxy/Door.php new file mode 100644 index 00000000..01995e30 --- /dev/null +++ b/examples-per-language/php/structural/src/Proxy/Door.php @@ -0,0 +1,11 @@ +door = $door; + } + + public function open($password) { + if ($this->authenticate($password)) { + $this->door->open(); + echo 'Access granted!' . PHP_EOL; + } else { + echo "Big no! It ain't possible!" . PHP_EOL; + } + } + + // In the code examples this is public, but there is no real reason + // why this method should be available to anything except this class. + private function authenticate($password) { + return $password === '$ecr@t'; + } + + public function close() { + $this->door->close(); + } + + +} \ No newline at end of file From ca96959f0743ba48dccdd701e94883a349e78ff9 Mon Sep 17 00:00:00 2001 From: Bert Van de Casteele Date: Sun, 26 Feb 2017 17:42:15 +0100 Subject: [PATCH 14/28] Small syntax changes + PSR-2 compliance --- .../src/AbstractFactory/Carpenter.php | 10 ++- .../creational/src/AbstractFactory/Door.php | 5 +- .../src/AbstractFactory/DoorFactory.php | 8 +- .../src/AbstractFactory/DoorFittingExpert.php | 5 +- .../src/AbstractFactory/IronDoor.php | 10 ++- .../src/AbstractFactory/IronDoorFactory.php | 17 ++-- .../creational/src/AbstractFactory/Welder.php | 10 ++- .../src/AbstractFactory/WoodenDoor.php | 10 ++- .../src/AbstractFactory/WoodenDoorFactory.php | 17 ++-- .../php/creational/src/Builder/Burger.php | 28 ++++--- .../creational/src/Builder/BurgerBuilder.php | 79 ++++++++++--------- .../src/FactoryMethod/CommunityExecutive.php | 10 ++- .../src/FactoryMethod/Developer.php | 10 ++- .../src/FactoryMethod/DevelopmentManager.php | 10 ++- .../src/FactoryMethod/HiringManager.php | 18 +++-- .../src/FactoryMethod/Interviewer.php | 5 +- .../src/FactoryMethod/MarketingManager.php | 10 ++- .../php/creational/src/Prototype/Sheep.php | 68 ++++++++-------- .../php/creational/src/SimpleFactory/Door.php | 8 +- .../src/SimpleFactory/DoorFactory.php | 10 ++- .../src/SimpleFactory/WoodenDoor.php | 30 ++++--- .../creational/src/Singleton/President.php | 43 +++++----- .../php/structural/autoload.php | 9 ++- .../structural/src/Adapter/AfricanLion.php | 8 +- .../php/structural/src/Adapter/AsianLion.php | 8 +- .../php/structural/src/Adapter/Hunter.php | 10 ++- .../php/structural/src/Adapter/Lion.php | 5 +- .../php/structural/src/Adapter/WildDog.php | 10 ++- .../structural/src/Adapter/WildDogAdapter.php | 19 +++-- .../php/structural/src/Bridge/About.php | 19 +++-- .../php/structural/src/Bridge/AquaTheme.php | 10 ++- .../php/structural/src/Bridge/Careers.php | 19 +++-- .../php/structural/src/Bridge/DarkTheme.php | 10 ++- .../php/structural/src/Bridge/LightTheme.php | 10 ++- .../php/structural/src/Bridge/Theme.php | 5 +- .../php/structural/src/Bridge/WebPage.php | 8 +- .../php/structural/src/Composite/Designer.php | 50 ++++++------ .../structural/src/Composite/Developer.php | 56 +++++++------ .../php/structural/src/Composite/Employee.php | 17 ++-- .../structural/src/Composite/Organization.php | 29 ++++--- .../php/structural/src/Decorator/Coffee.php | 8 +- .../structural/src/Decorator/MilkCoffee.php | 28 ++++--- .../structural/src/Decorator/SimpleCoffee.php | 17 ++-- .../src/Decorator/VanillaCoffee.php | 28 ++++--- .../structural/src/Decorator/WhipCoffee.php | 28 ++++--- .../php/structural/src/Facade/Computer.php | 66 +++++++++------- .../structural/src/Facade/ComputerFacade.php | 44 ++++++----- .../php/structural/src/Flyweight/KarakTea.php | 3 +- .../php/structural/src/Flyweight/TeaMaker.php | 24 +++--- .../php/structural/src/Flyweight/TeaShop.php | 46 ++++++----- .../php/structural/src/Proxy/Door.php | 8 +- .../php/structural/src/Proxy/LabDoor.php | 17 ++-- .../php/structural/src/Proxy/Security.php | 45 ++++++----- 53 files changed, 618 insertions(+), 467 deletions(-) diff --git a/examples-per-language/php/creational/src/AbstractFactory/Carpenter.php b/examples-per-language/php/creational/src/AbstractFactory/Carpenter.php index a1c176a9..921ce779 100644 --- a/examples-per-language/php/creational/src/AbstractFactory/Carpenter.php +++ b/examples-per-language/php/creational/src/AbstractFactory/Carpenter.php @@ -3,9 +3,11 @@ namespace designPatternsForHumans\creational\AbstractFactory; -class Carpenter implements DoorFittingExpert { +class Carpenter implements DoorFittingExpert +{ - public function getDescription() { - echo 'I can only fit wooden doors' . PHP_EOL; - } + public function getDescription() + { + echo 'I can only fit wooden doors' . PHP_EOL; + } } \ No newline at end of file diff --git a/examples-per-language/php/creational/src/AbstractFactory/Door.php b/examples-per-language/php/creational/src/AbstractFactory/Door.php index 27d87ed2..20818252 100644 --- a/examples-per-language/php/creational/src/AbstractFactory/Door.php +++ b/examples-per-language/php/creational/src/AbstractFactory/Door.php @@ -3,7 +3,8 @@ namespace designPatternsForHumans\creational\AbstractFactory; -interface Door { - public function getDescription(); +interface Door +{ + public function getDescription(); } \ No newline at end of file diff --git a/examples-per-language/php/creational/src/AbstractFactory/DoorFactory.php b/examples-per-language/php/creational/src/AbstractFactory/DoorFactory.php index 262d2983..cabd864a 100644 --- a/examples-per-language/php/creational/src/AbstractFactory/DoorFactory.php +++ b/examples-per-language/php/creational/src/AbstractFactory/DoorFactory.php @@ -3,8 +3,10 @@ namespace designPatternsForHumans\creational\AbstractFactory; -interface DoorFactory { - public function makeDoor(); - public function makeFittingExpert(); +interface DoorFactory +{ + public function makeDoor(); + + public function makeFittingExpert(); } \ No newline at end of file diff --git a/examples-per-language/php/creational/src/AbstractFactory/DoorFittingExpert.php b/examples-per-language/php/creational/src/AbstractFactory/DoorFittingExpert.php index b770c6b1..ec0cd085 100644 --- a/examples-per-language/php/creational/src/AbstractFactory/DoorFittingExpert.php +++ b/examples-per-language/php/creational/src/AbstractFactory/DoorFittingExpert.php @@ -3,6 +3,7 @@ namespace designPatternsForHumans\creational\AbstractFactory; -interface DoorFittingExpert { - public function getDescription(); +interface DoorFittingExpert +{ + public function getDescription(); } \ No newline at end of file diff --git a/examples-per-language/php/creational/src/AbstractFactory/IronDoor.php b/examples-per-language/php/creational/src/AbstractFactory/IronDoor.php index 4a79b45e..e857f86e 100644 --- a/examples-per-language/php/creational/src/AbstractFactory/IronDoor.php +++ b/examples-per-language/php/creational/src/AbstractFactory/IronDoor.php @@ -3,9 +3,11 @@ namespace designPatternsForHumans\creational\AbstractFactory; -class IronDoor implements Door { +class IronDoor implements Door +{ - public function getDescription() { - echo 'I am an Iron Door!' . PHP_EOL; - } + public function getDescription() + { + echo 'I am an Iron Door!' . PHP_EOL; + } } \ No newline at end of file diff --git a/examples-per-language/php/creational/src/AbstractFactory/IronDoorFactory.php b/examples-per-language/php/creational/src/AbstractFactory/IronDoorFactory.php index 41b4afb6..9bd25695 100644 --- a/examples-per-language/php/creational/src/AbstractFactory/IronDoorFactory.php +++ b/examples-per-language/php/creational/src/AbstractFactory/IronDoorFactory.php @@ -3,13 +3,16 @@ namespace designPatternsForHumans\creational\AbstractFactory; -class IronDoorFactory implements DoorFactory { +class IronDoorFactory implements DoorFactory +{ - public function makeDoor() { - return new IronDoor(); - } + public function makeDoor() + { + return new IronDoor(); + } - public function makeFittingExpert() { - return new Welder(); - } + public function makeFittingExpert() + { + return new Welder(); + } } \ No newline at end of file diff --git a/examples-per-language/php/creational/src/AbstractFactory/Welder.php b/examples-per-language/php/creational/src/AbstractFactory/Welder.php index b3dbf33d..344b6ec6 100644 --- a/examples-per-language/php/creational/src/AbstractFactory/Welder.php +++ b/examples-per-language/php/creational/src/AbstractFactory/Welder.php @@ -3,9 +3,11 @@ namespace designPatternsForHumans\creational\AbstractFactory; -class Welder implements DoorFittingExpert { +class Welder implements DoorFittingExpert +{ - public function getDescription() { - echo 'I can only fit iron doors' . PHP_EOL; - } + public function getDescription() + { + echo 'I can only fit iron doors' . PHP_EOL; + } } \ No newline at end of file diff --git a/examples-per-language/php/creational/src/AbstractFactory/WoodenDoor.php b/examples-per-language/php/creational/src/AbstractFactory/WoodenDoor.php index 161cfbf7..550c9365 100644 --- a/examples-per-language/php/creational/src/AbstractFactory/WoodenDoor.php +++ b/examples-per-language/php/creational/src/AbstractFactory/WoodenDoor.php @@ -3,9 +3,11 @@ namespace designPatternsForHumans\creational\AbstractFactory; -class WoodenDoor implements Door { +class WoodenDoor implements Door +{ - public function getDescription() { - echo 'I am a wooden door!' . PHP_EOL; - } + public function getDescription() + { + echo 'I am a wooden door!' . PHP_EOL; + } } \ No newline at end of file diff --git a/examples-per-language/php/creational/src/AbstractFactory/WoodenDoorFactory.php b/examples-per-language/php/creational/src/AbstractFactory/WoodenDoorFactory.php index dd449922..2bed7634 100644 --- a/examples-per-language/php/creational/src/AbstractFactory/WoodenDoorFactory.php +++ b/examples-per-language/php/creational/src/AbstractFactory/WoodenDoorFactory.php @@ -3,13 +3,16 @@ namespace designPatternsForHumans\creational\AbstractFactory; -class WoodenDoorFactory implements DoorFactory { +class WoodenDoorFactory implements DoorFactory +{ - public function makeDoor() { - return new WoodenDoor(); - } + public function makeDoor() + { + return new WoodenDoor(); + } - public function makeFittingExpert() { - return new Carpenter(); - } + public function makeFittingExpert() + { + return new Carpenter(); + } } \ No newline at end of file diff --git a/examples-per-language/php/creational/src/Builder/Burger.php b/examples-per-language/php/creational/src/Builder/Burger.php index 54503579..2c0fe70a 100644 --- a/examples-per-language/php/creational/src/Builder/Burger.php +++ b/examples-per-language/php/creational/src/Builder/Burger.php @@ -3,19 +3,21 @@ namespace designPatternsForHumans\creational\Builder; -class Burger { +class Burger +{ - protected $size; - protected $cheese = FALSE; - protected $pepperoni = FALSE; - protected $lettuce = FALSE; - protected $tomato = FALSE; + protected $size; + protected $cheese = false; + protected $pepperoni = false; + protected $lettuce = false; + protected $tomato = false; - public function __construct(BurgerBuilder $builder) { - $this->size = $builder->size; - $this->cheese = $builder->cheese; - $this->pepperoni = $builder->pepperoni; - $this->lettuce = $builder->lettuce; - $this->tomato = $builder->tomato; - } + public function __construct(BurgerBuilder $builder) + { + $this->size = $builder->size; + $this->cheese = $builder->cheese; + $this->pepperoni = $builder->pepperoni; + $this->lettuce = $builder->lettuce; + $this->tomato = $builder->tomato; + } } \ No newline at end of file diff --git a/examples-per-language/php/creational/src/Builder/BurgerBuilder.php b/examples-per-language/php/creational/src/Builder/BurgerBuilder.php index 6ade7929..7afabfbe 100644 --- a/examples-per-language/php/creational/src/Builder/BurgerBuilder.php +++ b/examples-per-language/php/creational/src/Builder/BurgerBuilder.php @@ -3,41 +3,48 @@ namespace designPatternsForHumans\creational\Builder; -class BurgerBuilder { - - public $size; - public $cheese = FALSE; - public $pepperoni = FALSE; - public $lettuce = FALSE; - public $tomato = FALSE; - - public function __construct($size) { - $this->size = $size; - } - - public function addCheese() { - $this->cheese = true; - return $this; - } - - public function addPepperoni() { - $this->pepperoni = true; - return $this; - } - - public function addLettuce() { - $this->lettuce = true; - return $this; - } - - public function addTomato() { - $this->tomato = true; - return $this; - } - - // Finishes the build process. - public function build() { - return new Burger($this); - } +class BurgerBuilder +{ + + public $size; + public $cheese = false; + public $pepperoni = false; + public $lettuce = false; + public $tomato = false; + + public function __construct($size) + { + $this->size = $size; + } + + public function addCheese() + { + $this->cheese = true; + return $this; + } + + public function addPepperoni() + { + $this->pepperoni = true; + return $this; + } + + public function addLettuce() + { + $this->lettuce = true; + return $this; + } + + public function addTomato() + { + $this->tomato = true; + return $this; + } + + // Finishes the build process. + public function build() + { + return new Burger($this); + } } \ No newline at end of file diff --git a/examples-per-language/php/creational/src/FactoryMethod/CommunityExecutive.php b/examples-per-language/php/creational/src/FactoryMethod/CommunityExecutive.php index 836f1d3f..5c972189 100644 --- a/examples-per-language/php/creational/src/FactoryMethod/CommunityExecutive.php +++ b/examples-per-language/php/creational/src/FactoryMethod/CommunityExecutive.php @@ -3,9 +3,11 @@ namespace designPatternsForHumans\creational\FactoryMethod; -class CommunityExecutive implements Interviewer { +class CommunityExecutive implements Interviewer +{ - public function askQuestions() { - echo 'Asking about community building!' . PHP_EOL; - } + public function askQuestions() + { + echo 'Asking about community building!' . PHP_EOL; + } } \ No newline at end of file diff --git a/examples-per-language/php/creational/src/FactoryMethod/Developer.php b/examples-per-language/php/creational/src/FactoryMethod/Developer.php index 34124e04..399f49c0 100644 --- a/examples-per-language/php/creational/src/FactoryMethod/Developer.php +++ b/examples-per-language/php/creational/src/FactoryMethod/Developer.php @@ -3,9 +3,11 @@ namespace designPatternsForHumans\creational\FactoryMethod; -class Developer implements Interviewer { +class Developer implements Interviewer +{ - public function askQuestions() { - echo 'Asking about Design Patterns!' . PHP_EOL; - } + public function askQuestions() + { + echo 'Asking about Design Patterns!' . PHP_EOL; + } } \ No newline at end of file diff --git a/examples-per-language/php/creational/src/FactoryMethod/DevelopmentManager.php b/examples-per-language/php/creational/src/FactoryMethod/DevelopmentManager.php index 8c36de12..16b41420 100644 --- a/examples-per-language/php/creational/src/FactoryMethod/DevelopmentManager.php +++ b/examples-per-language/php/creational/src/FactoryMethod/DevelopmentManager.php @@ -3,9 +3,11 @@ namespace designPatternsForHumans\creational\FactoryMethod; -class DevelopmentManager extends HiringManager { +class DevelopmentManager extends HiringManager +{ - public function makeInterviewer() { - return new Developer(); - } + public function makeInterviewer() + { + return new Developer(); + } } \ No newline at end of file diff --git a/examples-per-language/php/creational/src/FactoryMethod/HiringManager.php b/examples-per-language/php/creational/src/FactoryMethod/HiringManager.php index f6dbf495..06fdea15 100644 --- a/examples-per-language/php/creational/src/FactoryMethod/HiringManager.php +++ b/examples-per-language/php/creational/src/FactoryMethod/HiringManager.php @@ -3,15 +3,17 @@ namespace designPatternsForHumans\creational\FactoryMethod; -abstract class HiringManager { +abstract class HiringManager +{ - // This is the factory method. - abstract public function makeInterviewer(); + // This is the factory method. + abstract public function makeInterviewer(); - public function takeInterview() { + public function takeInterview() + { - /** @var Interviewer $interviewer */ - $interviewer = $this->makeInterviewer(); - $interviewer->askQuestions(); - } + /** @var Interviewer $interviewer */ + $interviewer = $this->makeInterviewer(); + $interviewer->askQuestions(); + } } \ No newline at end of file diff --git a/examples-per-language/php/creational/src/FactoryMethod/Interviewer.php b/examples-per-language/php/creational/src/FactoryMethod/Interviewer.php index 6e6e550b..d3f0b6bb 100644 --- a/examples-per-language/php/creational/src/FactoryMethod/Interviewer.php +++ b/examples-per-language/php/creational/src/FactoryMethod/Interviewer.php @@ -3,6 +3,7 @@ namespace designPatternsForHumans\creational\FactoryMethod; -interface Interviewer { - public function askQuestions(); +interface Interviewer +{ + public function askQuestions(); } \ No newline at end of file diff --git a/examples-per-language/php/creational/src/FactoryMethod/MarketingManager.php b/examples-per-language/php/creational/src/FactoryMethod/MarketingManager.php index 8d0bf804..af03c95e 100644 --- a/examples-per-language/php/creational/src/FactoryMethod/MarketingManager.php +++ b/examples-per-language/php/creational/src/FactoryMethod/MarketingManager.php @@ -3,9 +3,11 @@ namespace designPatternsForHumans\creational\FactoryMethod; -class MarketingManager extends HiringManager { +class MarketingManager extends HiringManager +{ - public function makeInterviewer() { - return new CommunityExecutive(); - } + public function makeInterviewer() + { + return new CommunityExecutive(); + } } \ No newline at end of file diff --git a/examples-per-language/php/creational/src/Prototype/Sheep.php b/examples-per-language/php/creational/src/Prototype/Sheep.php index 74d92fb0..60f82b13 100644 --- a/examples-per-language/php/creational/src/Prototype/Sheep.php +++ b/examples-per-language/php/creational/src/Prototype/Sheep.php @@ -3,36 +3,42 @@ namespace designPatternsForHumans\creational\Prototype; -class Sheep { - - protected $name; - protected $category; - - public function __construct($name, $category = 'Mountain Sheep') { - $this->name = $name; - $this->category = $category; - } - - public function getName() { - return $this->name; - } - - /** - * @param string $name - */ - public function setName($name) { - $this->name = $name; - } - - /** - * @param string $category - */ - public function setCategory($category) { - $this->category = $category; - } - - public function getCategory() { - return $this->category; - } +class Sheep +{ + + protected $name; + protected $category; + + public function __construct($name, $category = 'Mountain Sheep') + { + $this->name = $name; + $this->category = $category; + } + + public function getName() + { + return $this->name; + } + + /** + * @param string $name + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * @param string $category + */ + public function setCategory($category) + { + $this->category = $category; + } + + public function getCategory() + { + return $this->category; + } } \ No newline at end of file diff --git a/examples-per-language/php/creational/src/SimpleFactory/Door.php b/examples-per-language/php/creational/src/SimpleFactory/Door.php index 1eea7e4a..1ac5d60d 100644 --- a/examples-per-language/php/creational/src/SimpleFactory/Door.php +++ b/examples-per-language/php/creational/src/SimpleFactory/Door.php @@ -3,8 +3,10 @@ namespace designPatternsForHumans\creational\SimpleFactory; -interface Door { - public function getWidth(); - public function getHeight(); +interface Door +{ + public function getWidth(); + + public function getHeight(); } \ No newline at end of file diff --git a/examples-per-language/php/creational/src/SimpleFactory/DoorFactory.php b/examples-per-language/php/creational/src/SimpleFactory/DoorFactory.php index e74578ff..51f6a04c 100644 --- a/examples-per-language/php/creational/src/SimpleFactory/DoorFactory.php +++ b/examples-per-language/php/creational/src/SimpleFactory/DoorFactory.php @@ -3,10 +3,12 @@ namespace designPatternsForHumans\creational\SimpleFactory; -class DoorFactory { +class DoorFactory +{ - public static function makeDoor($width, $height) { - return new WoodenDoor($width, $height); - } + public static function makeDoor($width, $height) + { + return new WoodenDoor($width, $height); + } } \ No newline at end of file diff --git a/examples-per-language/php/creational/src/SimpleFactory/WoodenDoor.php b/examples-per-language/php/creational/src/SimpleFactory/WoodenDoor.php index fb95fa58..cf2dd321 100644 --- a/examples-per-language/php/creational/src/SimpleFactory/WoodenDoor.php +++ b/examples-per-language/php/creational/src/SimpleFactory/WoodenDoor.php @@ -3,22 +3,26 @@ namespace designPatternsForHumans\creational\SimpleFactory; -class WoodenDoor implements Door { +class WoodenDoor implements Door +{ - protected $width; - protected $height; + protected $width; + protected $height; - public function __construct($width, $height) { - $this->width = $width; - $this->height = $height; - } + public function __construct($width, $height) + { + $this->width = $width; + $this->height = $height; + } - public function getWidth() { - return $this->width; - } + public function getWidth() + { + return $this->width; + } - public function getHeight() { - return $this->height; - } + public function getHeight() + { + return $this->height; + } } \ No newline at end of file diff --git a/examples-per-language/php/creational/src/Singleton/President.php b/examples-per-language/php/creational/src/Singleton/President.php index 48ea3931..22a0a9c0 100644 --- a/examples-per-language/php/creational/src/Singleton/President.php +++ b/examples-per-language/php/creational/src/Singleton/President.php @@ -3,30 +3,35 @@ namespace designPatternsForHumans\creational\Singleton; -final class President { +final class President +{ - private static $instance ; + private static $instance; - private function __construct() { - // Hide the constructor. - } - - private function __clone() { - // Disable cloning. - } + private function __construct() + { + // Hide the constructor. + } - private function __wakeup() { - // Disable unserialize. - } + private function __clone() + { + // Disable cloning. + } - // Only make a new instance it hasn't already been set, return the already - // existing instance if it was already set. - public static function getInstance() { - if (!self::$instance) { - self::$instance = new self(); + private function __wakeup() + { + // Disable unserialize. } - return self::$instance; - } + // Only make a new instance it hasn't already been set, return the already + // existing instance if it was already set. + public static function getInstance() + { + if (!self::$instance) { + self::$instance = new self(); + } + + return self::$instance; + } } \ No newline at end of file diff --git a/examples-per-language/php/structural/autoload.php b/examples-per-language/php/structural/autoload.php index 580cf4ba..a1139fb0 100644 --- a/examples-per-language/php/structural/autoload.php +++ b/examples-per-language/php/structural/autoload.php @@ -1,7 +1,8 @@ dog = $dog; - } + public function __construct(WildDog $dog) + { + $this->dog = $dog; + } - public function roar() { - $this->dog->bark(); - } + public function roar() + { + $this->dog->bark(); + } } \ No newline at end of file diff --git a/examples-per-language/php/structural/src/Bridge/About.php b/examples-per-language/php/structural/src/Bridge/About.php index 58161b19..053004be 100644 --- a/examples-per-language/php/structural/src/Bridge/About.php +++ b/examples-per-language/php/structural/src/Bridge/About.php @@ -2,15 +2,18 @@ namespace designPatternsForHumans\structural\Bridge; -class About implements WebPage { +class About implements WebPage +{ - protected $theme; + protected $theme; - public function __construct(Theme $theme) { - $this->theme = $theme; - } + public function __construct(Theme $theme) + { + $this->theme = $theme; + } - public function getContent() { - return 'About page in ' . $this->theme->getColor(); - } + public function getContent() + { + return 'About page in ' . $this->theme->getColor(); + } } \ No newline at end of file diff --git a/examples-per-language/php/structural/src/Bridge/AquaTheme.php b/examples-per-language/php/structural/src/Bridge/AquaTheme.php index 612247aa..36171f74 100644 --- a/examples-per-language/php/structural/src/Bridge/AquaTheme.php +++ b/examples-per-language/php/structural/src/Bridge/AquaTheme.php @@ -3,9 +3,11 @@ namespace designPatternsForHumans\structural\Bridge; -class AquaTheme implements Theme { +class AquaTheme implements Theme +{ - public function getColor() { - return 'Light blue'; - } + public function getColor() + { + return 'Light blue'; + } } \ No newline at end of file diff --git a/examples-per-language/php/structural/src/Bridge/Careers.php b/examples-per-language/php/structural/src/Bridge/Careers.php index 04cb24d7..6333f934 100644 --- a/examples-per-language/php/structural/src/Bridge/Careers.php +++ b/examples-per-language/php/structural/src/Bridge/Careers.php @@ -2,15 +2,18 @@ namespace designPatternsForHumans\structural\Bridge; -class Careers implements WebPage { +class Careers implements WebPage +{ - protected $theme; + protected $theme; - public function __construct(\designPatternsForHumans\structural\Bridge\Theme $theme) { - $this->theme = $theme; - } + public function __construct(Theme $theme) + { + $this->theme = $theme; + } - public function getContent() { - return 'Careers page in ' . $this->theme->getColor(); - } + public function getContent() + { + return 'Careers page in ' . $this->theme->getColor(); + } } \ No newline at end of file diff --git a/examples-per-language/php/structural/src/Bridge/DarkTheme.php b/examples-per-language/php/structural/src/Bridge/DarkTheme.php index 3d991d02..41588674 100644 --- a/examples-per-language/php/structural/src/Bridge/DarkTheme.php +++ b/examples-per-language/php/structural/src/Bridge/DarkTheme.php @@ -3,9 +3,11 @@ namespace designPatternsForHumans\structural\Bridge; -class DarkTheme implements Theme { +class DarkTheme implements Theme +{ - public function getColor() { - return 'Dark Black'; - } + public function getColor() + { + return 'Dark Black'; + } } \ No newline at end of file diff --git a/examples-per-language/php/structural/src/Bridge/LightTheme.php b/examples-per-language/php/structural/src/Bridge/LightTheme.php index 3571271d..93c62576 100644 --- a/examples-per-language/php/structural/src/Bridge/LightTheme.php +++ b/examples-per-language/php/structural/src/Bridge/LightTheme.php @@ -3,9 +3,11 @@ namespace designPatternsForHumans\structural\Bridge; -class LightTheme implements Theme { +class LightTheme implements Theme +{ - public function getColor() { - return 'Off white'; - } + public function getColor() + { + return 'Off white'; + } } \ No newline at end of file diff --git a/examples-per-language/php/structural/src/Bridge/Theme.php b/examples-per-language/php/structural/src/Bridge/Theme.php index 1cfbb6a6..37a0d6eb 100644 --- a/examples-per-language/php/structural/src/Bridge/Theme.php +++ b/examples-per-language/php/structural/src/Bridge/Theme.php @@ -3,7 +3,8 @@ namespace designPatternsForHumans\structural\Bridge; -interface Theme { - public function getColor(); +interface Theme +{ + public function getColor(); } \ No newline at end of file diff --git a/examples-per-language/php/structural/src/Bridge/WebPage.php b/examples-per-language/php/structural/src/Bridge/WebPage.php index 8ba648d4..116f1a37 100644 --- a/examples-per-language/php/structural/src/Bridge/WebPage.php +++ b/examples-per-language/php/structural/src/Bridge/WebPage.php @@ -3,9 +3,11 @@ namespace designPatternsForHumans\structural\Bridge; -interface WebPage { +interface WebPage +{ - public function __construct(Theme $theme); - public function getContent(); + public function __construct(Theme $theme); + + public function getContent(); } \ No newline at end of file diff --git a/examples-per-language/php/structural/src/Composite/Designer.php b/examples-per-language/php/structural/src/Composite/Designer.php index 47a6bdf1..2dba2ffc 100644 --- a/examples-per-language/php/structural/src/Composite/Designer.php +++ b/examples-per-language/php/structural/src/Composite/Designer.php @@ -3,26 +3,32 @@ namespace designPatternsForHumans\structural\Composite; -class Designer implements Employee { - - public function __construct($name, $salary) { - $this->name = $name; - $this->salary = $salary; - } - - public function getName() { - return $this->name; - } - - public function setSalary($salary) { - $this->salary = $salary; - } - - public function getSalary() { - return $this->salary; - } - - public function getRoles() { - return $this->roles; - } +class Designer implements Employee +{ + + public function __construct($name, $salary) + { + $this->name = $name; + $this->salary = $salary; + } + + public function getName() + { + return $this->name; + } + + public function setSalary($salary) + { + $this->salary = $salary; + } + + public function getSalary() + { + return $this->salary; + } + + public function getRoles() + { + return $this->roles; + } } \ No newline at end of file diff --git a/examples-per-language/php/structural/src/Composite/Developer.php b/examples-per-language/php/structural/src/Composite/Developer.php index b2c69aa8..3e7f234b 100644 --- a/examples-per-language/php/structural/src/Composite/Developer.php +++ b/examples-per-language/php/structural/src/Composite/Developer.php @@ -3,29 +3,35 @@ namespace designPatternsForHumans\structural\Composite; -class Developer implements Employee { - - protected $name; - protected $salary; - - public function __construct($name, $salary) { - $this->name = $name; - $this->salary = $salary; - } - - public function getName() { - return $this->name; - } - - public function setSalary($salary) { - $this->salary = $salary; - } - - public function getSalary() { - return $this->salary; - } - - public function getRoles() { - return $this->roles; - } +class Developer implements Employee +{ + + protected $name; + protected $salary; + + public function __construct($name, $salary) + { + $this->name = $name; + $this->salary = $salary; + } + + public function getName() + { + return $this->name; + } + + public function setSalary($salary) + { + $this->salary = $salary; + } + + public function getSalary() + { + return $this->salary; + } + + public function getRoles() + { + return $this->roles; + } } \ No newline at end of file diff --git a/examples-per-language/php/structural/src/Composite/Employee.php b/examples-per-language/php/structural/src/Composite/Employee.php index 177e8cfe..7064e183 100644 --- a/examples-per-language/php/structural/src/Composite/Employee.php +++ b/examples-per-language/php/structural/src/Composite/Employee.php @@ -3,11 +3,16 @@ namespace designPatternsForHumans\structural\Composite; -interface Employee { +interface Employee +{ - public function __construct($name, $salary); - public function getName(); - public function setSalary($salary); - public function getSalary(); - public function getRoles(); + public function __construct($name, $salary); + + public function getName(); + + public function setSalary($salary); + + public function getSalary(); + + public function getRoles(); } \ No newline at end of file diff --git a/examples-per-language/php/structural/src/Composite/Organization.php b/examples-per-language/php/structural/src/Composite/Organization.php index 8fbcf572..623c2d4c 100644 --- a/examples-per-language/php/structural/src/Composite/Organization.php +++ b/examples-per-language/php/structural/src/Composite/Organization.php @@ -3,23 +3,26 @@ namespace designPatternsForHumans\structural\Composite; -class Organization { +class Organization +{ - protected $employees; + protected $employees; - public function addEmployee(Employee $employee) { - $this->employees[] = $employee; - } + public function addEmployee(Employee $employee) + { + $this->employees[] = $employee; + } - public function getNetSalaries() { - $netSalary = 0; + public function getNetSalaries() + { + $netSalary = 0; - /** @var Employee $employee */ - foreach ($this->employees as $employee) { - $netSalary += $employee->getSalary(); - } + /** @var Employee $employee */ + foreach ($this->employees as $employee) { + $netSalary += $employee->getSalary(); + } - return $netSalary; - } + return $netSalary; + } } \ No newline at end of file diff --git a/examples-per-language/php/structural/src/Decorator/Coffee.php b/examples-per-language/php/structural/src/Decorator/Coffee.php index e7c02461..85cfa3f5 100644 --- a/examples-per-language/php/structural/src/Decorator/Coffee.php +++ b/examples-per-language/php/structural/src/Decorator/Coffee.php @@ -3,9 +3,11 @@ namespace designPatternsForHumans\structural\Decorator; -interface Coffee { +interface Coffee +{ - public function getCost(); - public function getDescription(); + public function getCost(); + + public function getDescription(); } \ No newline at end of file diff --git a/examples-per-language/php/structural/src/Decorator/MilkCoffee.php b/examples-per-language/php/structural/src/Decorator/MilkCoffee.php index ea62a0b4..37606516 100644 --- a/examples-per-language/php/structural/src/Decorator/MilkCoffee.php +++ b/examples-per-language/php/structural/src/Decorator/MilkCoffee.php @@ -3,20 +3,24 @@ namespace designPatternsForHumans\structural\Decorator; -class MilkCoffee implements Coffee { +class MilkCoffee implements Coffee +{ - /** @var Coffee */ - protected $coffee; + /** @var Coffee */ + protected $coffee; - public function __construct(Coffee $coffee) { - $this->coffee = $coffee; - } + public function __construct(Coffee $coffee) + { + $this->coffee = $coffee; + } - public function getCost() { - return $this->coffee->getCost() + 2; - } + public function getCost() + { + return $this->coffee->getCost() + 2; + } - public function getDescription() { - return $this->coffee->getDescription() . ', milk'; - } + public function getDescription() + { + return $this->coffee->getDescription() . ', milk'; + } } \ No newline at end of file diff --git a/examples-per-language/php/structural/src/Decorator/SimpleCoffee.php b/examples-per-language/php/structural/src/Decorator/SimpleCoffee.php index 153e115b..a8df92d1 100644 --- a/examples-per-language/php/structural/src/Decorator/SimpleCoffee.php +++ b/examples-per-language/php/structural/src/Decorator/SimpleCoffee.php @@ -3,13 +3,16 @@ namespace designPatternsForHumans\structural\Decorator; -class SimpleCoffee implements Coffee { +class SimpleCoffee implements Coffee +{ - public function getCost() { - return 10; - } + public function getCost() + { + return 10; + } - public function getDescription() { - return 'Simple coffee'; - } + public function getDescription() + { + return 'Simple coffee'; + } } \ No newline at end of file diff --git a/examples-per-language/php/structural/src/Decorator/VanillaCoffee.php b/examples-per-language/php/structural/src/Decorator/VanillaCoffee.php index fcd311b0..a2e6efbb 100644 --- a/examples-per-language/php/structural/src/Decorator/VanillaCoffee.php +++ b/examples-per-language/php/structural/src/Decorator/VanillaCoffee.php @@ -3,20 +3,24 @@ namespace designPatternsForHumans\structural\Decorator; -class VanillaCoffee implements Coffee { +class VanillaCoffee implements Coffee +{ - /** @var Coffee */ - protected $coffee; + /** @var Coffee */ + protected $coffee; - public function __construct(Coffee $coffee) { - $this->coffee = $coffee; - } + public function __construct(Coffee $coffee) + { + $this->coffee = $coffee; + } - public function getCost() { - return $this->coffee->getCost() + 3; - } + public function getCost() + { + return $this->coffee->getCost() + 3; + } - public function getDescription() { - return $this->coffee->getDescription() . ', vanilla'; - } + public function getDescription() + { + return $this->coffee->getDescription() . ', vanilla'; + } } \ No newline at end of file diff --git a/examples-per-language/php/structural/src/Decorator/WhipCoffee.php b/examples-per-language/php/structural/src/Decorator/WhipCoffee.php index a50989fd..5fcba679 100644 --- a/examples-per-language/php/structural/src/Decorator/WhipCoffee.php +++ b/examples-per-language/php/structural/src/Decorator/WhipCoffee.php @@ -3,20 +3,24 @@ namespace designPatternsForHumans\structural\Decorator; -class WhipCoffee implements Coffee { +class WhipCoffee implements Coffee +{ - /** @var Coffee */ - protected $coffee; + /** @var Coffee */ + protected $coffee; - public function __construct(Coffee $coffee) { - $this->coffee = $coffee; - } + public function __construct(Coffee $coffee) + { + $this->coffee = $coffee; + } - public function getCost() { - return $this->coffee->getCost() + 5; - } + public function getCost() + { + return $this->coffee->getCost() + 5; + } - public function getDescription() { - return $this->coffee->getDescription() . ', whip'; - } + public function getDescription() + { + return $this->coffee->getDescription() . ', whip'; + } } \ No newline at end of file diff --git a/examples-per-language/php/structural/src/Facade/Computer.php b/examples-per-language/php/structural/src/Facade/Computer.php index 8106555c..0d592b3a 100644 --- a/examples-per-language/php/structural/src/Facade/Computer.php +++ b/examples-per-language/php/structural/src/Facade/Computer.php @@ -3,34 +3,42 @@ namespace designPatternsForHumans\structural\Facade; -class Computer { - - public function getElectricShock() { - echo 'Ouch!' . PHP_EOL; - } - - public function makeSound() { - echo 'Beep, Beep' . PHP_EOL; - } - - public function showLoadingScreen() { - echo 'Loading ...' . PHP_EOL; - } - - public function bam() { - echo 'Ready to be used!' . PHP_EOL; - } - - public function closeEverything() { - echo 'Bup bup bup buzzzzzz' . PHP_EOL; - } - - public function pullCurrent() { - echo 'Haah!' . PHP_EOL; - } - - public function sooth() { - echo 'zzzzzzz' . PHP_EOL; - } +class Computer +{ + + public function getElectricShock() + { + echo 'Ouch!' . PHP_EOL; + } + + public function makeSound() + { + echo 'Beep, Beep' . PHP_EOL; + } + + public function showLoadingScreen() + { + echo 'Loading ...' . PHP_EOL; + } + + public function bam() + { + echo 'Ready to be used!' . PHP_EOL; + } + + public function closeEverything() + { + echo 'Bup bup bup buzzzzzz' . PHP_EOL; + } + + public function pullCurrent() + { + echo 'Haah!' . PHP_EOL; + } + + public function sooth() + { + echo 'zzzzzzz' . PHP_EOL; + } } \ No newline at end of file diff --git a/examples-per-language/php/structural/src/Facade/ComputerFacade.php b/examples-per-language/php/structural/src/Facade/ComputerFacade.php index 96971c22..2821321e 100644 --- a/examples-per-language/php/structural/src/Facade/ComputerFacade.php +++ b/examples-per-language/php/structural/src/Facade/ComputerFacade.php @@ -3,26 +3,30 @@ namespace designPatternsForHumans\structural\Facade; -class ComputerFacade { - - protected $computer; - - public function __construct(Computer $computer) { - $this->computer = $computer; - } - - public function turnOn() { - $this->computer->getElectricShock(); - $this->computer->makeSound(); - $this->computer->showLoadingScreen(); - $this->computer->bam(); - } - - public function turnOff() { - $this->computer->closeEverything(); - $this->computer->pullCurrent(); - $this->computer->sooth(); - } +class ComputerFacade +{ + + protected $computer; + + public function __construct(Computer $computer) + { + $this->computer = $computer; + } + + public function turnOn() + { + $this->computer->getElectricShock(); + $this->computer->makeSound(); + $this->computer->showLoadingScreen(); + $this->computer->bam(); + } + + public function turnOff() + { + $this->computer->closeEverything(); + $this->computer->pullCurrent(); + $this->computer->sooth(); + } } \ No newline at end of file diff --git a/examples-per-language/php/structural/src/Flyweight/KarakTea.php b/examples-per-language/php/structural/src/Flyweight/KarakTea.php index ea6c17b1..2a0ab1a8 100644 --- a/examples-per-language/php/structural/src/Flyweight/KarakTea.php +++ b/examples-per-language/php/structural/src/Flyweight/KarakTea.php @@ -4,6 +4,7 @@ // Anything that will be cached is flyweight. // In this example Types of tea will be flyweights. -class KarakTea { +class KarakTea +{ } \ No newline at end of file diff --git a/examples-per-language/php/structural/src/Flyweight/TeaMaker.php b/examples-per-language/php/structural/src/Flyweight/TeaMaker.php index c0385bf0..eff500f3 100644 --- a/examples-per-language/php/structural/src/Flyweight/TeaMaker.php +++ b/examples-per-language/php/structural/src/Flyweight/TeaMaker.php @@ -3,19 +3,21 @@ namespace designPatternsForHumans\structural\Flyweight; -class TeaMaker { +class TeaMaker +{ - protected $availableTea = []; + protected $availableTea = []; - public function make($preference) { - if (empty($this->availableTea[$preference])) { - $this->availableTea[$preference] = new KarakTea(); - echo 'The tea ' . $preference . ' was not available and was freshly made' . PHP_EOL; - } else { - echo 'The tea ' . $preference . ' was already made, so we served that' . PHP_EOL; - } + public function make($preference) + { + if (empty($this->availableTea[$preference])) { + $this->availableTea[$preference] = new KarakTea(); + echo 'The tea ' . $preference . ' was not available and was freshly made' . PHP_EOL; + } else { + echo 'The tea ' . $preference . ' was already made, so we served that' . PHP_EOL; + } - return $this->availableTea[$preference]; - } + return $this->availableTea[$preference]; + } } \ No newline at end of file diff --git a/examples-per-language/php/structural/src/Flyweight/TeaShop.php b/examples-per-language/php/structural/src/Flyweight/TeaShop.php index dfbeda2f..79de029a 100644 --- a/examples-per-language/php/structural/src/Flyweight/TeaShop.php +++ b/examples-per-language/php/structural/src/Flyweight/TeaShop.php @@ -3,28 +3,32 @@ namespace designPatternsForHumans\structural\Flyweight; -class TeaShop { - - protected $teaMaker; - protected $orders; - - public function __construct(TeaMaker $teaMaker) { - $this->teaMaker = $teaMaker; - } - - /** - * @param string $teaType - * @param int $table - */ - public function takeOrder($teaType, $table) { - $this->orders[$table] = $this->teaMaker->make($teaType); - } - - public function serve() { - foreach ($this->orders as $table => $order) { - echo "Serving tea to table # " . $table . PHP_EOL; +class TeaShop +{ + + protected $teaMaker; + protected $orders; + + public function __construct(TeaMaker $teaMaker) + { + $this->teaMaker = $teaMaker; + } + + /** + * @param string $teaType + * @param int $table + */ + public function takeOrder($teaType, $table) + { + $this->orders[$table] = $this->teaMaker->make($teaType); + } + + public function serve() + { + foreach ($this->orders as $table => $order) { + echo 'Serving tea to table # ' . $table . PHP_EOL; + } } - } } \ No newline at end of file diff --git a/examples-per-language/php/structural/src/Proxy/Door.php b/examples-per-language/php/structural/src/Proxy/Door.php index 01995e30..bc6b82bc 100644 --- a/examples-per-language/php/structural/src/Proxy/Door.php +++ b/examples-per-language/php/structural/src/Proxy/Door.php @@ -3,9 +3,11 @@ namespace designPatternsForHumans\structural\Proxy; -interface Door { +interface Door +{ - public function open(); - public function close(); + public function open(); + + public function close(); } \ No newline at end of file diff --git a/examples-per-language/php/structural/src/Proxy/LabDoor.php b/examples-per-language/php/structural/src/Proxy/LabDoor.php index 388026c5..dcf7d4e5 100644 --- a/examples-per-language/php/structural/src/Proxy/LabDoor.php +++ b/examples-per-language/php/structural/src/Proxy/LabDoor.php @@ -3,13 +3,16 @@ namespace designPatternsForHumans\structural\Proxy; -class LabDoor implements Door { +class LabDoor implements Door +{ - public function open() { - echo 'Opening lab door ' . PHP_EOL; - } + public function open() + { + echo 'Opening lab door ' . PHP_EOL; + } - public function close() { - echo 'Closing lab door ' . PHP_EOL; - } + public function close() + { + echo 'Closing lab door ' . PHP_EOL; + } } \ No newline at end of file diff --git a/examples-per-language/php/structural/src/Proxy/Security.php b/examples-per-language/php/structural/src/Proxy/Security.php index 42d3739e..83f28e60 100644 --- a/examples-per-language/php/structural/src/Proxy/Security.php +++ b/examples-per-language/php/structural/src/Proxy/Security.php @@ -3,32 +3,37 @@ namespace designPatternsForHumans\structural\Proxy; -class Security { +class Security +{ - protected $door; + protected $door; - public function __construct(Door $door) { - $this->door = $door; - } + public function __construct(Door $door) + { + $this->door = $door; + } - public function open($password) { - if ($this->authenticate($password)) { - $this->door->open(); - echo 'Access granted!' . PHP_EOL; - } else { - echo "Big no! It ain't possible!" . PHP_EOL; + public function open($password) + { + if ($this->authenticate($password)) { + $this->door->open(); + echo 'Access granted!' . PHP_EOL; + } else { + echo "Big no! It ain't possible!" . PHP_EOL; + } } - } - // In the code examples this is public, but there is no real reason - // why this method should be available to anything except this class. - private function authenticate($password) { - return $password === '$ecr@t'; - } + // In the code examples this is public, but there is no real reason + // why this method should be available to anything except this class. + private function authenticate($password) + { + return $password === '$ecr@t'; + } - public function close() { - $this->door->close(); - } + public function close() + { + $this->door->close(); + } } \ No newline at end of file From b777cc197dec6e903e326f31e92abaafe611c494 Mon Sep 17 00:00:00 2001 From: Bert Van de Casteele Date: Mon, 27 Feb 2017 00:07:14 +0100 Subject: [PATCH 15/28] Added Chain Of Command example --- .../behavioral/Chain_Of_Responsibility.php | 23 +++++++++++++ .../php/behavioral/autoload.php | 7 ++++ .../src/Chain_Of_Responsibility/Account.php | 34 +++++++++++++++++++ .../src/Chain_Of_Responsibility/Bank.php | 16 +++++++++ .../src/Chain_Of_Responsibility/BitCoin.php | 16 +++++++++ .../src/Chain_Of_Responsibility/Paypal.php | 16 +++++++++ 6 files changed, 112 insertions(+) create mode 100644 examples-per-language/php/behavioral/Chain_Of_Responsibility.php create mode 100644 examples-per-language/php/behavioral/autoload.php create mode 100644 examples-per-language/php/behavioral/src/Chain_Of_Responsibility/Account.php create mode 100644 examples-per-language/php/behavioral/src/Chain_Of_Responsibility/Bank.php create mode 100644 examples-per-language/php/behavioral/src/Chain_Of_Responsibility/BitCoin.php create mode 100644 examples-per-language/php/behavioral/src/Chain_Of_Responsibility/Paypal.php diff --git a/examples-per-language/php/behavioral/Chain_Of_Responsibility.php b/examples-per-language/php/behavioral/Chain_Of_Responsibility.php new file mode 100644 index 00000000..d6bad27e --- /dev/null +++ b/examples-per-language/php/behavioral/Chain_Of_Responsibility.php @@ -0,0 +1,23 @@ +$paypal->$bitcoin + +$bank = new Bank(100); +$paypal = new Paypal(200); +$bitcoin = new BitCoin(300); + +// First priority bank +// If bank can't pay then paypal +// If paypal can't pay then bit coin. +$bank->setNext($paypal); +$paypal->setNext($bitcoin); + +// Let's try and pay our bill. +$bank->pay(259); \ No newline at end of file diff --git a/examples-per-language/php/behavioral/autoload.php b/examples-per-language/php/behavioral/autoload.php new file mode 100644 index 00000000..580cf4ba --- /dev/null +++ b/examples-per-language/php/behavioral/autoload.php @@ -0,0 +1,7 @@ +successor = $account; + } + + public function pay($amountToPay) + { + if ($this->canPay($amountToPay)) { + echo sprintf('Paid %s using %s' . PHP_EOL, $amountToPay, + get_called_class()); + } elseif ($this->successor) { + echo sprintf('Cannot pay using %s. Proceeding ...' . PHP_EOL, + get_called_class()); + $this->successor->pay($amountToPay); + } else { + throw new \Exception('None of the accounts have enough balance'); + } + } + + public function canPay($amount) + { + return $this->balance >= $amount; + } +} \ No newline at end of file diff --git a/examples-per-language/php/behavioral/src/Chain_Of_Responsibility/Bank.php b/examples-per-language/php/behavioral/src/Chain_Of_Responsibility/Bank.php new file mode 100644 index 00000000..79d3d877 --- /dev/null +++ b/examples-per-language/php/behavioral/src/Chain_Of_Responsibility/Bank.php @@ -0,0 +1,16 @@ +balance = $balance; + } +} \ No newline at end of file diff --git a/examples-per-language/php/behavioral/src/Chain_Of_Responsibility/BitCoin.php b/examples-per-language/php/behavioral/src/Chain_Of_Responsibility/BitCoin.php new file mode 100644 index 00000000..d99c4fb4 --- /dev/null +++ b/examples-per-language/php/behavioral/src/Chain_Of_Responsibility/BitCoin.php @@ -0,0 +1,16 @@ +balance = $balance; + } +} \ No newline at end of file diff --git a/examples-per-language/php/behavioral/src/Chain_Of_Responsibility/Paypal.php b/examples-per-language/php/behavioral/src/Chain_Of_Responsibility/Paypal.php new file mode 100644 index 00000000..673ecd80 --- /dev/null +++ b/examples-per-language/php/behavioral/src/Chain_Of_Responsibility/Paypal.php @@ -0,0 +1,16 @@ +balance = $balance; + } +} \ No newline at end of file From 0cd70fe97c61a098d90e6acb67a27e2217f0debb Mon Sep 17 00:00:00 2001 From: Bert Van de Casteele Date: Mon, 27 Feb 2017 00:20:01 +0100 Subject: [PATCH 16/28] Added Command example --- .../php/behavioral/Command.php | 17 +++++++++++ .../php/behavioral/src/Command/Bulb.php | 19 ++++++++++++ .../php/behavioral/src/Command/Command.php | 12 ++++++++ .../behavioral/src/Command/RemoteControl.php | 13 ++++++++ .../php/behavioral/src/Command/TurnOff.php | 30 +++++++++++++++++++ .../php/behavioral/src/Command/TurnOn.php | 30 +++++++++++++++++++ 6 files changed, 121 insertions(+) create mode 100644 examples-per-language/php/behavioral/Command.php create mode 100644 examples-per-language/php/behavioral/src/Command/Bulb.php create mode 100644 examples-per-language/php/behavioral/src/Command/Command.php create mode 100644 examples-per-language/php/behavioral/src/Command/RemoteControl.php create mode 100644 examples-per-language/php/behavioral/src/Command/TurnOff.php create mode 100644 examples-per-language/php/behavioral/src/Command/TurnOn.php diff --git a/examples-per-language/php/behavioral/Command.php b/examples-per-language/php/behavioral/Command.php new file mode 100644 index 00000000..50711314 --- /dev/null +++ b/examples-per-language/php/behavioral/Command.php @@ -0,0 +1,17 @@ +submit($turnOn); +$remote->submit($turnOff); \ No newline at end of file diff --git a/examples-per-language/php/behavioral/src/Command/Bulb.php b/examples-per-language/php/behavioral/src/Command/Bulb.php new file mode 100644 index 00000000..351b552d --- /dev/null +++ b/examples-per-language/php/behavioral/src/Command/Bulb.php @@ -0,0 +1,19 @@ +execute(); + } + +} \ No newline at end of file diff --git a/examples-per-language/php/behavioral/src/Command/TurnOff.php b/examples-per-language/php/behavioral/src/Command/TurnOff.php new file mode 100644 index 00000000..51963109 --- /dev/null +++ b/examples-per-language/php/behavioral/src/Command/TurnOff.php @@ -0,0 +1,30 @@ +bulb = $bulb; + } + + public function execute() + { + $this->bulb->turnOff(); + } + + public function undo() + { + $this->bulb->turnOn(); + } + + public function redo() + { + $this->execute(); + } +} \ No newline at end of file diff --git a/examples-per-language/php/behavioral/src/Command/TurnOn.php b/examples-per-language/php/behavioral/src/Command/TurnOn.php new file mode 100644 index 00000000..b3288714 --- /dev/null +++ b/examples-per-language/php/behavioral/src/Command/TurnOn.php @@ -0,0 +1,30 @@ +bulb = $bulb; + } + + public function execute() + { + $this->bulb->turnOn(); + } + + public function undo() + { + $this->bulb->turnOff(); + } + + public function redo() + { + $this->execute(); + } +} \ No newline at end of file From a52e9ca7a4b3beb8d48bb4e4b7a3b5d8fd85da8b Mon Sep 17 00:00:00 2001 From: Bert Van de Casteele Date: Mon, 27 Feb 2017 00:53:45 +0100 Subject: [PATCH 17/28] Added Iterator example, slightly modified to better show the workings --- .../php/behavioral/Iterator.php | 32 ++++++++++ .../behavioral/src/Iterator/RadioStation.php | 19 ++++++ .../behavioral/src/Iterator/StationList.php | 61 +++++++++++++++++++ 3 files changed, 112 insertions(+) create mode 100644 examples-per-language/php/behavioral/Iterator.php create mode 100644 examples-per-language/php/behavioral/src/Iterator/RadioStation.php create mode 100644 examples-per-language/php/behavioral/src/Iterator/StationList.php diff --git a/examples-per-language/php/behavioral/Iterator.php b/examples-per-language/php/behavioral/Iterator.php new file mode 100644 index 00000000..34ebd6c4 --- /dev/null +++ b/examples-per-language/php/behavioral/Iterator.php @@ -0,0 +1,32 @@ +addStation(new RadioStation(89)); +$stationList->addStation(new RadioStation(101)); +$stationList->addStation(new RadioStation(102)); +$stationList->addStation(new RadioStation(103.2)); + +/** @var RadioStation $station */ +echo 'These are the known Radio Stations' . PHP_EOL; +foreach ($stationList as $station) { + echo $station->getFrequency(). PHP_EOL; +} + +$stationList->removeStation(new RadioStation(89)); + +// To prove the station was indeed removed, we iterate through the list again. +// Small caveat : Iterators need to be rewinded after beeing Iterated! +$stationList->rewind(); + +/** @var RadioStation $station */ +echo 'These are the known Radio Stations' . PHP_EOL; +foreach ($stationList as $station) { + echo $station->getFrequency(). PHP_EOL; +} + diff --git a/examples-per-language/php/behavioral/src/Iterator/RadioStation.php b/examples-per-language/php/behavioral/src/Iterator/RadioStation.php new file mode 100644 index 00000000..32c44d07 --- /dev/null +++ b/examples-per-language/php/behavioral/src/Iterator/RadioStation.php @@ -0,0 +1,19 @@ +frequency = $frequency; + } + + public function getFrequency() + { + return $this->frequency; + } +} \ No newline at end of file diff --git a/examples-per-language/php/behavioral/src/Iterator/StationList.php b/examples-per-language/php/behavioral/src/Iterator/StationList.php new file mode 100644 index 00000000..e1ff5ed7 --- /dev/null +++ b/examples-per-language/php/behavioral/src/Iterator/StationList.php @@ -0,0 +1,61 @@ +stations[] = $station; + } + + public function removeStation(RadioStation $toRemove) + { + $toRemoveFrequency = $toRemove->getFrequency(); + $this->stations = array_filter($this->stations, function (RadioStation $station) use ($toRemoveFrequency) { + return $station->getFrequency() !== $toRemoveFrequency; + }); + } + + public function current() + { + return $this->stations[$this->counter]; + } + + public function next() + { + $this->counter++; + } + + public function key() + { + return $this->counter; + } + + public function valid() + { + return isset($this->stations[$this->counter]); + } + + public function rewind() + { + // When using a numbered array like we do with $counter, we need to reset + // the array as well, otherwise the removed station will wreak havoc with + // our iteration, because the value ox removed station at position X will + // be NULL; + $this->stations = array_values($this->stations); + return $this->counter = 0; + } + + public function count() + { + return count($this->stations); + } +} \ No newline at end of file From f7c1310adcd8009f40e739cf541c5ccbc06e38cd Mon Sep 17 00:00:00 2001 From: Bert Van de Casteele Date: Mon, 27 Feb 2017 00:55:08 +0100 Subject: [PATCH 18/28] Small typo fix in Iterator example --- .../php/behavioral/src/Iterator/StationList.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples-per-language/php/behavioral/src/Iterator/StationList.php b/examples-per-language/php/behavioral/src/Iterator/StationList.php index e1ff5ed7..c1a7bc05 100644 --- a/examples-per-language/php/behavioral/src/Iterator/StationList.php +++ b/examples-per-language/php/behavioral/src/Iterator/StationList.php @@ -48,7 +48,7 @@ public function rewind() { // When using a numbered array like we do with $counter, we need to reset // the array as well, otherwise the removed station will wreak havoc with - // our iteration, because the value ox removed station at position X will + // our iteration, because the value of removed station at position X will // be NULL; $this->stations = array_values($this->stations); return $this->counter = 0; From 47c5081cd60179e640fe064bd9c19104f7ba451b Mon Sep 17 00:00:00 2001 From: Bert Van de Casteele Date: Mon, 27 Feb 2017 22:36:25 +0100 Subject: [PATCH 19/28] Removed .gitignore as per suggestion of @povils --- .gitignore | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 .gitignore diff --git a/.gitignore b/.gitignore deleted file mode 100644 index b38118ad..00000000 --- a/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -# IntelliJ project files -.idea -*.iml -out -gen From c56150bccb57d1d9b3b1c7d3abe99aa429f2572d Mon Sep 17 00:00:00 2001 From: Bert Van de Casteele Date: Mon, 27 Feb 2017 22:45:59 +0100 Subject: [PATCH 20/28] Added newlines at the end of files, per request @povils --- .../php/behavioral/Chain_Of_Responsibility.php | 2 +- examples-per-language/php/behavioral/Command.php | 2 +- examples-per-language/php/behavioral/Iterator.php | 1 - examples-per-language/php/behavioral/autoload.php | 2 +- .../php/behavioral/src/Chain_Of_Responsibility/Account.php | 2 +- .../php/behavioral/src/Chain_Of_Responsibility/Bank.php | 2 +- .../php/behavioral/src/Chain_Of_Responsibility/BitCoin.php | 2 +- .../php/behavioral/src/Chain_Of_Responsibility/Paypal.php | 2 +- examples-per-language/php/behavioral/src/Command/Bulb.php | 2 +- examples-per-language/php/behavioral/src/Command/Command.php | 2 +- .../php/behavioral/src/Command/RemoteControl.php | 2 +- examples-per-language/php/behavioral/src/Command/TurnOff.php | 2 +- examples-per-language/php/behavioral/src/Command/TurnOn.php | 2 +- .../php/behavioral/src/Iterator/RadioStation.php | 2 +- .../php/behavioral/src/Iterator/StationList.php | 2 +- examples-per-language/php/creational/AbstractFactoryMethod.php | 1 - examples-per-language/php/creational/Builder.php | 2 +- examples-per-language/php/creational/FactoryMethod.php | 2 +- examples-per-language/php/creational/Prototype.php | 1 - examples-per-language/php/creational/SimpleFactory.php | 2 +- examples-per-language/php/creational/Singleton.php | 2 +- examples-per-language/php/creational/autoload.php | 2 +- .../php/creational/src/AbstractFactory/Carpenter.php | 2 +- .../php/creational/src/AbstractFactory/Door.php | 2 +- .../php/creational/src/AbstractFactory/DoorFactory.php | 2 +- .../php/creational/src/AbstractFactory/DoorFittingExpert.php | 2 +- .../php/creational/src/AbstractFactory/IronDoor.php | 2 +- .../php/creational/src/AbstractFactory/IronDoorFactory.php | 2 +- .../php/creational/src/AbstractFactory/Welder.php | 2 +- .../php/creational/src/AbstractFactory/WoodenDoor.php | 2 +- .../php/creational/src/AbstractFactory/WoodenDoorFactory.php | 2 +- examples-per-language/php/creational/src/Builder/Burger.php | 2 +- .../php/creational/src/Builder/BurgerBuilder.php | 2 +- .../php/creational/src/FactoryMethod/CommunityExecutive.php | 2 +- .../php/creational/src/FactoryMethod/Developer.php | 2 +- .../php/creational/src/FactoryMethod/DevelopmentManager.php | 2 +- .../php/creational/src/FactoryMethod/HiringManager.php | 2 +- .../php/creational/src/FactoryMethod/Interviewer.php | 2 +- .../php/creational/src/FactoryMethod/MarketingManager.php | 2 +- examples-per-language/php/creational/src/Prototype/Sheep.php | 2 +- .../php/creational/src/SimpleFactory/Door.php | 2 +- .../php/creational/src/SimpleFactory/DoorFactory.php | 2 +- .../php/creational/src/SimpleFactory/WoodenDoor.php | 2 +- .../php/creational/src/Singleton/President.php | 3 ++- examples-per-language/php/structural/Adapter.php | 2 +- examples-per-language/php/structural/Bridge.php | 2 +- examples-per-language/php/structural/Composite.php | 2 +- examples-per-language/php/structural/Decorator.php | 2 +- examples-per-language/php/structural/Facade.php | 2 +- examples-per-language/php/structural/Flyweight.php | 2 +- examples-per-language/php/structural/Proxy.php | 2 +- examples-per-language/php/structural/autoload.php | 2 +- .../php/structural/src/Adapter/AfricanLion.php | 2 +- examples-per-language/php/structural/src/Adapter/AsianLion.php | 2 +- examples-per-language/php/structural/src/Adapter/Hunter.php | 2 +- examples-per-language/php/structural/src/Adapter/Lion.php | 2 +- examples-per-language/php/structural/src/Adapter/WildDog.php | 2 +- .../php/structural/src/Adapter/WildDogAdapter.php | 2 +- examples-per-language/php/structural/src/Bridge/About.php | 2 +- examples-per-language/php/structural/src/Bridge/AquaTheme.php | 2 +- examples-per-language/php/structural/src/Bridge/Careers.php | 2 +- examples-per-language/php/structural/src/Bridge/DarkTheme.php | 2 +- examples-per-language/php/structural/src/Bridge/LightTheme.php | 2 +- examples-per-language/php/structural/src/Bridge/Theme.php | 2 +- examples-per-language/php/structural/src/Bridge/WebPage.php | 2 +- .../php/structural/src/Composite/Designer.php | 2 +- .../php/structural/src/Composite/Developer.php | 2 +- .../php/structural/src/Composite/Employee.php | 2 +- .../php/structural/src/Composite/Organization.php | 2 +- examples-per-language/php/structural/src/Decorator/Coffee.php | 2 +- .../php/structural/src/Decorator/MilkCoffee.php | 2 +- .../php/structural/src/Decorator/SimpleCoffee.php | 2 +- .../php/structural/src/Decorator/VanillaCoffee.php | 2 +- .../php/structural/src/Decorator/WhipCoffee.php | 2 +- examples-per-language/php/structural/src/Facade/Computer.php | 2 +- .../php/structural/src/Facade/ComputerFacade.php | 2 +- .../php/structural/src/Flyweight/KarakTea.php | 2 +- .../php/structural/src/Flyweight/TeaMaker.php | 2 +- examples-per-language/php/structural/src/Flyweight/TeaShop.php | 2 +- examples-per-language/php/structural/src/Proxy/Door.php | 2 +- examples-per-language/php/structural/src/Proxy/LabDoor.php | 2 +- examples-per-language/php/structural/src/Proxy/Security.php | 2 +- 82 files changed, 80 insertions(+), 82 deletions(-) diff --git a/examples-per-language/php/behavioral/Chain_Of_Responsibility.php b/examples-per-language/php/behavioral/Chain_Of_Responsibility.php index d6bad27e..c66b6622 100644 --- a/examples-per-language/php/behavioral/Chain_Of_Responsibility.php +++ b/examples-per-language/php/behavioral/Chain_Of_Responsibility.php @@ -20,4 +20,4 @@ $paypal->setNext($bitcoin); // Let's try and pay our bill. -$bank->pay(259); \ No newline at end of file +$bank->pay(259); diff --git a/examples-per-language/php/behavioral/Command.php b/examples-per-language/php/behavioral/Command.php index 50711314..93a5c6e1 100644 --- a/examples-per-language/php/behavioral/Command.php +++ b/examples-per-language/php/behavioral/Command.php @@ -14,4 +14,4 @@ $remote = new RemoteControl(); $remote->submit($turnOn); -$remote->submit($turnOff); \ No newline at end of file +$remote->submit($turnOff); diff --git a/examples-per-language/php/behavioral/Iterator.php b/examples-per-language/php/behavioral/Iterator.php index 34ebd6c4..d9f02de4 100644 --- a/examples-per-language/php/behavioral/Iterator.php +++ b/examples-per-language/php/behavioral/Iterator.php @@ -29,4 +29,3 @@ foreach ($stationList as $station) { echo $station->getFrequency(). PHP_EOL; } - diff --git a/examples-per-language/php/behavioral/autoload.php b/examples-per-language/php/behavioral/autoload.php index 580cf4ba..fa8db82c 100644 --- a/examples-per-language/php/behavioral/autoload.php +++ b/examples-per-language/php/behavioral/autoload.php @@ -4,4 +4,4 @@ $explode = explode("\\", $className); $slice = array_slice($explode, -2, 2); require_once 'src' . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $slice) . '.php'; -}); \ No newline at end of file +}); diff --git a/examples-per-language/php/behavioral/src/Chain_Of_Responsibility/Account.php b/examples-per-language/php/behavioral/src/Chain_Of_Responsibility/Account.php index ebd0c4f5..3d293c82 100644 --- a/examples-per-language/php/behavioral/src/Chain_Of_Responsibility/Account.php +++ b/examples-per-language/php/behavioral/src/Chain_Of_Responsibility/Account.php @@ -31,4 +31,4 @@ public function canPay($amount) { return $this->balance >= $amount; } -} \ No newline at end of file +} diff --git a/examples-per-language/php/behavioral/src/Chain_Of_Responsibility/Bank.php b/examples-per-language/php/behavioral/src/Chain_Of_Responsibility/Bank.php index 79d3d877..7516553e 100644 --- a/examples-per-language/php/behavioral/src/Chain_Of_Responsibility/Bank.php +++ b/examples-per-language/php/behavioral/src/Chain_Of_Responsibility/Bank.php @@ -13,4 +13,4 @@ public function __construct($balance) { $this->balance = $balance; } -} \ No newline at end of file +} diff --git a/examples-per-language/php/behavioral/src/Chain_Of_Responsibility/BitCoin.php b/examples-per-language/php/behavioral/src/Chain_Of_Responsibility/BitCoin.php index d99c4fb4..03aef73d 100644 --- a/examples-per-language/php/behavioral/src/Chain_Of_Responsibility/BitCoin.php +++ b/examples-per-language/php/behavioral/src/Chain_Of_Responsibility/BitCoin.php @@ -13,4 +13,4 @@ public function __construct($balance) { $this->balance = $balance; } -} \ No newline at end of file +} diff --git a/examples-per-language/php/behavioral/src/Chain_Of_Responsibility/Paypal.php b/examples-per-language/php/behavioral/src/Chain_Of_Responsibility/Paypal.php index 673ecd80..8a306f7c 100644 --- a/examples-per-language/php/behavioral/src/Chain_Of_Responsibility/Paypal.php +++ b/examples-per-language/php/behavioral/src/Chain_Of_Responsibility/Paypal.php @@ -13,4 +13,4 @@ public function __construct($balance) { $this->balance = $balance; } -} \ No newline at end of file +} diff --git a/examples-per-language/php/behavioral/src/Command/Bulb.php b/examples-per-language/php/behavioral/src/Command/Bulb.php index 351b552d..efee1f6a 100644 --- a/examples-per-language/php/behavioral/src/Command/Bulb.php +++ b/examples-per-language/php/behavioral/src/Command/Bulb.php @@ -16,4 +16,4 @@ public function turnOff() echo 'Darkness!' . PHP_EOL; } -} \ No newline at end of file +} diff --git a/examples-per-language/php/behavioral/src/Command/Command.php b/examples-per-language/php/behavioral/src/Command/Command.php index 3cc6c2a4..0db0dbad 100644 --- a/examples-per-language/php/behavioral/src/Command/Command.php +++ b/examples-per-language/php/behavioral/src/Command/Command.php @@ -9,4 +9,4 @@ public function execute(); public function undo(); public function redo(); -} \ No newline at end of file +} diff --git a/examples-per-language/php/behavioral/src/Command/RemoteControl.php b/examples-per-language/php/behavioral/src/Command/RemoteControl.php index 04f37b92..db98e57a 100644 --- a/examples-per-language/php/behavioral/src/Command/RemoteControl.php +++ b/examples-per-language/php/behavioral/src/Command/RemoteControl.php @@ -10,4 +10,4 @@ public function submit(Command $command) $command->execute(); } -} \ No newline at end of file +} diff --git a/examples-per-language/php/behavioral/src/Command/TurnOff.php b/examples-per-language/php/behavioral/src/Command/TurnOff.php index 51963109..cebbf94e 100644 --- a/examples-per-language/php/behavioral/src/Command/TurnOff.php +++ b/examples-per-language/php/behavioral/src/Command/TurnOff.php @@ -27,4 +27,4 @@ public function redo() { $this->execute(); } -} \ No newline at end of file +} diff --git a/examples-per-language/php/behavioral/src/Command/TurnOn.php b/examples-per-language/php/behavioral/src/Command/TurnOn.php index b3288714..f2c5b6bb 100644 --- a/examples-per-language/php/behavioral/src/Command/TurnOn.php +++ b/examples-per-language/php/behavioral/src/Command/TurnOn.php @@ -27,4 +27,4 @@ public function redo() { $this->execute(); } -} \ No newline at end of file +} diff --git a/examples-per-language/php/behavioral/src/Iterator/RadioStation.php b/examples-per-language/php/behavioral/src/Iterator/RadioStation.php index 32c44d07..e5f94544 100644 --- a/examples-per-language/php/behavioral/src/Iterator/RadioStation.php +++ b/examples-per-language/php/behavioral/src/Iterator/RadioStation.php @@ -16,4 +16,4 @@ public function getFrequency() { return $this->frequency; } -} \ No newline at end of file +} diff --git a/examples-per-language/php/behavioral/src/Iterator/StationList.php b/examples-per-language/php/behavioral/src/Iterator/StationList.php index c1a7bc05..18971145 100644 --- a/examples-per-language/php/behavioral/src/Iterator/StationList.php +++ b/examples-per-language/php/behavioral/src/Iterator/StationList.php @@ -58,4 +58,4 @@ public function count() { return count($this->stations); } -} \ No newline at end of file +} diff --git a/examples-per-language/php/creational/AbstractFactoryMethod.php b/examples-per-language/php/creational/AbstractFactoryMethod.php index 46fe3f99..2aa5de5c 100644 --- a/examples-per-language/php/creational/AbstractFactoryMethod.php +++ b/examples-per-language/php/creational/AbstractFactoryMethod.php @@ -20,4 +20,3 @@ $door->getDescription(); $expert->getDescription(); - diff --git a/examples-per-language/php/creational/Builder.php b/examples-per-language/php/creational/Builder.php index c432fef8..d649d0a7 100644 --- a/examples-per-language/php/creational/Builder.php +++ b/examples-per-language/php/creational/Builder.php @@ -10,4 +10,4 @@ ->addTomato() ->build(); -var_dump($burger); \ No newline at end of file +var_dump($burger); diff --git a/examples-per-language/php/creational/FactoryMethod.php b/examples-per-language/php/creational/FactoryMethod.php index 0fb030fa..5d6df106 100644 --- a/examples-per-language/php/creational/FactoryMethod.php +++ b/examples-per-language/php/creational/FactoryMethod.php @@ -9,4 +9,4 @@ $devManager->takeInterview(); $marketingManager = new MarketingManager(); -$marketingManager->takeInterview(); \ No newline at end of file +$marketingManager->takeInterview(); diff --git a/examples-per-language/php/creational/Prototype.php b/examples-per-language/php/creational/Prototype.php index 9332b36b..d61fcfd3 100644 --- a/examples-per-language/php/creational/Prototype.php +++ b/examples-per-language/php/creational/Prototype.php @@ -14,4 +14,3 @@ echo $cloned->getCategory() . PHP_EOL; echo 'Remember, you can use the magic method __clone to modify the behaviour of cloning the object!'; - diff --git a/examples-per-language/php/creational/SimpleFactory.php b/examples-per-language/php/creational/SimpleFactory.php index 882f0009..8fd444eb 100644 --- a/examples-per-language/php/creational/SimpleFactory.php +++ b/examples-per-language/php/creational/SimpleFactory.php @@ -6,4 +6,4 @@ $door = DoorFactory::makeDoor(100, 200); echo 'Width: ' . $door->getWidth() . PHP_EOL; -echo 'Height: ' . $door->getHeight() . PHP_EOL; \ No newline at end of file +echo 'Height: ' . $door->getHeight() . PHP_EOL; diff --git a/examples-per-language/php/creational/Singleton.php b/examples-per-language/php/creational/Singleton.php index 432fe28c..56527767 100644 --- a/examples-per-language/php/creational/Singleton.php +++ b/examples-per-language/php/creational/Singleton.php @@ -8,4 +8,4 @@ $president2 = President::getInstance(); echo 'Are both presidents 100% identical? '; -var_dump($president1 === $president2); \ No newline at end of file +var_dump($president1 === $president2); diff --git a/examples-per-language/php/creational/autoload.php b/examples-per-language/php/creational/autoload.php index 580cf4ba..fa8db82c 100644 --- a/examples-per-language/php/creational/autoload.php +++ b/examples-per-language/php/creational/autoload.php @@ -4,4 +4,4 @@ $explode = explode("\\", $className); $slice = array_slice($explode, -2, 2); require_once 'src' . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $slice) . '.php'; -}); \ No newline at end of file +}); diff --git a/examples-per-language/php/creational/src/AbstractFactory/Carpenter.php b/examples-per-language/php/creational/src/AbstractFactory/Carpenter.php index 921ce779..e7a9d466 100644 --- a/examples-per-language/php/creational/src/AbstractFactory/Carpenter.php +++ b/examples-per-language/php/creational/src/AbstractFactory/Carpenter.php @@ -10,4 +10,4 @@ public function getDescription() { echo 'I can only fit wooden doors' . PHP_EOL; } -} \ No newline at end of file +} diff --git a/examples-per-language/php/creational/src/AbstractFactory/Door.php b/examples-per-language/php/creational/src/AbstractFactory/Door.php index 20818252..bb802a39 100644 --- a/examples-per-language/php/creational/src/AbstractFactory/Door.php +++ b/examples-per-language/php/creational/src/AbstractFactory/Door.php @@ -7,4 +7,4 @@ interface Door { public function getDescription(); -} \ No newline at end of file +} diff --git a/examples-per-language/php/creational/src/AbstractFactory/DoorFactory.php b/examples-per-language/php/creational/src/AbstractFactory/DoorFactory.php index cabd864a..c62ef619 100644 --- a/examples-per-language/php/creational/src/AbstractFactory/DoorFactory.php +++ b/examples-per-language/php/creational/src/AbstractFactory/DoorFactory.php @@ -9,4 +9,4 @@ public function makeDoor(); public function makeFittingExpert(); -} \ No newline at end of file +} diff --git a/examples-per-language/php/creational/src/AbstractFactory/DoorFittingExpert.php b/examples-per-language/php/creational/src/AbstractFactory/DoorFittingExpert.php index ec0cd085..bb3bf0a2 100644 --- a/examples-per-language/php/creational/src/AbstractFactory/DoorFittingExpert.php +++ b/examples-per-language/php/creational/src/AbstractFactory/DoorFittingExpert.php @@ -6,4 +6,4 @@ interface DoorFittingExpert { public function getDescription(); -} \ No newline at end of file +} diff --git a/examples-per-language/php/creational/src/AbstractFactory/IronDoor.php b/examples-per-language/php/creational/src/AbstractFactory/IronDoor.php index e857f86e..c3912c97 100644 --- a/examples-per-language/php/creational/src/AbstractFactory/IronDoor.php +++ b/examples-per-language/php/creational/src/AbstractFactory/IronDoor.php @@ -10,4 +10,4 @@ public function getDescription() { echo 'I am an Iron Door!' . PHP_EOL; } -} \ No newline at end of file +} diff --git a/examples-per-language/php/creational/src/AbstractFactory/IronDoorFactory.php b/examples-per-language/php/creational/src/AbstractFactory/IronDoorFactory.php index 9bd25695..e4640a82 100644 --- a/examples-per-language/php/creational/src/AbstractFactory/IronDoorFactory.php +++ b/examples-per-language/php/creational/src/AbstractFactory/IronDoorFactory.php @@ -15,4 +15,4 @@ public function makeFittingExpert() { return new Welder(); } -} \ No newline at end of file +} diff --git a/examples-per-language/php/creational/src/AbstractFactory/Welder.php b/examples-per-language/php/creational/src/AbstractFactory/Welder.php index 344b6ec6..e86c1a42 100644 --- a/examples-per-language/php/creational/src/AbstractFactory/Welder.php +++ b/examples-per-language/php/creational/src/AbstractFactory/Welder.php @@ -10,4 +10,4 @@ public function getDescription() { echo 'I can only fit iron doors' . PHP_EOL; } -} \ No newline at end of file +} diff --git a/examples-per-language/php/creational/src/AbstractFactory/WoodenDoor.php b/examples-per-language/php/creational/src/AbstractFactory/WoodenDoor.php index 550c9365..e42b7537 100644 --- a/examples-per-language/php/creational/src/AbstractFactory/WoodenDoor.php +++ b/examples-per-language/php/creational/src/AbstractFactory/WoodenDoor.php @@ -10,4 +10,4 @@ public function getDescription() { echo 'I am a wooden door!' . PHP_EOL; } -} \ No newline at end of file +} diff --git a/examples-per-language/php/creational/src/AbstractFactory/WoodenDoorFactory.php b/examples-per-language/php/creational/src/AbstractFactory/WoodenDoorFactory.php index 2bed7634..abc1ba1a 100644 --- a/examples-per-language/php/creational/src/AbstractFactory/WoodenDoorFactory.php +++ b/examples-per-language/php/creational/src/AbstractFactory/WoodenDoorFactory.php @@ -15,4 +15,4 @@ public function makeFittingExpert() { return new Carpenter(); } -} \ No newline at end of file +} diff --git a/examples-per-language/php/creational/src/Builder/Burger.php b/examples-per-language/php/creational/src/Builder/Burger.php index 2c0fe70a..9c14efdd 100644 --- a/examples-per-language/php/creational/src/Builder/Burger.php +++ b/examples-per-language/php/creational/src/Builder/Burger.php @@ -20,4 +20,4 @@ public function __construct(BurgerBuilder $builder) $this->lettuce = $builder->lettuce; $this->tomato = $builder->tomato; } -} \ No newline at end of file +} diff --git a/examples-per-language/php/creational/src/Builder/BurgerBuilder.php b/examples-per-language/php/creational/src/Builder/BurgerBuilder.php index 7afabfbe..a5357b7b 100644 --- a/examples-per-language/php/creational/src/Builder/BurgerBuilder.php +++ b/examples-per-language/php/creational/src/Builder/BurgerBuilder.php @@ -47,4 +47,4 @@ public function build() return new Burger($this); } -} \ No newline at end of file +} diff --git a/examples-per-language/php/creational/src/FactoryMethod/CommunityExecutive.php b/examples-per-language/php/creational/src/FactoryMethod/CommunityExecutive.php index 5c972189..e6870e55 100644 --- a/examples-per-language/php/creational/src/FactoryMethod/CommunityExecutive.php +++ b/examples-per-language/php/creational/src/FactoryMethod/CommunityExecutive.php @@ -10,4 +10,4 @@ public function askQuestions() { echo 'Asking about community building!' . PHP_EOL; } -} \ No newline at end of file +} diff --git a/examples-per-language/php/creational/src/FactoryMethod/Developer.php b/examples-per-language/php/creational/src/FactoryMethod/Developer.php index 399f49c0..b9815c91 100644 --- a/examples-per-language/php/creational/src/FactoryMethod/Developer.php +++ b/examples-per-language/php/creational/src/FactoryMethod/Developer.php @@ -10,4 +10,4 @@ public function askQuestions() { echo 'Asking about Design Patterns!' . PHP_EOL; } -} \ No newline at end of file +} diff --git a/examples-per-language/php/creational/src/FactoryMethod/DevelopmentManager.php b/examples-per-language/php/creational/src/FactoryMethod/DevelopmentManager.php index 16b41420..82a7599c 100644 --- a/examples-per-language/php/creational/src/FactoryMethod/DevelopmentManager.php +++ b/examples-per-language/php/creational/src/FactoryMethod/DevelopmentManager.php @@ -10,4 +10,4 @@ public function makeInterviewer() { return new Developer(); } -} \ No newline at end of file +} diff --git a/examples-per-language/php/creational/src/FactoryMethod/HiringManager.php b/examples-per-language/php/creational/src/FactoryMethod/HiringManager.php index 06fdea15..42ce78a5 100644 --- a/examples-per-language/php/creational/src/FactoryMethod/HiringManager.php +++ b/examples-per-language/php/creational/src/FactoryMethod/HiringManager.php @@ -16,4 +16,4 @@ public function takeInterview() $interviewer = $this->makeInterviewer(); $interviewer->askQuestions(); } -} \ No newline at end of file +} diff --git a/examples-per-language/php/creational/src/FactoryMethod/Interviewer.php b/examples-per-language/php/creational/src/FactoryMethod/Interviewer.php index d3f0b6bb..9a284121 100644 --- a/examples-per-language/php/creational/src/FactoryMethod/Interviewer.php +++ b/examples-per-language/php/creational/src/FactoryMethod/Interviewer.php @@ -6,4 +6,4 @@ interface Interviewer { public function askQuestions(); -} \ No newline at end of file +} diff --git a/examples-per-language/php/creational/src/FactoryMethod/MarketingManager.php b/examples-per-language/php/creational/src/FactoryMethod/MarketingManager.php index af03c95e..eca85304 100644 --- a/examples-per-language/php/creational/src/FactoryMethod/MarketingManager.php +++ b/examples-per-language/php/creational/src/FactoryMethod/MarketingManager.php @@ -10,4 +10,4 @@ public function makeInterviewer() { return new CommunityExecutive(); } -} \ No newline at end of file +} diff --git a/examples-per-language/php/creational/src/Prototype/Sheep.php b/examples-per-language/php/creational/src/Prototype/Sheep.php index 60f82b13..13eda2ce 100644 --- a/examples-per-language/php/creational/src/Prototype/Sheep.php +++ b/examples-per-language/php/creational/src/Prototype/Sheep.php @@ -41,4 +41,4 @@ public function getCategory() return $this->category; } -} \ No newline at end of file +} diff --git a/examples-per-language/php/creational/src/SimpleFactory/Door.php b/examples-per-language/php/creational/src/SimpleFactory/Door.php index 1ac5d60d..7281d665 100644 --- a/examples-per-language/php/creational/src/SimpleFactory/Door.php +++ b/examples-per-language/php/creational/src/SimpleFactory/Door.php @@ -9,4 +9,4 @@ public function getWidth(); public function getHeight(); -} \ No newline at end of file +} diff --git a/examples-per-language/php/creational/src/SimpleFactory/DoorFactory.php b/examples-per-language/php/creational/src/SimpleFactory/DoorFactory.php index 51f6a04c..7b480957 100644 --- a/examples-per-language/php/creational/src/SimpleFactory/DoorFactory.php +++ b/examples-per-language/php/creational/src/SimpleFactory/DoorFactory.php @@ -11,4 +11,4 @@ public static function makeDoor($width, $height) return new WoodenDoor($width, $height); } -} \ No newline at end of file +} diff --git a/examples-per-language/php/creational/src/SimpleFactory/WoodenDoor.php b/examples-per-language/php/creational/src/SimpleFactory/WoodenDoor.php index cf2dd321..886ca271 100644 --- a/examples-per-language/php/creational/src/SimpleFactory/WoodenDoor.php +++ b/examples-per-language/php/creational/src/SimpleFactory/WoodenDoor.php @@ -25,4 +25,4 @@ public function getHeight() { return $this->height; } -} \ No newline at end of file +} diff --git a/examples-per-language/php/creational/src/Singleton/President.php b/examples-per-language/php/creational/src/Singleton/President.php index 22a0a9c0..3dbcce65 100644 --- a/examples-per-language/php/creational/src/Singleton/President.php +++ b/examples-per-language/php/creational/src/Singleton/President.php @@ -34,4 +34,5 @@ public static function getInstance() return self::$instance; } -} \ No newline at end of file +} + diff --git a/examples-per-language/php/structural/Adapter.php b/examples-per-language/php/structural/Adapter.php index f7dfd65f..16f5f15b 100644 --- a/examples-per-language/php/structural/Adapter.php +++ b/examples-per-language/php/structural/Adapter.php @@ -10,4 +10,4 @@ $wildDogAdapter = new WildDogAdapter($wildDog); $hunter = new Hunter(); -$hunter->hunt($wildDogAdapter); \ No newline at end of file +$hunter->hunt($wildDogAdapter); diff --git a/examples-per-language/php/structural/Bridge.php b/examples-per-language/php/structural/Bridge.php index 7dfab062..f1cbbb79 100644 --- a/examples-per-language/php/structural/Bridge.php +++ b/examples-per-language/php/structural/Bridge.php @@ -12,4 +12,4 @@ $careers = new Careers($darkTheme); echo $about->getContent() . PHP_EOL; -echo $careers->getContent() . PHP_EOL; \ No newline at end of file +echo $careers->getContent() . PHP_EOL; diff --git a/examples-per-language/php/structural/Composite.php b/examples-per-language/php/structural/Composite.php index 83574948..3c46654c 100644 --- a/examples-per-language/php/structural/Composite.php +++ b/examples-per-language/php/structural/Composite.php @@ -14,4 +14,4 @@ $organization->addEmployee($john); $organization->addEmployee($jane); -echo 'Net salaries ' . $organization->getNetSalaries() . PHP_EOL; \ No newline at end of file +echo 'Net salaries ' . $organization->getNetSalaries() . PHP_EOL; diff --git a/examples-per-language/php/structural/Decorator.php b/examples-per-language/php/structural/Decorator.php index 18dda301..1026f51f 100644 --- a/examples-per-language/php/structural/Decorator.php +++ b/examples-per-language/php/structural/Decorator.php @@ -21,4 +21,4 @@ $someCoffee = new VanillaCoffee($someCoffee); echo $someCoffee->getCost() . PHP_EOL; -echo $someCoffee->getDescription() . PHP_EOL; \ No newline at end of file +echo $someCoffee->getDescription() . PHP_EOL; diff --git a/examples-per-language/php/structural/Facade.php b/examples-per-language/php/structural/Facade.php index e3d3c5d3..cdb26f81 100644 --- a/examples-per-language/php/structural/Facade.php +++ b/examples-per-language/php/structural/Facade.php @@ -8,4 +8,4 @@ $computer = new ComputerFacade(new Computer()); $computer->turnOn(); -$computer->turnOff(); \ No newline at end of file +$computer->turnOff(); diff --git a/examples-per-language/php/structural/Flyweight.php b/examples-per-language/php/structural/Flyweight.php index 5ce010ce..4802e960 100644 --- a/examples-per-language/php/structural/Flyweight.php +++ b/examples-per-language/php/structural/Flyweight.php @@ -14,4 +14,4 @@ $shop->takeOrder('without sugar', 3); $shop->takeOrder('less sugar', 3); -$shop->serve(); \ No newline at end of file +$shop->serve(); diff --git a/examples-per-language/php/structural/Proxy.php b/examples-per-language/php/structural/Proxy.php index 4d756157..bb611a55 100644 --- a/examples-per-language/php/structural/Proxy.php +++ b/examples-per-language/php/structural/Proxy.php @@ -9,4 +9,4 @@ $door->open('invalid'); $door->open('$ecr@t'); -$door->close(); \ No newline at end of file +$door->close(); diff --git a/examples-per-language/php/structural/autoload.php b/examples-per-language/php/structural/autoload.php index a1139fb0..7216f597 100644 --- a/examples-per-language/php/structural/autoload.php +++ b/examples-per-language/php/structural/autoload.php @@ -5,4 +5,4 @@ $slice = array_slice($explode, -2, 2); require_once 'src' . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $slice) . '.php'; -}); \ No newline at end of file +}); diff --git a/examples-per-language/php/structural/src/Adapter/AfricanLion.php b/examples-per-language/php/structural/src/Adapter/AfricanLion.php index 8ad69cc7..22253dd0 100644 --- a/examples-per-language/php/structural/src/Adapter/AfricanLion.php +++ b/examples-per-language/php/structural/src/Adapter/AfricanLion.php @@ -9,4 +9,4 @@ class AfricanLion implements Lion public function roar() { } -} \ No newline at end of file +} diff --git a/examples-per-language/php/structural/src/Adapter/AsianLion.php b/examples-per-language/php/structural/src/Adapter/AsianLion.php index 557496cb..f1bd5156 100644 --- a/examples-per-language/php/structural/src/Adapter/AsianLion.php +++ b/examples-per-language/php/structural/src/Adapter/AsianLion.php @@ -9,4 +9,4 @@ public function roar() { } -} \ No newline at end of file +} diff --git a/examples-per-language/php/structural/src/Adapter/Hunter.php b/examples-per-language/php/structural/src/Adapter/Hunter.php index fdbdb754..b9968fa2 100644 --- a/examples-per-language/php/structural/src/Adapter/Hunter.php +++ b/examples-per-language/php/structural/src/Adapter/Hunter.php @@ -11,4 +11,4 @@ public function hunt(Lion $lion) echo "I'm hunting a " . get_class($lion) . PHP_EOL; } -} \ No newline at end of file +} diff --git a/examples-per-language/php/structural/src/Adapter/Lion.php b/examples-per-language/php/structural/src/Adapter/Lion.php index ec8cdc49..16f6846b 100644 --- a/examples-per-language/php/structural/src/Adapter/Lion.php +++ b/examples-per-language/php/structural/src/Adapter/Lion.php @@ -6,4 +6,4 @@ interface Lion { public function roar(); -} \ No newline at end of file +} diff --git a/examples-per-language/php/structural/src/Adapter/WildDog.php b/examples-per-language/php/structural/src/Adapter/WildDog.php index 87a64d4f..a74e194b 100644 --- a/examples-per-language/php/structural/src/Adapter/WildDog.php +++ b/examples-per-language/php/structural/src/Adapter/WildDog.php @@ -11,4 +11,4 @@ public function bark() } -} \ No newline at end of file +} diff --git a/examples-per-language/php/structural/src/Adapter/WildDogAdapter.php b/examples-per-language/php/structural/src/Adapter/WildDogAdapter.php index a13f957a..6cb3278b 100644 --- a/examples-per-language/php/structural/src/Adapter/WildDogAdapter.php +++ b/examples-per-language/php/structural/src/Adapter/WildDogAdapter.php @@ -17,4 +17,4 @@ public function roar() { $this->dog->bark(); } -} \ No newline at end of file +} diff --git a/examples-per-language/php/structural/src/Bridge/About.php b/examples-per-language/php/structural/src/Bridge/About.php index 053004be..453495d8 100644 --- a/examples-per-language/php/structural/src/Bridge/About.php +++ b/examples-per-language/php/structural/src/Bridge/About.php @@ -16,4 +16,4 @@ public function getContent() { return 'About page in ' . $this->theme->getColor(); } -} \ No newline at end of file +} diff --git a/examples-per-language/php/structural/src/Bridge/AquaTheme.php b/examples-per-language/php/structural/src/Bridge/AquaTheme.php index 36171f74..ca0aa914 100644 --- a/examples-per-language/php/structural/src/Bridge/AquaTheme.php +++ b/examples-per-language/php/structural/src/Bridge/AquaTheme.php @@ -10,4 +10,4 @@ public function getColor() { return 'Light blue'; } -} \ No newline at end of file +} diff --git a/examples-per-language/php/structural/src/Bridge/Careers.php b/examples-per-language/php/structural/src/Bridge/Careers.php index 6333f934..071a796b 100644 --- a/examples-per-language/php/structural/src/Bridge/Careers.php +++ b/examples-per-language/php/structural/src/Bridge/Careers.php @@ -16,4 +16,4 @@ public function getContent() { return 'Careers page in ' . $this->theme->getColor(); } -} \ No newline at end of file +} diff --git a/examples-per-language/php/structural/src/Bridge/DarkTheme.php b/examples-per-language/php/structural/src/Bridge/DarkTheme.php index 41588674..28c4dd55 100644 --- a/examples-per-language/php/structural/src/Bridge/DarkTheme.php +++ b/examples-per-language/php/structural/src/Bridge/DarkTheme.php @@ -10,4 +10,4 @@ public function getColor() { return 'Dark Black'; } -} \ No newline at end of file +} diff --git a/examples-per-language/php/structural/src/Bridge/LightTheme.php b/examples-per-language/php/structural/src/Bridge/LightTheme.php index 93c62576..4e52e2f9 100644 --- a/examples-per-language/php/structural/src/Bridge/LightTheme.php +++ b/examples-per-language/php/structural/src/Bridge/LightTheme.php @@ -10,4 +10,4 @@ public function getColor() { return 'Off white'; } -} \ No newline at end of file +} diff --git a/examples-per-language/php/structural/src/Bridge/Theme.php b/examples-per-language/php/structural/src/Bridge/Theme.php index 37a0d6eb..0d35da63 100644 --- a/examples-per-language/php/structural/src/Bridge/Theme.php +++ b/examples-per-language/php/structural/src/Bridge/Theme.php @@ -7,4 +7,4 @@ interface Theme { public function getColor(); -} \ No newline at end of file +} diff --git a/examples-per-language/php/structural/src/Bridge/WebPage.php b/examples-per-language/php/structural/src/Bridge/WebPage.php index 116f1a37..1855b6a0 100644 --- a/examples-per-language/php/structural/src/Bridge/WebPage.php +++ b/examples-per-language/php/structural/src/Bridge/WebPage.php @@ -10,4 +10,4 @@ public function __construct(Theme $theme); public function getContent(); -} \ No newline at end of file +} diff --git a/examples-per-language/php/structural/src/Composite/Designer.php b/examples-per-language/php/structural/src/Composite/Designer.php index 2dba2ffc..7584944b 100644 --- a/examples-per-language/php/structural/src/Composite/Designer.php +++ b/examples-per-language/php/structural/src/Composite/Designer.php @@ -31,4 +31,4 @@ public function getRoles() { return $this->roles; } -} \ No newline at end of file +} diff --git a/examples-per-language/php/structural/src/Composite/Developer.php b/examples-per-language/php/structural/src/Composite/Developer.php index 3e7f234b..6ee5c19c 100644 --- a/examples-per-language/php/structural/src/Composite/Developer.php +++ b/examples-per-language/php/structural/src/Composite/Developer.php @@ -34,4 +34,4 @@ public function getRoles() { return $this->roles; } -} \ No newline at end of file +} diff --git a/examples-per-language/php/structural/src/Composite/Employee.php b/examples-per-language/php/structural/src/Composite/Employee.php index 7064e183..a21d03ff 100644 --- a/examples-per-language/php/structural/src/Composite/Employee.php +++ b/examples-per-language/php/structural/src/Composite/Employee.php @@ -15,4 +15,4 @@ public function setSalary($salary); public function getSalary(); public function getRoles(); -} \ No newline at end of file +} diff --git a/examples-per-language/php/structural/src/Composite/Organization.php b/examples-per-language/php/structural/src/Composite/Organization.php index 623c2d4c..da4e5726 100644 --- a/examples-per-language/php/structural/src/Composite/Organization.php +++ b/examples-per-language/php/structural/src/Composite/Organization.php @@ -25,4 +25,4 @@ public function getNetSalaries() return $netSalary; } -} \ No newline at end of file +} diff --git a/examples-per-language/php/structural/src/Decorator/Coffee.php b/examples-per-language/php/structural/src/Decorator/Coffee.php index 85cfa3f5..b3e5bb4b 100644 --- a/examples-per-language/php/structural/src/Decorator/Coffee.php +++ b/examples-per-language/php/structural/src/Decorator/Coffee.php @@ -10,4 +10,4 @@ public function getCost(); public function getDescription(); -} \ No newline at end of file +} diff --git a/examples-per-language/php/structural/src/Decorator/MilkCoffee.php b/examples-per-language/php/structural/src/Decorator/MilkCoffee.php index 37606516..1ad96cc4 100644 --- a/examples-per-language/php/structural/src/Decorator/MilkCoffee.php +++ b/examples-per-language/php/structural/src/Decorator/MilkCoffee.php @@ -23,4 +23,4 @@ public function getDescription() { return $this->coffee->getDescription() . ', milk'; } -} \ No newline at end of file +} diff --git a/examples-per-language/php/structural/src/Decorator/SimpleCoffee.php b/examples-per-language/php/structural/src/Decorator/SimpleCoffee.php index a8df92d1..4bc880da 100644 --- a/examples-per-language/php/structural/src/Decorator/SimpleCoffee.php +++ b/examples-per-language/php/structural/src/Decorator/SimpleCoffee.php @@ -15,4 +15,4 @@ public function getDescription() { return 'Simple coffee'; } -} \ No newline at end of file +} diff --git a/examples-per-language/php/structural/src/Decorator/VanillaCoffee.php b/examples-per-language/php/structural/src/Decorator/VanillaCoffee.php index a2e6efbb..57c2f4ca 100644 --- a/examples-per-language/php/structural/src/Decorator/VanillaCoffee.php +++ b/examples-per-language/php/structural/src/Decorator/VanillaCoffee.php @@ -23,4 +23,4 @@ public function getDescription() { return $this->coffee->getDescription() . ', vanilla'; } -} \ No newline at end of file +} diff --git a/examples-per-language/php/structural/src/Decorator/WhipCoffee.php b/examples-per-language/php/structural/src/Decorator/WhipCoffee.php index 5fcba679..6b738ced 100644 --- a/examples-per-language/php/structural/src/Decorator/WhipCoffee.php +++ b/examples-per-language/php/structural/src/Decorator/WhipCoffee.php @@ -23,4 +23,4 @@ public function getDescription() { return $this->coffee->getDescription() . ', whip'; } -} \ No newline at end of file +} diff --git a/examples-per-language/php/structural/src/Facade/Computer.php b/examples-per-language/php/structural/src/Facade/Computer.php index 0d592b3a..841a8fff 100644 --- a/examples-per-language/php/structural/src/Facade/Computer.php +++ b/examples-per-language/php/structural/src/Facade/Computer.php @@ -41,4 +41,4 @@ public function sooth() echo 'zzzzzzz' . PHP_EOL; } -} \ No newline at end of file +} diff --git a/examples-per-language/php/structural/src/Facade/ComputerFacade.php b/examples-per-language/php/structural/src/Facade/ComputerFacade.php index 2821321e..49d37ef2 100644 --- a/examples-per-language/php/structural/src/Facade/ComputerFacade.php +++ b/examples-per-language/php/structural/src/Facade/ComputerFacade.php @@ -29,4 +29,4 @@ public function turnOff() } -} \ No newline at end of file +} diff --git a/examples-per-language/php/structural/src/Flyweight/KarakTea.php b/examples-per-language/php/structural/src/Flyweight/KarakTea.php index 2a0ab1a8..906ae8b6 100644 --- a/examples-per-language/php/structural/src/Flyweight/KarakTea.php +++ b/examples-per-language/php/structural/src/Flyweight/KarakTea.php @@ -7,4 +7,4 @@ class KarakTea { -} \ No newline at end of file +} diff --git a/examples-per-language/php/structural/src/Flyweight/TeaMaker.php b/examples-per-language/php/structural/src/Flyweight/TeaMaker.php index eff500f3..63045c6c 100644 --- a/examples-per-language/php/structural/src/Flyweight/TeaMaker.php +++ b/examples-per-language/php/structural/src/Flyweight/TeaMaker.php @@ -20,4 +20,4 @@ public function make($preference) return $this->availableTea[$preference]; } -} \ No newline at end of file +} diff --git a/examples-per-language/php/structural/src/Flyweight/TeaShop.php b/examples-per-language/php/structural/src/Flyweight/TeaShop.php index 79de029a..0255cc7f 100644 --- a/examples-per-language/php/structural/src/Flyweight/TeaShop.php +++ b/examples-per-language/php/structural/src/Flyweight/TeaShop.php @@ -31,4 +31,4 @@ public function serve() } -} \ No newline at end of file +} diff --git a/examples-per-language/php/structural/src/Proxy/Door.php b/examples-per-language/php/structural/src/Proxy/Door.php index bc6b82bc..6ba48c1d 100644 --- a/examples-per-language/php/structural/src/Proxy/Door.php +++ b/examples-per-language/php/structural/src/Proxy/Door.php @@ -10,4 +10,4 @@ public function open(); public function close(); -} \ No newline at end of file +} diff --git a/examples-per-language/php/structural/src/Proxy/LabDoor.php b/examples-per-language/php/structural/src/Proxy/LabDoor.php index dcf7d4e5..5a160fea 100644 --- a/examples-per-language/php/structural/src/Proxy/LabDoor.php +++ b/examples-per-language/php/structural/src/Proxy/LabDoor.php @@ -15,4 +15,4 @@ public function close() { echo 'Closing lab door ' . PHP_EOL; } -} \ No newline at end of file +} diff --git a/examples-per-language/php/structural/src/Proxy/Security.php b/examples-per-language/php/structural/src/Proxy/Security.php index 83f28e60..2a09c661 100644 --- a/examples-per-language/php/structural/src/Proxy/Security.php +++ b/examples-per-language/php/structural/src/Proxy/Security.php @@ -36,4 +36,4 @@ public function close() } -} \ No newline at end of file +} From e1f470a35b0f55fc730e755e02c88ff94f1914bb Mon Sep 17 00:00:00 2001 From: Bert Van de Casteele Date: Mon, 27 Feb 2017 22:47:38 +0100 Subject: [PATCH 21/28] Switched echo command with the actual action, per request @povils --- examples-per-language/php/structural/src/Proxy/Security.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples-per-language/php/structural/src/Proxy/Security.php b/examples-per-language/php/structural/src/Proxy/Security.php index 2a09c661..ace2411b 100644 --- a/examples-per-language/php/structural/src/Proxy/Security.php +++ b/examples-per-language/php/structural/src/Proxy/Security.php @@ -16,8 +16,8 @@ public function __construct(Door $door) public function open($password) { if ($this->authenticate($password)) { - $this->door->open(); echo 'Access granted!' . PHP_EOL; + $this->door->open(); } else { echo "Big no! It ain't possible!" . PHP_EOL; } From 2cf68642b8b456ed9c2762ee1464909b4dfe59c1 Mon Sep 17 00:00:00 2001 From: Bert Van de Casteele Date: Mon, 27 Feb 2017 23:08:23 +0100 Subject: [PATCH 22/28] Added Mediator example --- .../php/behavioral/Mediator.php | 14 ++++++++++ .../php/behavioral/src/Mediator/ChatRoom.php | 16 +++++++++++ .../src/Mediator/ChatRoomMediator.php | 9 +++++++ .../php/behavioral/src/Mediator/User.php | 27 +++++++++++++++++++ 4 files changed, 66 insertions(+) create mode 100644 examples-per-language/php/behavioral/Mediator.php create mode 100644 examples-per-language/php/behavioral/src/Mediator/ChatRoom.php create mode 100644 examples-per-language/php/behavioral/src/Mediator/ChatRoomMediator.php create mode 100644 examples-per-language/php/behavioral/src/Mediator/User.php diff --git a/examples-per-language/php/behavioral/Mediator.php b/examples-per-language/php/behavioral/Mediator.php new file mode 100644 index 00000000..9c02ba67 --- /dev/null +++ b/examples-per-language/php/behavioral/Mediator.php @@ -0,0 +1,14 @@ +send('Hi there!'); +$jane->send('Hey!'); diff --git a/examples-per-language/php/behavioral/src/Mediator/ChatRoom.php b/examples-per-language/php/behavioral/src/Mediator/ChatRoom.php new file mode 100644 index 00000000..ea40bab9 --- /dev/null +++ b/examples-per-language/php/behavioral/src/Mediator/ChatRoom.php @@ -0,0 +1,16 @@ +getName(); + + echo $time . '[' . $sender . ']:' . $message . PHP_EOL; + } +} diff --git a/examples-per-language/php/behavioral/src/Mediator/ChatRoomMediator.php b/examples-per-language/php/behavioral/src/Mediator/ChatRoomMediator.php new file mode 100644 index 00000000..b64bc350 --- /dev/null +++ b/examples-per-language/php/behavioral/src/Mediator/ChatRoomMediator.php @@ -0,0 +1,9 @@ +name = $name; + $this->chatMediator = $chatMediator; + } + + public function getName() + { + return $this->name; + } + + public function send($message) + { + $this->chatMediator->showMessage($this, $message); + } +} From 27d9a7661d2a3447aa19a849a08f3fe7695b95f8 Mon Sep 17 00:00:00 2001 From: Bert Van de Casteele Date: Mon, 27 Feb 2017 23:20:15 +0100 Subject: [PATCH 23/28] Added Memento example --- .../php/behavioral/Memento.php | 20 +++++++++++++ .../php/behavioral/src/Memento/Editor.php | 30 +++++++++++++++++++ .../behavioral/src/Memento/EditorMemento.php | 20 +++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 examples-per-language/php/behavioral/Memento.php create mode 100644 examples-per-language/php/behavioral/src/Memento/Editor.php create mode 100644 examples-per-language/php/behavioral/src/Memento/EditorMemento.php diff --git a/examples-per-language/php/behavioral/Memento.php b/examples-per-language/php/behavioral/Memento.php new file mode 100644 index 00000000..c4735154 --- /dev/null +++ b/examples-per-language/php/behavioral/Memento.php @@ -0,0 +1,20 @@ +type('This is the first sentence' . PHP_EOL); +$editor->type('This is the second sentence' . PHP_EOL); + +$saved = $editor->save(); + +$editor->type('And this is the third one.' . PHP_EOL); + +echo $editor->getContent(); + +$editor->restore($saved); +echo 'Restored $editor.' . PHP_EOL; +echo $editor->getContent(); diff --git a/examples-per-language/php/behavioral/src/Memento/Editor.php b/examples-per-language/php/behavioral/src/Memento/Editor.php new file mode 100644 index 00000000..c1a8e4a1 --- /dev/null +++ b/examples-per-language/php/behavioral/src/Memento/Editor.php @@ -0,0 +1,30 @@ +content; + } + + public function type($words) + { + $this->content = $this->content . ' ' . $words; + } + + public function save() + { + return new EditorMemento($this->content); + } + + public function restore(EditorMemento $memento) + { + $this->content = $memento->getContent(); + } + +} diff --git a/examples-per-language/php/behavioral/src/Memento/EditorMemento.php b/examples-per-language/php/behavioral/src/Memento/EditorMemento.php new file mode 100644 index 00000000..8df950b0 --- /dev/null +++ b/examples-per-language/php/behavioral/src/Memento/EditorMemento.php @@ -0,0 +1,20 @@ +content = $content; + } + + public function getContent() + { + return $this->content; + } + +} From b9b1fa64fad793eeb5056c92cc83a83f93e753d6 Mon Sep 17 00:00:00 2001 From: Bert Van de Casteele Date: Mon, 27 Feb 2017 23:45:13 +0100 Subject: [PATCH 24/28] Added Observer example --- .../php/behavioral/Observer.php | 16 +++++++++++ .../php/behavioral/src/Observer/JobPost.php | 21 +++++++++++++++ .../behavioral/src/Observer/JobPostings.php | 27 +++++++++++++++++++ .../php/behavioral/src/Observer/JobSeeker.php | 20 ++++++++++++++ .../behavioral/src/Observer/Observable.php | 11 ++++++++ .../php/behavioral/src/Observer/Observer.php | 9 +++++++ 6 files changed, 104 insertions(+) create mode 100644 examples-per-language/php/behavioral/Observer.php create mode 100644 examples-per-language/php/behavioral/src/Observer/JobPost.php create mode 100644 examples-per-language/php/behavioral/src/Observer/JobPostings.php create mode 100644 examples-per-language/php/behavioral/src/Observer/JobSeeker.php create mode 100644 examples-per-language/php/behavioral/src/Observer/Observable.php create mode 100644 examples-per-language/php/behavioral/src/Observer/Observer.php diff --git a/examples-per-language/php/behavioral/Observer.php b/examples-per-language/php/behavioral/Observer.php new file mode 100644 index 00000000..c6c0e42e --- /dev/null +++ b/examples-per-language/php/behavioral/Observer.php @@ -0,0 +1,16 @@ +attach($john); +$jobPostings->attach($jane); + +$jobPostings->add(new JobPost('Software Engineer')); diff --git a/examples-per-language/php/behavioral/src/Observer/JobPost.php b/examples-per-language/php/behavioral/src/Observer/JobPost.php new file mode 100644 index 00000000..3e1f46c4 --- /dev/null +++ b/examples-per-language/php/behavioral/src/Observer/JobPost.php @@ -0,0 +1,21 @@ +title = $title; + } + + public function getTitle() + { + return $this->title; + } + + +} diff --git a/examples-per-language/php/behavioral/src/Observer/JobPostings.php b/examples-per-language/php/behavioral/src/Observer/JobPostings.php new file mode 100644 index 00000000..b0971755 --- /dev/null +++ b/examples-per-language/php/behavioral/src/Observer/JobPostings.php @@ -0,0 +1,27 @@ +observers as $observer) { + $observer->onJobPosted($jobPosting); + } + } + + public function attach(Observer $observer) + { + $this->observers[] = $observer; + } + + public function add(JobPost $jobPosting) + { + $this->notify($jobPosting); + } +} diff --git a/examples-per-language/php/behavioral/src/Observer/JobSeeker.php b/examples-per-language/php/behavioral/src/Observer/JobSeeker.php new file mode 100644 index 00000000..7492776a --- /dev/null +++ b/examples-per-language/php/behavioral/src/Observer/JobSeeker.php @@ -0,0 +1,20 @@ +name = $name; + } + + public function onJobPosted(JobPost $job) + { + echo 'Hi ', $this->name . '! New job posted: ' . $job->getTitle() . PHP_EOL; + } +} diff --git a/examples-per-language/php/behavioral/src/Observer/Observable.php b/examples-per-language/php/behavioral/src/Observer/Observable.php new file mode 100644 index 00000000..860310dd --- /dev/null +++ b/examples-per-language/php/behavioral/src/Observer/Observable.php @@ -0,0 +1,11 @@ + Date: Thu, 2 Mar 2017 08:03:13 +0100 Subject: [PATCH 25/28] Added Visitor example --- .../php/behavioral/Visitor.php | 29 +++++++++++++++++++ .../php/behavioral/src/Visitor/Animal.php | 9 ++++++ .../src/Visitor/AnimalOperation.php | 12 ++++++++ .../php/behavioral/src/Visitor/Dolphin.php | 18 ++++++++++++ .../php/behavioral/src/Visitor/Jump.php | 23 +++++++++++++++ .../php/behavioral/src/Visitor/Lion.php | 18 ++++++++++++ .../php/behavioral/src/Visitor/Monkey.php | 18 ++++++++++++ .../php/behavioral/src/Visitor/Speak.php | 23 +++++++++++++++ 8 files changed, 150 insertions(+) create mode 100644 examples-per-language/php/behavioral/Visitor.php create mode 100644 examples-per-language/php/behavioral/src/Visitor/Animal.php create mode 100644 examples-per-language/php/behavioral/src/Visitor/AnimalOperation.php create mode 100644 examples-per-language/php/behavioral/src/Visitor/Dolphin.php create mode 100644 examples-per-language/php/behavioral/src/Visitor/Jump.php create mode 100644 examples-per-language/php/behavioral/src/Visitor/Lion.php create mode 100644 examples-per-language/php/behavioral/src/Visitor/Monkey.php create mode 100644 examples-per-language/php/behavioral/src/Visitor/Speak.php diff --git a/examples-per-language/php/behavioral/Visitor.php b/examples-per-language/php/behavioral/Visitor.php new file mode 100644 index 00000000..f9def424 --- /dev/null +++ b/examples-per-language/php/behavioral/Visitor.php @@ -0,0 +1,29 @@ +accept($speak); +$lion->accept($speak); +$dolphin->accept($speak); + +// Using the Visitor pattern it becomes easy to 'add' new functionality to +// the animals. Declare functionality in a class that implements Visitor. + +$jump = new Jump(); + +$monkey->accept($jump); +$lion->accept($jump); +$dolphin->accept($jump); \ No newline at end of file diff --git a/examples-per-language/php/behavioral/src/Visitor/Animal.php b/examples-per-language/php/behavioral/src/Visitor/Animal.php new file mode 100644 index 00000000..0874c53d --- /dev/null +++ b/examples-per-language/php/behavioral/src/Visitor/Animal.php @@ -0,0 +1,9 @@ +visitDolphin($this); + } + + public function speak() + { + echo '[High pitched ramblings about the end of the world].' . PHP_EOL; + } +} diff --git a/examples-per-language/php/behavioral/src/Visitor/Jump.php b/examples-per-language/php/behavioral/src/Visitor/Jump.php new file mode 100644 index 00000000..20d7394e --- /dev/null +++ b/examples-per-language/php/behavioral/src/Visitor/Jump.php @@ -0,0 +1,23 @@ +visitLion($this); + } + + public function roar() + { + echo 'Roarrrrrr!' . PHP_EOL; + } +} diff --git a/examples-per-language/php/behavioral/src/Visitor/Monkey.php b/examples-per-language/php/behavioral/src/Visitor/Monkey.php new file mode 100644 index 00000000..85bf16ce --- /dev/null +++ b/examples-per-language/php/behavioral/src/Visitor/Monkey.php @@ -0,0 +1,18 @@ +visitMonkey($this); + } + + public function shout() + { + echo 'Ooh oo Aa aa!' . PHP_EOL; + } +} diff --git a/examples-per-language/php/behavioral/src/Visitor/Speak.php b/examples-per-language/php/behavioral/src/Visitor/Speak.php new file mode 100644 index 00000000..831a146b --- /dev/null +++ b/examples-per-language/php/behavioral/src/Visitor/Speak.php @@ -0,0 +1,23 @@ +shout(); + } + + public function visitLion(Lion $lion) + { + $lion->roar(); + } + + public function visitDolphin(Dolphin $dolphin) + { + $dolphin->speak(); + } +} From 4190967f8e9e3222730b827f7e5c88efd9698cbf Mon Sep 17 00:00:00 2001 From: Bert Van de Casteele Date: Thu, 2 Mar 2017 08:12:09 +0100 Subject: [PATCH 26/28] Added Strategy example --- .../php/behavioral/Strategy.php | 15 ++++++++++++++ .../src/Strategy/BubbleSortStrategy.php | 17 ++++++++++++++++ .../src/Strategy/QuickSortStrategy.php | 17 ++++++++++++++++ .../behavioral/src/Strategy/SortStrategy.php | 9 +++++++++ .../php/behavioral/src/Strategy/Sorter.php | 20 +++++++++++++++++++ 5 files changed, 78 insertions(+) create mode 100644 examples-per-language/php/behavioral/Strategy.php create mode 100644 examples-per-language/php/behavioral/src/Strategy/BubbleSortStrategy.php create mode 100644 examples-per-language/php/behavioral/src/Strategy/QuickSortStrategy.php create mode 100644 examples-per-language/php/behavioral/src/Strategy/SortStrategy.php create mode 100644 examples-per-language/php/behavioral/src/Strategy/Sorter.php diff --git a/examples-per-language/php/behavioral/Strategy.php b/examples-per-language/php/behavioral/Strategy.php new file mode 100644 index 00000000..b84e1789 --- /dev/null +++ b/examples-per-language/php/behavioral/Strategy.php @@ -0,0 +1,15 @@ +sort($dataset); + +$sorter = new Sorter(new QuickSortStrategy()); +$sorter->sort($dataset); diff --git a/examples-per-language/php/behavioral/src/Strategy/BubbleSortStrategy.php b/examples-per-language/php/behavioral/src/Strategy/BubbleSortStrategy.php new file mode 100644 index 00000000..1d45420f --- /dev/null +++ b/examples-per-language/php/behavioral/src/Strategy/BubbleSortStrategy.php @@ -0,0 +1,17 @@ +sorter = $sorter; + } + + public function sort(array $dataset) + { + return $this->sorter->sort($dataset); + } + +} From 668d73d98d3f7029ab9cf7588d039c482a498f0a Mon Sep 17 00:00:00 2001 From: Bert Van de Casteele Date: Sun, 5 Mar 2017 18:11:35 +0100 Subject: [PATCH 27/28] Added State example --- .../php/behavioral/State.php | 22 ++++++++++++++++ .../php/behavioral/src/State/DefaultState.php | 13 ++++++++++ .../php/behavioral/src/State/LowerCase.php | 13 ++++++++++ .../php/behavioral/src/State/TextEditor.php | 26 +++++++++++++++++++ .../php/behavioral/src/State/UpperCase.php | 13 ++++++++++ .../php/behavioral/src/State/WritingState.php | 9 +++++++ 6 files changed, 96 insertions(+) create mode 100644 examples-per-language/php/behavioral/State.php create mode 100644 examples-per-language/php/behavioral/src/State/DefaultState.php create mode 100644 examples-per-language/php/behavioral/src/State/LowerCase.php create mode 100644 examples-per-language/php/behavioral/src/State/TextEditor.php create mode 100644 examples-per-language/php/behavioral/src/State/UpperCase.php create mode 100644 examples-per-language/php/behavioral/src/State/WritingState.php diff --git a/examples-per-language/php/behavioral/State.php b/examples-per-language/php/behavioral/State.php new file mode 100644 index 00000000..5b8645bc --- /dev/null +++ b/examples-per-language/php/behavioral/State.php @@ -0,0 +1,22 @@ +type('First line'); + +$editor->setState(new UpperCase()); + +$editor->type('Second line'); +$editor->type('Third line'); + +$editor->setState(new LowerCase()); + +$editor->type('Fourth line'); +$editor->type('Fifth line'); diff --git a/examples-per-language/php/behavioral/src/State/DefaultState.php b/examples-per-language/php/behavioral/src/State/DefaultState.php new file mode 100644 index 00000000..f288f014 --- /dev/null +++ b/examples-per-language/php/behavioral/src/State/DefaultState.php @@ -0,0 +1,13 @@ +state = $state; + } + + public function setState(WritingState $state) + { + $this->state = $state; + } + + public function type($words) + { + $this->state->write($words); + } + +} diff --git a/examples-per-language/php/behavioral/src/State/UpperCase.php b/examples-per-language/php/behavioral/src/State/UpperCase.php new file mode 100644 index 00000000..bb0c0174 --- /dev/null +++ b/examples-per-language/php/behavioral/src/State/UpperCase.php @@ -0,0 +1,13 @@ + Date: Sun, 5 Mar 2017 18:18:14 +0100 Subject: [PATCH 28/28] Added Template example --- .../php/behavioral/Template.php | 12 ++++++++ .../src/Template/AndroidBuilder.php | 28 +++++++++++++++++++ .../php/behavioral/src/Template/Builder.php | 20 +++++++++++++ .../behavioral/src/Template/IosBuilder.php | 28 +++++++++++++++++++ 4 files changed, 88 insertions(+) create mode 100644 examples-per-language/php/behavioral/Template.php create mode 100644 examples-per-language/php/behavioral/src/Template/AndroidBuilder.php create mode 100644 examples-per-language/php/behavioral/src/Template/Builder.php create mode 100644 examples-per-language/php/behavioral/src/Template/IosBuilder.php diff --git a/examples-per-language/php/behavioral/Template.php b/examples-per-language/php/behavioral/Template.php new file mode 100644 index 00000000..0dcbeb2f --- /dev/null +++ b/examples-per-language/php/behavioral/Template.php @@ -0,0 +1,12 @@ +build(); + +$iosBuilder = new IosBuilder(); +$iosBuilder->build(); diff --git a/examples-per-language/php/behavioral/src/Template/AndroidBuilder.php b/examples-per-language/php/behavioral/src/Template/AndroidBuilder.php new file mode 100644 index 00000000..3c187d2b --- /dev/null +++ b/examples-per-language/php/behavioral/src/Template/AndroidBuilder.php @@ -0,0 +1,28 @@ +test(); + $this->lint(); + $this->assemble(); + $this->deploy(); + } + + abstract public function test(); + abstract public function lint(); + abstract public function assemble(); + abstract public function deploy(); +} diff --git a/examples-per-language/php/behavioral/src/Template/IosBuilder.php b/examples-per-language/php/behavioral/src/Template/IosBuilder.php new file mode 100644 index 00000000..fec5219d --- /dev/null +++ b/examples-per-language/php/behavioral/src/Template/IosBuilder.php @@ -0,0 +1,28 @@ +