Passed
Pull Request — master (#48)
by Arman
03:56
created

DefaultRenderer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 36
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A render() 0 23 4
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.6.0
13
 */
14
15
namespace Quantum\Renderer;
16
17
use Quantum\Libraries\Storage\FileSystem;
18
use Quantum\Exceptions\ViewException;
19
use Quantum\Di\Di;
20
21
class DefaultRenderer implements TemplateRenderer
22
{
23
24
    /**
25
     * Renders the template
26
     * @param string $view
27
     * @param array $params
28
     * @param array $configs
29
     * @return string
30
     * @throws \Quantum\Exceptions\DiException
31
     * @throws \Quantum\Exceptions\ViewException
32
     * @throws \ReflectionException
33
     */
34
    public function render(string $view, array $params = [], array $configs = []): string
35
    {
36
        $fs = Di::get(FileSystem::class);
37
38
        $filePath = modules_dir() . DS . current_module() . DS . 'Views' . DS . $view . '.php';
39
40
        if (!$fs->exists($filePath)) {
41
            $filePath = base_dir() . DS . 'base' . DS . 'views' . DS . $view . '.php';
42
            if (!$fs->exists($filePath)) {
43
                throw ViewException::fileNotFound($view);
44
            }
45
        }
46
47
        ob_start();
48
        ob_implicit_flush(0);
49
50
        if (!empty($params)) {
51
            extract($params, EXTR_OVERWRITE);
52
        }
53
54
        require $filePath;
55
56
        return ob_get_clean();
57
    }
58
59
}