From 803e00600d7b921d44c81f49d659ea2478150bc4 Mon Sep 17 00:00:00 2001 From: Dmitry Aleynik <67788185+dm1tru@users.noreply.github.com> Date: Mon, 15 Apr 2024 16:25:43 +0300 Subject: [PATCH 1/8] Create .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..57872d0f1 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/vendor/ From 9f2c0d144f20adab7ade2b7b7ca5f298eb6a1688 Mon Sep 17 00:00:00 2001 From: Dmitry Aleynik <67788185+dm1tru@users.noreply.github.com> Date: Mon, 15 Apr 2024 16:26:19 +0300 Subject: [PATCH 2/8] Update .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 57872d0f1..8b90bd26d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ +.idea/ /vendor/ +.env From d546f31a17e7271f61fa427d52ccd91ad2b533fa Mon Sep 17 00:00:00 2001 From: Dmitry Aleynik <67788185+dm1tru@users.noreply.github.com> Date: Mon, 15 Apr 2024 16:27:35 +0300 Subject: [PATCH 3/8] add code --- .gitignore | 1 + README.md | 12 ++++- composer.json | 15 +++++++ index.php | 10 +++++ src/App.php | 30 +++++++++++++ src/Application/Adapter/PizzaAdapter.php | 31 +++++++++++++ src/Application/Builder/ProductBuilder.php | 44 +++++++++++++++++++ src/Application/Decorator/OnionDecorator.php | 26 +++++++++++ src/Application/Decorator/PepperDecorator.php | 26 +++++++++++ src/Application/Decorator/SaladDecorator.php | 26 +++++++++++ .../Factory/AbstractProductFactory.php | 14 ++++++ src/Application/Factory/BurgerFactory.php | 23 ++++++++++ src/Application/Factory/ProductFactory.php | 26 +++++++++++ src/Application/Publisher/Publisher.php | 27 ++++++++++++ .../Publisher/PublisherInterface.php | 15 +++++++ .../Publisher/SubscriberInterface.php | 10 +++++ src/Application/Services/CookingInterface.php | 13 ++++++ src/Application/Services/CookingService.php | 26 +++++++++++ src/Domain/Entity/Burger.php | 13 ++++++ src/Domain/Entity/Hotdog.php | 13 ++++++ src/Domain/Entity/Pizza.php | 12 +++++ src/Domain/Entity/Product.php | 21 +++++++++ src/Domain/Entity/ProductInterface.php | 10 +++++ src/Domain/Entity/Sandwich.php | 13 ++++++ 24 files changed, 455 insertions(+), 2 deletions(-) create mode 100644 composer.json create mode 100644 index.php create mode 100644 src/App.php create mode 100644 src/Application/Adapter/PizzaAdapter.php create mode 100644 src/Application/Builder/ProductBuilder.php create mode 100644 src/Application/Decorator/OnionDecorator.php create mode 100644 src/Application/Decorator/PepperDecorator.php create mode 100644 src/Application/Decorator/SaladDecorator.php create mode 100644 src/Application/Factory/AbstractProductFactory.php create mode 100644 src/Application/Factory/BurgerFactory.php create mode 100644 src/Application/Factory/ProductFactory.php create mode 100644 src/Application/Publisher/Publisher.php create mode 100644 src/Application/Publisher/PublisherInterface.php create mode 100644 src/Application/Publisher/SubscriberInterface.php create mode 100644 src/Application/Services/CookingInterface.php create mode 100644 src/Application/Services/CookingService.php create mode 100644 src/Domain/Entity/Burger.php create mode 100644 src/Domain/Entity/Hotdog.php create mode 100644 src/Domain/Entity/Pizza.php create mode 100644 src/Domain/Entity/Product.php create mode 100644 src/Domain/Entity/ProductInterface.php create mode 100644 src/Domain/Entity/Sandwich.php diff --git a/.gitignore b/.gitignore index 8b90bd26d..23a84b44d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea/ /vendor/ .env +/helpers/ \ No newline at end of file diff --git a/README.md b/README.md index e16b2a49b..0eb8a186d 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,11 @@ -# PHP_2023 +# Homework 16. Design patterns -https://otus.ru/lessons/razrabotchik-php/?utm_source=github&utm_medium=free&utm_campaign=otus + +Разрабатываем часть интернет-ресторана. Продаёт он фаст-фуд. + +1. Абстрактная фабрика будет отвечать за генерацию базового продукта-прототипа: бургер, сэндвич или хот-дог +2. При готовке каждого типа продукта Декоратор будет добавлять составляющие к базовому продукту либо по рецепту, либо по пожеланию клиента (салат, лук, перец и т.д.) +3. Наблюдатель подписывается на статус приготовления и отправляет оповещения о том, что изменился статус приготовления продукта. +4. Адаптер используем для сущности пицца. +5. Строитель будет отвечать за то, что нужно приготовить. +6. Все сущности должны по максимуму генерироваться через DI. diff --git a/composer.json b/composer.json new file mode 100644 index 000000000..0d72d3ad3 --- /dev/null +++ b/composer.json @@ -0,0 +1,15 @@ +{ + "name": "dmitry/hw16", + "type": "project", + "autoload": { + "psr-4": { + "Dmitry\\Hw16\\": "src/" + } + }, + "authors": [ + { + "name": "Dmitry Aleynik" + } + ], + "require": {} +} diff --git a/index.php b/index.php new file mode 100644 index 000000000..ba05fb85f --- /dev/null +++ b/index.php @@ -0,0 +1,10 @@ +run(); diff --git a/src/App.php b/src/App.php new file mode 100644 index 000000000..8999e4cbe --- /dev/null +++ b/src/App.php @@ -0,0 +1,30 @@ +createPizza(); + } + + private function createPizza(): void + { + $this->pizza = new Pizza(); + } + + public function getName(): string + { + return $this->pizza->getName(); + } + + public function makeCooked(): void + { + $this->pizza->makeCooked(); + } +} \ No newline at end of file diff --git a/src/Application/Builder/ProductBuilder.php b/src/Application/Builder/ProductBuilder.php new file mode 100644 index 000000000..5a042852b --- /dev/null +++ b/src/Application/Builder/ProductBuilder.php @@ -0,0 +1,44 @@ +product = $this->product; + } + + + public function addOnion(): self + { + $this->product = new OnionDecorator($this->product); + return $this; + } + + public function addPepper(): self + { + $this->product = new PepperDecorator($this->product); + return $this; + } + + + public function addSalad(): self + { + $this->product = new SaladDecorator($this->product); + return $this; + } + + + public function build(): ProductInterface + { + return $this->product; + } +} \ No newline at end of file diff --git a/src/Application/Decorator/OnionDecorator.php b/src/Application/Decorator/OnionDecorator.php new file mode 100644 index 000000000..455119211 --- /dev/null +++ b/src/Application/Decorator/OnionDecorator.php @@ -0,0 +1,26 @@ +product = $product; + } + + public function makeCooked(): void + { + $this->product->makeCooked(); + } + + public function getName(): string + { + return $this->product->getName() . ' с луком'; + } +} \ No newline at end of file diff --git a/src/Application/Decorator/PepperDecorator.php b/src/Application/Decorator/PepperDecorator.php new file mode 100644 index 000000000..ce9199cb3 --- /dev/null +++ b/src/Application/Decorator/PepperDecorator.php @@ -0,0 +1,26 @@ +product = $product; + } + + public function makeCooked(): void + { + $this->product->makeCooked(); + } + + public function getName(): string + { + return $this->product->getName() . ' с перцем'; + } +} \ No newline at end of file diff --git a/src/Application/Decorator/SaladDecorator.php b/src/Application/Decorator/SaladDecorator.php new file mode 100644 index 000000000..b80dd5614 --- /dev/null +++ b/src/Application/Decorator/SaladDecorator.php @@ -0,0 +1,26 @@ +product = $product; + } + + public function makeCooked(): void + { + $this->product->makeCooked(); + } + + public function getName(): string + { + return $this->product->getName() . ' с салатом'; + } +} \ No newline at end of file diff --git a/src/Application/Factory/AbstractProductFactory.php b/src/Application/Factory/AbstractProductFactory.php new file mode 100644 index 000000000..631bd223f --- /dev/null +++ b/src/Application/Factory/AbstractProductFactory.php @@ -0,0 +1,14 @@ +subscribers[] = $subscriber; + } + + public function unsubscribe(SubscriberInterface $subscriber): void + { + // TODO: Implement unsubscribe() method. + } + + public function notify($product, $status) + { + var_dump($product->getName() . ' - ' . $status); + foreach ($this->subscribers as $subscriber) { + $subscriber->notify($product, $status); + } + } +} \ No newline at end of file diff --git a/src/Application/Publisher/PublisherInterface.php b/src/Application/Publisher/PublisherInterface.php new file mode 100644 index 000000000..a1e0c3d61 --- /dev/null +++ b/src/Application/Publisher/PublisherInterface.php @@ -0,0 +1,15 @@ +publisher = $publisher; + } + + public function cook(ProductInterface $product): ProductInterface + { + $this->publisher->notify($product, 'Отправлен готовиться'); + $product->makeCooked(); + $this->publisher->notify($product, 'Приготовлен'); + return $product; + } +} \ No newline at end of file diff --git a/src/Domain/Entity/Burger.php b/src/Domain/Entity/Burger.php new file mode 100644 index 000000000..198f8b548 --- /dev/null +++ b/src/Domain/Entity/Burger.php @@ -0,0 +1,13 @@ +name = 'Бургер'; + } +} \ No newline at end of file diff --git a/src/Domain/Entity/Hotdog.php b/src/Domain/Entity/Hotdog.php new file mode 100644 index 000000000..c247de25a --- /dev/null +++ b/src/Domain/Entity/Hotdog.php @@ -0,0 +1,13 @@ +name = 'Хотдог'; + } +} \ No newline at end of file diff --git a/src/Domain/Entity/Pizza.php b/src/Domain/Entity/Pizza.php new file mode 100644 index 000000000..4926d5a54 --- /dev/null +++ b/src/Domain/Entity/Pizza.php @@ -0,0 +1,12 @@ +name = 'Пицца'; + } +} \ No newline at end of file diff --git a/src/Domain/Entity/Product.php b/src/Domain/Entity/Product.php new file mode 100644 index 000000000..48bb2645b --- /dev/null +++ b/src/Domain/Entity/Product.php @@ -0,0 +1,21 @@ +name; + } + + public function makeCooked(): void + { + $this->is_cooked = true; + } +} \ No newline at end of file diff --git a/src/Domain/Entity/ProductInterface.php b/src/Domain/Entity/ProductInterface.php new file mode 100644 index 000000000..3db930509 --- /dev/null +++ b/src/Domain/Entity/ProductInterface.php @@ -0,0 +1,10 @@ +name = 'Сэндвич'; + } +} \ No newline at end of file From 5da617602872b6a493a82f8a6a77d5cb41278b20 Mon Sep 17 00:00:00 2001 From: Dmitry Aleynik <67788185+dm1tru@users.noreply.github.com> Date: Mon, 15 Apr 2024 16:44:49 +0300 Subject: [PATCH 4/8] update code --- src/App.php | 19 +++++++++++---- .../Factory/AbstractProductFactory.php | 14 ----------- src/Application/Factory/BurgerFactory.php | 23 ------------------- src/Application/Factory/ProductFactory.php | 7 +++++- src/Application/UseCase/CookingUseCase.php | 19 +++++++++++++++ 5 files changed, 40 insertions(+), 42 deletions(-) delete mode 100644 src/Application/Factory/AbstractProductFactory.php delete mode 100644 src/Application/Factory/BurgerFactory.php create mode 100644 src/Application/UseCase/CookingUseCase.php diff --git a/src/App.php b/src/App.php index 8999e4cbe..e2915e241 100644 --- a/src/App.php +++ b/src/App.php @@ -11,20 +11,31 @@ use Dmitry\Hw16\Application\Factory\BurgerFactory; use Dmitry\Hw16\Application\Factory\ProductFactory; use Dmitry\Hw16\Application\Publisher\Publisher; +use Dmitry\Hw16\Application\Publisher\PublisherInterface; +use Dmitry\Hw16\Application\Services\CookingInterface; use Dmitry\Hw16\Application\Services\CookingService; +use Dmitry\Hw16\Domain\Entity\ProductInterface; class App { + private $useCase; + private CookingInterface $cookingService; + private array $products; + public function __construct() { - + $this->useCase = 'Dmitry\Hw16\Application\UseCase\CookingUseCase'; + $this->cookingService = new CookingService(new Publisher()); } public function run(): void { + $burger = ProductFactory::makeFood('burger'); + $sandwich = new PepperDecorator(new OnionDecorator(new SaladDecorator(ProductFactory::makeFood('sandwich')))); + $pizza = new PizzaAdapter(); - - + $useCase = new $this->useCase(); + $useCase($this->cookingService, $burger, $sandwich, $pizza); } -} \ No newline at end of file +} diff --git a/src/Application/Factory/AbstractProductFactory.php b/src/Application/Factory/AbstractProductFactory.php deleted file mode 100644 index 631bd223f..000000000 --- a/src/Application/Factory/AbstractProductFactory.php +++ /dev/null @@ -1,14 +0,0 @@ -cook($item); + } + } +} \ No newline at end of file From f79df769cad08f38775d3b5ccc3b18b279e11aa0 Mon Sep 17 00:00:00 2001 From: Dmitry Aleynik <67788185+dm1tru@users.noreply.github.com> Date: Mon, 15 Apr 2024 16:46:18 +0300 Subject: [PATCH 5/8] Update index.php --- index.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/index.php b/index.php index ba05fb85f..1dc9d88e9 100644 --- a/index.php +++ b/index.php @@ -6,5 +6,12 @@ use Dmitry\Hw16\App; -$app = new App(); -$app->run(); + +try { + $app = new App(); + $app->run(); +} catch (\Exception $e) { + throw new \Exception($e->getMessage()); +} + + From abe763fee4b29c30bc5e07b2c6a0d1728ffb5b7c Mon Sep 17 00:00:00 2001 From: Dmitry Aleynik <67788185+dm1tru@users.noreply.github.com> Date: Mon, 15 Apr 2024 16:48:22 +0300 Subject: [PATCH 6/8] update codestyle --- index.php | 2 -- src/Application/Adapter/PizzaAdapter.php | 2 +- src/Application/Builder/ProductBuilder.php | 2 +- src/Application/Decorator/OnionDecorator.php | 2 +- src/Application/Decorator/PepperDecorator.php | 2 +- src/Application/Decorator/SaladDecorator.php | 2 +- src/Application/Factory/ProductFactory.php | 2 +- src/Application/Publisher/Publisher.php | 2 +- src/Application/Publisher/PublisherInterface.php | 2 +- src/Application/Publisher/SubscriberInterface.php | 2 +- src/Application/Services/CookingInterface.php | 2 +- src/Application/Services/CookingService.php | 3 +-- src/Application/UseCase/CookingUseCase.php | 9 ++++----- src/Domain/Entity/Burger.php | 2 +- src/Domain/Entity/Hotdog.php | 2 +- src/Domain/Entity/Pizza.php | 3 +-- src/Domain/Entity/Product.php | 2 +- src/Domain/Entity/ProductInterface.php | 2 +- src/Domain/Entity/Sandwich.php | 2 +- 19 files changed, 21 insertions(+), 26 deletions(-) diff --git a/index.php b/index.php index 1dc9d88e9..3623b3741 100644 --- a/index.php +++ b/index.php @@ -13,5 +13,3 @@ } catch (\Exception $e) { throw new \Exception($e->getMessage()); } - - diff --git a/src/Application/Adapter/PizzaAdapter.php b/src/Application/Adapter/PizzaAdapter.php index 74ef8ec61..f9a5f22a0 100644 --- a/src/Application/Adapter/PizzaAdapter.php +++ b/src/Application/Adapter/PizzaAdapter.php @@ -28,4 +28,4 @@ public function makeCooked(): void { $this->pizza->makeCooked(); } -} \ No newline at end of file +} diff --git a/src/Application/Builder/ProductBuilder.php b/src/Application/Builder/ProductBuilder.php index 5a042852b..e416ca40e 100644 --- a/src/Application/Builder/ProductBuilder.php +++ b/src/Application/Builder/ProductBuilder.php @@ -41,4 +41,4 @@ public function build(): ProductInterface { return $this->product; } -} \ No newline at end of file +} diff --git a/src/Application/Decorator/OnionDecorator.php b/src/Application/Decorator/OnionDecorator.php index 455119211..f5e2f27b0 100644 --- a/src/Application/Decorator/OnionDecorator.php +++ b/src/Application/Decorator/OnionDecorator.php @@ -23,4 +23,4 @@ public function getName(): string { return $this->product->getName() . ' с луком'; } -} \ No newline at end of file +} diff --git a/src/Application/Decorator/PepperDecorator.php b/src/Application/Decorator/PepperDecorator.php index ce9199cb3..383331501 100644 --- a/src/Application/Decorator/PepperDecorator.php +++ b/src/Application/Decorator/PepperDecorator.php @@ -23,4 +23,4 @@ public function getName(): string { return $this->product->getName() . ' с перцем'; } -} \ No newline at end of file +} diff --git a/src/Application/Decorator/SaladDecorator.php b/src/Application/Decorator/SaladDecorator.php index b80dd5614..4c371d3cf 100644 --- a/src/Application/Decorator/SaladDecorator.php +++ b/src/Application/Decorator/SaladDecorator.php @@ -23,4 +23,4 @@ public function getName(): string { return $this->product->getName() . ' с салатом'; } -} \ No newline at end of file +} diff --git a/src/Application/Factory/ProductFactory.php b/src/Application/Factory/ProductFactory.php index fccab9a87..04b54ff42 100644 --- a/src/Application/Factory/ProductFactory.php +++ b/src/Application/Factory/ProductFactory.php @@ -28,4 +28,4 @@ public static function makeFood(string $type): Product break; } } -} \ No newline at end of file +} diff --git a/src/Application/Publisher/Publisher.php b/src/Application/Publisher/Publisher.php index 51646571c..3edd4ed03 100644 --- a/src/Application/Publisher/Publisher.php +++ b/src/Application/Publisher/Publisher.php @@ -24,4 +24,4 @@ public function notify($product, $status) $subscriber->notify($product, $status); } } -} \ No newline at end of file +} diff --git a/src/Application/Publisher/PublisherInterface.php b/src/Application/Publisher/PublisherInterface.php index a1e0c3d61..954cb752f 100644 --- a/src/Application/Publisher/PublisherInterface.php +++ b/src/Application/Publisher/PublisherInterface.php @@ -12,4 +12,4 @@ public function subscribe(SubscriberInterface $subscriber): void; public function unsubscribe(SubscriberInterface $subscriber): void; public function notify(Product $product, string $status); -} \ No newline at end of file +} diff --git a/src/Application/Publisher/SubscriberInterface.php b/src/Application/Publisher/SubscriberInterface.php index 932403701..9f5c5dc96 100644 --- a/src/Application/Publisher/SubscriberInterface.php +++ b/src/Application/Publisher/SubscriberInterface.php @@ -7,4 +7,4 @@ interface SubscriberInterface { public function notify(Product $product, string $status); -} \ No newline at end of file +} diff --git a/src/Application/Services/CookingInterface.php b/src/Application/Services/CookingInterface.php index 62e4f0125..79fc86efc 100644 --- a/src/Application/Services/CookingInterface.php +++ b/src/Application/Services/CookingInterface.php @@ -10,4 +10,4 @@ interface CookingInterface public function __construct(PublisherInterface $publisher); public function cook(ProductInterface $product): ProductInterface; -} \ No newline at end of file +} diff --git a/src/Application/Services/CookingService.php b/src/Application/Services/CookingService.php index 59060cb47..c62b8e802 100644 --- a/src/Application/Services/CookingService.php +++ b/src/Application/Services/CookingService.php @@ -2,7 +2,6 @@ namespace Dmitry\Hw16\Application\Services; - use Dmitry\Hw16\Application\Publisher\PublisherInterface; use Dmitry\Hw16\Domain\Entity\ProductInterface; @@ -23,4 +22,4 @@ public function cook(ProductInterface $product): ProductInterface $this->publisher->notify($product, 'Приготовлен'); return $product; } -} \ No newline at end of file +} diff --git a/src/Application/UseCase/CookingUseCase.php b/src/Application/UseCase/CookingUseCase.php index 9f07d42c7..448229543 100644 --- a/src/Application/UseCase/CookingUseCase.php +++ b/src/Application/UseCase/CookingUseCase.php @@ -8,12 +8,11 @@ class CookingUseCase { public function __invoke( - CookingInterface $cookingService, - ProductInterface ...$product - ) - { + CookingInterface $cookingService, + ProductInterface ...$product + ) { foreach ($product as $item) { $cookingService->cook($item); } } -} \ No newline at end of file +} diff --git a/src/Domain/Entity/Burger.php b/src/Domain/Entity/Burger.php index 198f8b548..9ad29a61b 100644 --- a/src/Domain/Entity/Burger.php +++ b/src/Domain/Entity/Burger.php @@ -10,4 +10,4 @@ public function __construct() { $this->name = 'Бургер'; } -} \ No newline at end of file +} diff --git a/src/Domain/Entity/Hotdog.php b/src/Domain/Entity/Hotdog.php index c247de25a..a2acc6c9e 100644 --- a/src/Domain/Entity/Hotdog.php +++ b/src/Domain/Entity/Hotdog.php @@ -10,4 +10,4 @@ public function __construct() { $this->name = 'Хотдог'; } -} \ No newline at end of file +} diff --git a/src/Domain/Entity/Pizza.php b/src/Domain/Entity/Pizza.php index 4926d5a54..8856b7cc6 100644 --- a/src/Domain/Entity/Pizza.php +++ b/src/Domain/Entity/Pizza.php @@ -2,11 +2,10 @@ namespace Dmitry\Hw16\Domain\Entity; - class Pizza extends Product { public function __construct() { $this->name = 'Пицца'; } -} \ No newline at end of file +} diff --git a/src/Domain/Entity/Product.php b/src/Domain/Entity/Product.php index 48bb2645b..bedb2e0cd 100644 --- a/src/Domain/Entity/Product.php +++ b/src/Domain/Entity/Product.php @@ -18,4 +18,4 @@ public function makeCooked(): void { $this->is_cooked = true; } -} \ No newline at end of file +} diff --git a/src/Domain/Entity/ProductInterface.php b/src/Domain/Entity/ProductInterface.php index 3db930509..71d1aff19 100644 --- a/src/Domain/Entity/ProductInterface.php +++ b/src/Domain/Entity/ProductInterface.php @@ -7,4 +7,4 @@ interface ProductInterface public function getName(): string; public function makeCooked(): void; -} \ No newline at end of file +} diff --git a/src/Domain/Entity/Sandwich.php b/src/Domain/Entity/Sandwich.php index ff0f501c7..248bbd8d1 100644 --- a/src/Domain/Entity/Sandwich.php +++ b/src/Domain/Entity/Sandwich.php @@ -10,4 +10,4 @@ public function __construct() { $this->name = 'Сэндвич'; } -} \ No newline at end of file +} From aab8351410d2d40c9f8721f933de44e13682cc2f Mon Sep 17 00:00:00 2001 From: Dmitry Aleynik <67788185+dm1tru@users.noreply.github.com> Date: Mon, 15 Apr 2024 16:51:35 +0300 Subject: [PATCH 7/8] update codestyle --- src/App.php | 3 --- src/Application/Decorator/OnionDecorator.php | 1 - src/Application/Decorator/PepperDecorator.php | 1 - src/Application/Decorator/SaladDecorator.php | 1 - src/Application/Publisher/Publisher.php | 1 - src/Application/Services/CookingService.php | 1 - 6 files changed, 8 deletions(-) diff --git a/src/App.php b/src/App.php index e2915e241..70a44f4f6 100644 --- a/src/App.php +++ b/src/App.php @@ -11,14 +11,11 @@ use Dmitry\Hw16\Application\Factory\BurgerFactory; use Dmitry\Hw16\Application\Factory\ProductFactory; use Dmitry\Hw16\Application\Publisher\Publisher; -use Dmitry\Hw16\Application\Publisher\PublisherInterface; use Dmitry\Hw16\Application\Services\CookingInterface; use Dmitry\Hw16\Application\Services\CookingService; -use Dmitry\Hw16\Domain\Entity\ProductInterface; class App { - private $useCase; private CookingInterface $cookingService; private array $products; diff --git a/src/Application/Decorator/OnionDecorator.php b/src/Application/Decorator/OnionDecorator.php index f5e2f27b0..3bb857a9f 100644 --- a/src/Application/Decorator/OnionDecorator.php +++ b/src/Application/Decorator/OnionDecorator.php @@ -6,7 +6,6 @@ class OnionDecorator implements ProductInterface { - private $product; public function __construct($product) diff --git a/src/Application/Decorator/PepperDecorator.php b/src/Application/Decorator/PepperDecorator.php index 383331501..b0d8dfb33 100644 --- a/src/Application/Decorator/PepperDecorator.php +++ b/src/Application/Decorator/PepperDecorator.php @@ -6,7 +6,6 @@ class PepperDecorator implements ProductInterface { - private $product; public function __construct($product) diff --git a/src/Application/Decorator/SaladDecorator.php b/src/Application/Decorator/SaladDecorator.php index 4c371d3cf..71ded8d10 100644 --- a/src/Application/Decorator/SaladDecorator.php +++ b/src/Application/Decorator/SaladDecorator.php @@ -6,7 +6,6 @@ class SaladDecorator implements ProductInterface { - private $product; public function __construct($product) diff --git a/src/Application/Publisher/Publisher.php b/src/Application/Publisher/Publisher.php index 3edd4ed03..60099c4c3 100644 --- a/src/Application/Publisher/Publisher.php +++ b/src/Application/Publisher/Publisher.php @@ -4,7 +4,6 @@ class Publisher implements PublisherInterface { - private $subscribers = []; public function subscribe(SubscriberInterface $subscriber): void diff --git a/src/Application/Services/CookingService.php b/src/Application/Services/CookingService.php index c62b8e802..0bc1188ed 100644 --- a/src/Application/Services/CookingService.php +++ b/src/Application/Services/CookingService.php @@ -7,7 +7,6 @@ class CookingService implements CookingInterface { - private PublisherInterface $publisher; public function __construct(PublisherInterface $publisher) From 593627a18fe4ec139f824237927cb1259029e54e Mon Sep 17 00:00:00 2001 From: Dmitry Aleynik <67788185+dm1tru@users.noreply.github.com> Date: Tue, 16 Apr 2024 21:46:48 +0300 Subject: [PATCH 8/8] working on comments --- src/App.php | 9 +++------ src/Application/Publisher/Publisher.php | 4 ++-- src/Domain/Entity/Pizza.php | 15 ++++++++++++++- src/Domain/Entity/Product.php | 2 +- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/App.php b/src/App.php index 70a44f4f6..24b71cacd 100644 --- a/src/App.php +++ b/src/App.php @@ -13,16 +13,14 @@ use Dmitry\Hw16\Application\Publisher\Publisher; use Dmitry\Hw16\Application\Services\CookingInterface; use Dmitry\Hw16\Application\Services\CookingService; +use Dmitry\Hw16\Application\UseCase\CookingUseCase; class App { - private $useCase; private CookingInterface $cookingService; - private array $products; public function __construct() { - $this->useCase = 'Dmitry\Hw16\Application\UseCase\CookingUseCase'; $this->cookingService = new CookingService(new Publisher()); } @@ -31,8 +29,7 @@ public function run(): void $burger = ProductFactory::makeFood('burger'); $sandwich = new PepperDecorator(new OnionDecorator(new SaladDecorator(ProductFactory::makeFood('sandwich')))); $pizza = new PizzaAdapter(); - - $useCase = new $this->useCase(); - $useCase($this->cookingService, $burger, $sandwich, $pizza); + $usecase = new CookingUseCase(); + $usecase($this->cookingService, $burger, $sandwich, $pizza); } } diff --git a/src/Application/Publisher/Publisher.php b/src/Application/Publisher/Publisher.php index 60099c4c3..a6f1bca1e 100644 --- a/src/Application/Publisher/Publisher.php +++ b/src/Application/Publisher/Publisher.php @@ -8,12 +8,12 @@ class Publisher implements PublisherInterface public function subscribe(SubscriberInterface $subscriber): void { - $this->subscribers[] = $subscriber; + $this->subscribers[spl_object_id($subscriber)] = $subscriber; } public function unsubscribe(SubscriberInterface $subscriber): void { - // TODO: Implement unsubscribe() method. + unset($this->subscribers[spl_object_id($subscriber)]); } public function notify($product, $status) diff --git a/src/Domain/Entity/Pizza.php b/src/Domain/Entity/Pizza.php index 8856b7cc6..51a927fa0 100644 --- a/src/Domain/Entity/Pizza.php +++ b/src/Domain/Entity/Pizza.php @@ -2,10 +2,23 @@ namespace Dmitry\Hw16\Domain\Entity; -class Pizza extends Product +class Pizza implements ProductInterface { + private string $name; + private bool $is_cooked = false; + public function __construct() { $this->name = 'Пицца'; } + + public function getName(): string + { + return $this->name; + } + + public function makeCooked(): void + { + $this->is_cooked = true; + } } diff --git a/src/Domain/Entity/Product.php b/src/Domain/Entity/Product.php index bedb2e0cd..36c7f033b 100644 --- a/src/Domain/Entity/Product.php +++ b/src/Domain/Entity/Product.php @@ -5,7 +5,7 @@ abstract class Product implements ProductInterface { protected $name; - private $is_cooked = false; + private bool $is_cooked = false; abstract public function __construct();