Passed
Pull Request — master (#190)
by Arman
03:12
created

Renderer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
/**
4
 * Quantum PHP Framework
5
 *
6
 * An open source software development framework for PHP
7
 *
8
 * @package Quantum
9
 * @author Arman Ag. <[email protected]>
10
 * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org)
11
 * @link http://quantum.softberg.org/
12
 * @since 2.9.5
13
 */
14
15
namespace Quantum\Renderer;
16
17
use Quantum\Renderer\Contracts\TemplateRendererInterface;
18
use Quantum\Renderer\Exceptions\RendererException;
19
use Quantum\Exceptions\BaseException;
20
21
/**
22
 * Class Renderer
23
 * @package Quantum\Renderer
24
 * @method string render(string $view, array $params = [])
25
 */
26
class Renderer
27
{
28
29
    /**
30
     * HTML adapter
31
     */
32
    const HTML = 'html';
33
34
    /**
35
     * Twig adapter
36
     */
37
    const TWIG = 'twig';
38
39
    /**
40
     * @var TemplateRendererInterface
41
     */
42
    private $adapter;
43
44
    /**
45
     * @param TemplateRendererInterface $adapter
46
     */
47
    public function __construct(TemplateRendererInterface $adapter)
48
    {
49
        $this->adapter = $adapter;
50
    }
51
52
    /**
53
     * @return TemplateRendererInterface
54
     */
55
    public function getAdapter(): TemplateRendererInterface
56
    {
57
        return $this->adapter;
58
    }
59
60
    /**
61
     * @param string $method
62
     * @param array|null $arguments
63
     * @return mixed
64
     * @throws BaseException
65
     */
66
    public function __call(string $method, ?array $arguments)
67
    {
68
        if (!method_exists($this->adapter, $method)) {
69
            throw RendererException::methodNotSupported($method, get_class($this->adapter));
70
        }
71
72
        return $this->adapter->$method(...$arguments);
73
    }
74
}