Completed
Push — master ( 1f36be...d8b059 )
by Beñat
03:59
created

AbstractTemplateFactory::templates()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
c 0
b 0
f 0
nc 1
1
<?php
2
3
/*
4
 * This file is part of the CMS Kernel library.
5
 *
6
 * Copyright (c) 2016 LIN3S <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace LIN3S\CMSKernel\Domain\Model\Page\Template;
13
14
/**
15
 * @author Beñat Espiña <[email protected]>
16
 */
17
abstract class AbstractTemplateFactory implements TemplateFactory
18
{
19
    abstract public function templates();
20
21
    public function build($name, array $content)
22
    {
23
        if (!array_key_exists($name, $this->templates())) {
24
            throw new TemplateNameDoesNotExistException($name);
25
        }
26
27
        return forward_static_call_array([$this->get($name), 'fromContent'], [new TemplateContent($content)]);
28
    }
29
30
    private function get($name)
31
    {
32
        if (array_key_exists($name, $this->templates())) {
33
            return $this->templates()[$name];
34
        }
35
    }
36
}
37