-
Notifications
You must be signed in to change notification settings - Fork 136
/
Copy pathTemplatePool.php
66 lines (60 loc) · 1.46 KB
/
TemplatePool.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
57
58
59
60
61
62
63
64
65
66
<?php
/**
* Copyright © Magefan (support@magefan.com). All rights reserved.
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
*
* Glory to Ukraine! Glory to the heroes!
*/
declare(strict_types=1);
namespace Magefan\Blog\Model;
/**
* Blog Template Pool
*
* @api
* @since 2.10.0
*/
class TemplatePool
{
/**
* Templates objects
*
* @var []
*/
private $templates;
/**
* TemplatePool constructor.
* @param array $templates
*/
public function __construct(array $templates)
{
$this->templates = $templates;
}
/**
* Retrieve all templates for type
* @param $templateType
* @return array
*/
public function getAll(string $templateType):array
{
return $this->templates[$templateType] ?? [];
}
/**
* Retrieve template
* @param string $templateType
* @param string $name
* @return string
*/
public function getTemplate(string $templateType, string $name):string
{
if (isset($this->templates[$templateType]) &&
(is_array($this->templates[$templateType]) || $this->templates[$templateType] instanceof Countable)
) {
foreach ($this->templates[$templateType] as $item) {
if (isset($item['value']) && $item['value'] == $name) {
return $item['template'];
}
}
}
return '';
}
}