-
Notifications
You must be signed in to change notification settings - Fork 2
/
AdminManager.php
91 lines (80 loc) · 2.14 KB
/
AdminManager.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
namespace Snowcap\AdminBundle;
use Snowcap\AdminBundle\Admin\AdminInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* Environment admin service
*
*/
class AdminManager
{
/**
* @var string
*/
private $defaultTranslationDomain;
/**
* @var array
*/
private $admins = array();
/**
* @param string $alias
* @param \Snowcap\AdminBundle\Admin\AdminInterface $admin
* @param array
*/
public function registerAdmin($alias, AdminInterface $admin, array $options = array())
{
$admin->setAlias($alias);
$resolver = new OptionsResolver();
$admin->configureOptions($resolver);
$resolvedOptions = $resolver->resolve($options);
$admin->setOptions($resolvedOptions);
$this->admins[$alias] = $admin;
}
/**
* @param $alias
* @return \Snowcap\AdminBundle\Admin\AdminInterface
* @throws \InvalidArgumentException
*/
public function getAdmin($alias)
{
if (!array_key_exists($alias, $this->admins)) {
throw new \InvalidArgumentException(sprintf('The admin section %s has not been registered with the admin bundle', $alias));
}
return $this->admins[$alias];
}
/**
* @return array
*/
public function getAdmins()
{
return $this->admins;
}
/**
* @param object $entity
* @return AdminInterface|null
*/
public function getAdminForEntity($entity) //TODO: remove ?
{
$class = get_class($entity);
foreach($this->admins as $adminCode => $admin) {
if($admin instanceof \Snowcap\AdminBundle\Admin\ContentAdmin && $class === $admin->getEntityClass()) {
return $admin;
}
}
return null;
}
/**
* @param string $defaultTranslationDomain
*/
public function setDefaultTranslationDomain($defaultTranslationDomain)
{
$this->defaultTranslationDomain = $defaultTranslationDomain;
}
/**
* @return string
*/
public function getDefaultTranslationDomain()
{
return $this->defaultTranslationDomain;
}
}