/
ElementManager.php
59 lines (52 loc) · 1.49 KB
/
ElementManager.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
<?php
namespace Concrete\Core\Filesystem;
class ElementManager
{
/**
* @var \Concrete\Core\Filesystem\Element[]
*/
protected $registry = [];
/**
* @param string $element the element name
* @param \Concrete\Core\Page\Page $page
* @param array $elementArguments the arguments to be used when calling the constructor of the element controller
* @param string $pkgHandle the handle of the package defining this element
*
* @return \Concrete\Core\Filesystem\Element
*/
public function get($element)
{
if (isset($this->registry[$element])) {
$o = $this->registry[$element];
if ($o instanceof \Closure) {
$element = $o();
} else {
$element = $o;
}
$element->populateFromArguments(func_get_args());
return $element;
} else {
$class = new \ReflectionClass(Element::class);
return $class->newInstanceArgs(func_get_args());
}
}
/**
* Register an element.
*
* @param string $element the element name
* @param \Concrete\Core\Filesystem\Element $object the element instance
*/
public function register($element, $object)
{
$this->registry[$element] = $object;
}
/**
* Unregister an element.
*
* @param string $element the element name
*/
public function unregister($element)
{
unset($this->registry[$element]);
}
}