-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObserver.php
More file actions
61 lines (54 loc) · 1.66 KB
/
Observer.php
File metadata and controls
61 lines (54 loc) · 1.66 KB
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
57
58
59
60
61
<?php
/**
* @author Artemii Karkusha
* @copyright Copyright (c) (https://www.linkedin.com/in/artemiy-karkusha/)
*/
declare(strict_types=1);
namespace ArtemiiKarkusha\DesignPatterns\Controller\Test;
use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\Controller\ResultFactory;
use ArtemiiKarkusha\DesignPatterns\Api\Observer\WeatherServiceInterface;
use ArtemiiKarkusha\DesignPatterns\Api\Observer\WeatherNotifierInterface;
use Magento\Framework\Controller\ResultInterface;
class Observer implements HttpGetActionInterface
{
/**
*
* @param ResultFactory $resultFactory
* @param WeatherServiceInterface $weatherService
* @param WeatherNotifierInterface $weatherNotifier
*/
public function __construct(
readonly private ResultFactory $resultFactory,
readonly private WeatherServiceInterface $weatherService,
readonly private WeatherNotifierInterface $weatherNotifier
) {
}
/**
* @inheritDoc
*/
public function execute(): ResultInterface
{
$this->getContents();
return $this->resultFactory->create(ResultFactory::TYPE_RAW);
}
/**
* @return void
*/
public function getContents(): void
{
$locations = ['Bratislava', 'Wien', 'Vinesia'];
foreach ($locations as $location) {
$this->cronWhichCheckWeatherByLocation($location);
}
}
/**
* @param string $location
* @return void
*/
private function cronWhichCheckWeatherByLocation(string $location): void
{
$storm = $this->weatherService->getStormInfo($location);
$this->weatherNotifier->notify($storm);
}
}