-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f5c02a7
commit c0c7f36
Showing
27 changed files
with
642 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
FROM php:8.2-fpm | ||
|
||
RUN mkdir -p /var/www/otusphp.local | ||
|
||
WORKDIR /var/www/otusphp.local | ||
|
||
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer | ||
|
||
RUN pecl install xdebug-3.3.0 \ | ||
&& docker-php-ext-enable xdebug | ||
|
||
RUN chown -R www-data:www-data /var/www/otusphp.local | ||
COPY ./xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini | ||
|
||
CMD ["php-fpm"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[xdebug] | ||
zend_extension=xdebug.so | ||
xdebug.mode=debug | ||
xdebug.client_host=host.docker.internal | ||
xdebug.client_port=54321 | ||
xdebug.log=/var/www/otusphp.local/xdebug.log | ||
xdebug.start_with_request=yes | ||
xdebug.idekey=PHPSTORM |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
version: "3" | ||
services: | ||
php-fpm: | ||
container_name: php-fpm | ||
build: ./.docker/php-fpm | ||
volumes: | ||
- ./www:/var/www/otusphp.local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "shabanov/otusphp", | ||
"autoload": { | ||
"psr-4": { | ||
"Shabanov\\Otusphp\\": "src/" | ||
} | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Shabanov Vyacheslav", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
require_once __DIR__ . '/../vendor/autoload.php'; | ||
|
||
use Shabanov\Otusphp\App; | ||
|
||
try { | ||
(new App())->run(); | ||
} catch (\Exception $e) { | ||
throw new \Exception($e->getMessage()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace Shabanov\Otusphp\Adapter; | ||
|
||
use Shabanov\Otusphp\Builder\ProductBuilder; | ||
use Shabanov\Otusphp\Entity\Pizza; | ||
use Shabanov\Otusphp\Interfaces\ProductInterface; | ||
use Shabanov\Otusphp\Observer\Event; | ||
use Shabanov\Otusphp\Services\Cooking; | ||
|
||
class PizzaAdapter | ||
{ | ||
private ProductInterface $pizza; | ||
private Cooking $cooking; | ||
public function __construct(private Event $event) | ||
{ | ||
$this->createPizza(); | ||
$this->cooking = new Cooking($this->pizza, $this->event); | ||
} | ||
|
||
private function createPizza(): void | ||
{ | ||
$this->pizza = (new ProductBuilder(new Pizza())) | ||
->addSalad() | ||
->addOnion() | ||
->build(); | ||
} | ||
|
||
public function cook(): void | ||
{ | ||
$this->cooking->run(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace Shabanov\Otusphp; | ||
|
||
use Shabanov\Otusphp\Adapter\PizzaAdapter; | ||
use Shabanov\Otusphp\Builder\ProductBuilder; | ||
use Shabanov\Otusphp\Decorator\OnionIngradient; | ||
use Shabanov\Otusphp\Decorator\PepperIngradient; | ||
use Shabanov\Otusphp\Decorator\SaladIngradient; | ||
use Shabanov\Otusphp\Entity\Client; | ||
use Shabanov\Otusphp\Interfaces\ProductInterface; | ||
use Shabanov\Otusphp\Observer\Event; | ||
use Shabanov\Otusphp\Services\Cooking; | ||
|
||
class App | ||
{ | ||
private const PRODUCT = 'Shabanov\Otusphp\Fabrics\BurgerFabric'; | ||
private Event $event; | ||
public function __construct() {} | ||
Check failure on line 19 in hw16/www/src/App.php GitHub Actions / phpcs
|
||
|
||
public function run() | ||
{ | ||
/** | ||
* Создадим клиентов и слушатель событий | ||
*/ | ||
$this->createClients(); | ||
/** | ||
* Создадим продукт | ||
*/ | ||
$product = $this->createProduct(); | ||
$product = (new ProductBuilder($product)) | ||
->addOnion() | ||
->addPepper() | ||
->addSalad() | ||
->build(); | ||
/** | ||
* Приготовим продукт | ||
*/ | ||
$cooking = new Cooking($product, $this->event); | ||
$cooking->run(); | ||
/** | ||
* Пиццу приготовим через адаптер | ||
*/ | ||
$pizzaAdapter = new PizzaAdapter($this->event); | ||
$pizzaAdapter->cook(); | ||
} | ||
|
||
private function createProduct(): ProductInterface | ||
{ | ||
return self::PRODUCT::createProduct(); | ||
} | ||
|
||
private function createClients(): void | ||
{ | ||
$client1 = new Client('Вячеслав'); | ||
$client2 = new Client('Сергей'); | ||
$this->event = new Event(); | ||
$this->event->addSubscriber($client1) | ||
->addSubscriber($client2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Shabanov\Otusphp\Builder; | ||
|
||
use Shabanov\Otusphp\Decorator\OnionIngradient; | ||
use Shabanov\Otusphp\Decorator\PepperIngradient; | ||
use Shabanov\Otusphp\Decorator\SaladIngradient; | ||
use Shabanov\Otusphp\Interfaces\ProductInterface; | ||
|
||
class ProductBuilder | ||
{ | ||
public function __construct(private ProductInterface $product) {} | ||
Check failure on line 12 in hw16/www/src/Builder/ProductBuilder.php GitHub Actions / phpcs
|
||
|
||
public function addOnion(): self | ||
{ | ||
$this->product = new OnionIngradient($this->product); | ||
return $this; | ||
} | ||
|
||
public function addPepper(): self | ||
{ | ||
$this->product = new PepperIngradient($this->product); | ||
return $this; | ||
} | ||
|
||
public function addSalad(): self | ||
{ | ||
$this->product = new SaladIngradient($this->product); | ||
return $this; | ||
} | ||
|
||
public function build(): ProductInterface | ||
{ | ||
return $this->product; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace Shabanov\Otusphp\Decorator; | ||
|
||
use Shabanov\Otusphp\Interfaces\ProductInterface; | ||
|
||
abstract class AbstractIngradients implements ProductInterface | ||
{ | ||
public function __construct(private readonly ProductInterface $product) {} | ||
Check failure on line 9 in hw16/www/src/Decorator/AbstractIngradients.php GitHub Actions / phpcs
|
||
|
||
public function getInfo(): string | ||
{ | ||
return $this->product->getInfo(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Shabanov\Otusphp\Decorator; | ||
|
||
use Shabanov\Otusphp\Interfaces\ProductInterface; | ||
|
||
class MultipleIngradients extends AbstractIngradients | ||
{ | ||
public function __construct(private ProductInterface $product, | ||
private array $ingradients | ||
) { | ||
foreach ($this->ingradients as $ingradient) { | ||
$this->product = new $ingradient($this->product); | ||
} | ||
} | ||
|
||
public function getInfo(): string | ||
{ | ||
return $this->product->getInfo(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Shabanov\Otusphp\Decorator; | ||
|
||
class OnionIngradient extends AbstractIngradients | ||
{ | ||
|
||
public function getInfo(): string | ||
{ | ||
return parent::getInfo() . ' с луком'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace Shabanov\Otusphp\Decorator; | ||
|
||
class PepperIngradient extends AbstractIngradients | ||
{ | ||
public function getInfo(): string | ||
{ | ||
return parent::getInfo() . ' с перцем'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Shabanov\Otusphp\Decorator; | ||
|
||
class SaladIngradient extends AbstractIngradients | ||
{ | ||
|
||
public function getInfo(): string | ||
{ | ||
return parent::getInfo() . ' с салатом'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Shabanov\Otusphp\Entity; | ||
|
||
use Shabanov\Otusphp\Interfaces\ProductInterface; | ||
|
||
class Burger implements ProductInterface | ||
{ | ||
|
||
public function getInfo(): string | ||
{ | ||
return 'Бургер'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace Shabanov\Otusphp\Entity; | ||
|
||
use Shabanov\Otusphp\Interfaces\ObserverInterface; | ||
|
||
class Client implements ObserverInterface | ||
{ | ||
public function __construct(private string $name) {} | ||
|
||
|
||
public function update($product, $status): void | ||
{ | ||
echo $this->name . ': Статус приготовления ' . $product->getInfo() . ' -- ' . $status . PHP_EOL; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Shabanov\Otusphp\Entity; | ||
|
||
use Shabanov\Otusphp\Interfaces\ProductInterface; | ||
|
||
class HotDog implements ProductInterface | ||
{ | ||
|
||
public function getInfo(): string | ||
{ | ||
return 'Хот дог'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace Shabanov\Otusphp\Entity; | ||
|
||
use Shabanov\Otusphp\Interfaces\ProductInterface; | ||
|
||
class Pizza implements ProductInterface | ||
{ | ||
public function getInfo(): string | ||
{ | ||
return 'Пицца'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Shabanov\Otusphp\Entity; | ||
|
||
use Shabanov\Otusphp\Interfaces\ProductInterface; | ||
|
||
class Sandwich implements ProductInterface | ||
{ | ||
|
||
public function getInfo(): string | ||
{ | ||
return 'Сэндвич'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace Shabanov\Otusphp\Fabrics; | ||
|
||
use Shabanov\Otusphp\Interfaces\ProductInterface; | ||
|
||
abstract class AbstractProductFabric | ||
{ | ||
abstract public static function createProduct(): ProductInterface; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace Shabanov\Otusphp\Fabrics; | ||
|
||
use Shabanov\Otusphp\Entity\Burger; | ||
use Shabanov\Otusphp\Interfaces\ProductInterface; | ||
|
||
class BurgerFabric extends AbstractProductFabric | ||
{ | ||
|
||
public static function createProduct(): ProductInterface | ||
{ | ||
return new Burger(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace Shabanov\Otusphp\Fabrics; | ||
|
||
use Shabanov\Otusphp\Entity\HotDog; | ||
use Shabanov\Otusphp\Interfaces\ProductInterface; | ||
|
||
class HotDogFabric extends AbstractProductFabric | ||
{ | ||
|
||
public static function createProduct(): ProductInterface | ||
{ | ||
return new HotDog(); | ||
} | ||
} |
Oops, something went wrong.