-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSectionFactory.php
More file actions
52 lines (41 loc) · 1.21 KB
/
SectionFactory.php
File metadata and controls
52 lines (41 loc) · 1.21 KB
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
<?php
namespace Optime\Commtool\TemplateBundle;
use Symfony\Component\DependencyInjection\ContainerInterface;
class SectionFactory
{
/**
*
* @var ContainerInterface
*/
protected $container;
protected $validSections;
protected $sections = array();
function __construct(ContainerInterface $container, array $validSections = array())
{
$this->container = $container;
$this->validSections = $validSections;
}
public function getTypes()
{
return array_keys($this->validSections);
}
public function getType($name)
{
if (!isset($this->validSections[$name])) {
throw new \Exception("No existe la sección de nombre $name");
}
if (count($this->sections)) {
return $this->sections[$this->validSections[$name]];
}
return $this->container->get($this->validSections[$name]);
}
public function getSections()
{
if (count($this->sections) === 0) {
foreach ($this->validSections as $name => $serviceId) {
$this->sections[$name] = $this->container->get($this->validSections[$name]);
}
}
return $this->sections;
}
}