Passed
Push — master ( 003724...f241d1 )
by Brent
02:47
created

TemplateEngineFactory::getDefault()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Brendt\Stitcher\Factory;
4
5
use Brendt\Stitcher\Exception\UnknownEngineException;
6
use Brendt\Stitcher\Template\TemplateEngine;
7
use Symfony\Component\DependencyInjection\ContainerInterface;
8
9
class TemplateEngineFactory
10
{
11
    const SMARTY_ENGINE = 'smarty';
12
    const TWIG_ENGINE = 'twig';
13
14
    /**
15
     * @var ContainerInterface
16
     */
17
    private $container;
18
19
    /**
20
     * @var string
21
     */
22
    private $templateEngine;
23
24
    /**
25
     * TemplateEngineFactory constructor.
26
     *
27
     * @param ContainerInterface $container
28
     * @param string             $templateEngine
29
     */
30
    public function __construct(ContainerInterface $container, string $templateEngine) {
31
        $this->container = $container;
32
        $this->templateEngine = $templateEngine;
33
    }
34
35
    /**
36
     * @param $type
37
     *
38
     * @return mixed
39
     *
40
     * @throws UnknownEngineException
41
     */
42
    public function getByType($type) : TemplateEngine {
43
        switch ($type) {
44
            case self::TWIG_ENGINE:
45
                return $this->container->get('service.twig');
46
            case self::SMARTY_ENGINE:
47
                return $this->container->get('service.smarty');
48
            default:
49
                throw new UnknownEngineException();
50
        }
51
    }
52
53
    /**
54
     * @return TemplateEngine
55
     */
56
    public function getDefault() : TemplateEngine {
57
        return $this->getByType($this->templateEngine);
58
    }
59
60
}
61