-
Notifications
You must be signed in to change notification settings - Fork 0
/
ViewImage.php
38 lines (30 loc) · 1.2 KB
/
ViewImage.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
<?php
namespace LaSalle\Rendimiento\JudithVilela\ImageRegister\Application\ViewImage;
use LaSalle\Rendimiento\JudithVilela\ImageRegister\Domain\ImageRegisterRepository;
use LaSalle\Rendimiento\JudithVilela\ImageRegister\Infrastructure\Persistence\Repository\RedisCacheRepository;
final class ViewImage
{
/** @var ImageRegisterRepository */
private $imageRegisterRepository;
/** @var RedisCacheRepository */
private $redisRepository;
/**
* @param ImageRegisterRepository $imageRegisterRepository
* @param RedisCacheRepository $redisRepository
*/
public function __construct(ImageRegisterRepository $imageRegisterRepository, RedisCacheRepository $redisRepository)
{
$this->imageRegisterRepository = $imageRegisterRepository;
$this->redisRepository = $redisRepository;
}
public function __invoke(): array
{
if ($this->redisRepository->find('images')) {
$images = $this->redisRepository->findAll('images');
} else {
$images = $this->imageRegisterRepository->findAll();
$this->redisRepository->saveAll('images', $images);
}
return $images;
}
}