-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMetaRegistry.php
61 lines (52 loc) · 1.11 KB
/
MetaRegistry.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
<?php
namespace FDevs\MetaPage;
use FDevs\MetaPage\Type\MetaTypeInterface;
class MetaRegistry
{
/**
* @var MetaTypeInterface[]
*/
private $metaTypeList = [];
/**
* MetaRegistry constructor.
*
* @param Type\MetaTypeInterface[] $metaTypeList
*/
public function __construct(array $metaTypeList = [])
{
foreach ($metaTypeList as $type) {
$this->addType($type);
}
}
/**
* @param MetaTypeInterface $metaType
*
* @return $this
*/
public function addType(MetaTypeInterface $metaType)
{
$this->metaTypeList[get_class($metaType)] = $metaType;
return $this;
}
/**
* @param string $type
*
* @return bool
*/
public function hasType($type)
{
return isset($this->metaTypeList[$type]);
}
/**
* @param string $type
*
* @return MetaTypeInterface
*/
public function getType($type)
{
if (!$this->hasType($type)) {
$this->metaTypeList[$type] = new $type();
}
return $this->metaTypeList[$type];
}
}