Passed
Push — master ( 3e1455...cd0e92 )
by Peter
02:07
created

Block::hasAnyChangedSince()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Website\Template\Loader;
6
7
use AbterPhp\Framework\Template\IData;
8
use AbterPhp\Framework\Template\ILoader;
9
use AbterPhp\Framework\Template\Data;
10
use AbterPhp\Website\Databases\Queries\BlockCache;
11
use AbterPhp\Website\Orm\BlockRepo;
12
13
class Block implements ILoader
14
{
15
    /**
16
     * @var BlockRepo
17
     */
18
    protected $blockRepo;
19
20
    /**
21
     * @var BlockCache
22
     */
23
    protected $blockCache;
24
25
    /**
26
     * BlockLoader constructor.
27
     *
28
     * @param BlockRepo  $blockRepo
29
     * @param BlockCache $blockCache
30
     */
31
    public function __construct(BlockRepo $blockRepo, BlockCache $blockCache)
32
    {
33
        $this->blockRepo  = $blockRepo;
34
        $this->blockCache = $blockCache;
35
    }
36
37
    /**
38
     * @param string[] $identifiers
39
     *
40
     * @return IData[]
41
     */
42
    public function load(array $identifiers): array
43
    {
44
        $blocks = $this->blockRepo->getWithLayoutByIdentifiers($identifiers);
45
46
        $templateData = [];
47
        foreach ($blocks as $block) {
48
            $templateData[] = new Data(
49
                $block->getIdentifier(),
50
                ['title' => $block->getTitle()],
51
                ['body' => $block->getBody(), 'layout' => $block->getLayout()]
52
            );
53
        }
54
55
        return $templateData;
56
    }
57
58
    /**
59
     * @param string[] $identifiers
60
     * @param string   $cacheTime
61
     *
62
     * @return bool
63
     */
64
    public function hasAnyChangedSince(array $identifiers, string $cacheTime): bool
65
    {
66
        return $this->blockCache->hasAnyChangedSince($identifiers, $cacheTime);
67
    }
68
}
69