-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDecorator.php
56 lines (49 loc) · 1.61 KB
/
Decorator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/**
* @author Artemii Karkusha
* @copyright Copyright (c) (https://www.linkedin.com/in/artemiy-karkusha/)
*/
declare(strict_types=1);
namespace ArtemiiKarkusha\DesignPatterns\Controller\Test;
use ArtemiiKarkusha\DesignPatterns\Api\Decorator\Model\PizzaInterface;
use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\Controller\ResultFactory;
use ArtemiiKarkusha\DesignPatterns\Model\Decorator\PizzaWithoutAnything;
use ArtemiiKarkusha\DesignPatterns\Model\Decorator\PizzaWithCheeseDecorator;
use ArtemiiKarkusha\DesignPatterns\Model\Decorator\PizzaWithMushroomsDecorator;
use ArtemiiKarkusha\DesignPatterns\Model\Decorator\PizzaWithPineapplesDecorator;
use ArtemiiKarkusha\DesignPatterns\Model\Decorator\PizzaWithSeafoodDecorator;
use Magento\Framework\Controller\ResultInterface;
class Decorator implements HttpGetActionInterface
{
/**
* @param ResultFactory $resultFactory
*/
public function __construct(
private ResultFactory $resultFactory,
) {
}
/**
* @inheritDoc
*/
public function execute(): ResultInterface
{
return $this->resultFactory->create(ResultFactory::TYPE_RAW)
->setContents($this->getContents());
}
/**
* @return string
*/
public function getContents(): string
{
/** @var PizzaInterface $pizza */
$pizza = new PizzaWithoutAnything(
new PizzaWithCheeseDecorator(
new PizzaWithPineapplesDecorator(
new PizzaWithMushroomsDecorator()
)
)
);
return $pizza->getIngredients();
}
}