Completed
Push — feature/fixing_cost ( 2c76a0...f58af6 )
by Laurent
01:38
created

WebController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 49
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A render() 0 8 2
A renderHtml() 0 3 1
A redirect() 0 10 2
1
<?php
2
3
4
namespace FlightLog\Http\Web\Controller;
5
6
7
use FlightLog\Http\Web\Requests\Request;
8
9
abstract class WebController
10
{
11
    /**
12
     * @var \DoliDB
13
     */
14
    protected $db;
15
16
    /**
17
     * @var Request
18
     */
19
    protected $request;
20
21
    public function __construct(\DoliDB $db)
22
    {
23
        $this->db = $db;
24
        $this->request = new Request();
25
    }
26
27
    protected function render($template, array $variables = []){
28
29
        foreach($variables as $variableName => $variableValue){
30
            $GLOBALS[$variableName] = $variableValue;
31
        }
32
33
        return include __DIR__.'/../templates/'.$template;
34
    }
35
36
    /**
37
     * @param string $html
38
     */
39
    protected function renderHtml($html){
40
        print $html;
41
    }
42
43
    /**
44
     * @param string $location
45
     */
46
    protected function redirect($location)
47
    {
48
        if (headers_sent()) {
49
            echo("<script>location.href='$location'</script>");
50
            return;
51
        }
52
53
        header("Location: $location");
54
        exit;
55
    }
56
57
}