-
Notifications
You must be signed in to change notification settings - Fork 453
/
Manager.php
56 lines (46 loc) · 1.51 KB
/
Manager.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
<?php
namespace Concrete\Core\Area\Layout\Preset\Provider;
use Concrete\Core\Area\Layout\Preset\InvalidPresetException;
use Concrete\Core\Area\Layout\Preset\PresetInterface;
class Manager
{
protected $providers = array();
public function register(ProviderInterface $provider)
{
$this->providers[$provider->getName()] = $provider;
}
public function unregister($nameOrObject)
{
$plugin = ($nameOrObject instanceof ProviderInterface) ? $nameOrObject : $this->providers[$nameOrObject];
unset($this->providers[$plugin->getName()]);
}
public function getByName($name)
{
return $this->providers[$name];
}
public function getProviders()
{
return $this->providers;
}
public function getPresets()
{
$presets = array();
foreach ($this->providers as $provider) {
$presets = array_merge($presets, $provider->getPresets());
}
array_map(function ($preset) {
if (!($preset instanceof PresetInterface)) {
throw new InvalidPresetException(t('Items returned by getPresets() must implement the PresetInterface'));
}
}, $presets);
return $presets;
}
public function getPresetByIdentifier($identifier)
{
$results = array_filter($this->getPresets(), function ($preset) use ($identifier) {
return $preset->getIdentifier() == $identifier;
});
$results = array_values($results);
return $results[0];
}
}