1 | <?php |
||
5 | class View implements ViewInterface |
||
6 | { |
||
7 | /** |
||
8 | * @var string $file The file to load. |
||
9 | */ |
||
10 | protected $file; |
||
11 | |||
12 | |||
13 | /** |
||
14 | * @var array $data The data to inject. |
||
15 | */ |
||
16 | protected $data = []; |
||
17 | |||
18 | |||
19 | /** |
||
20 | * @var RendererInterface $renderer The rendering engine. |
||
21 | */ |
||
22 | protected $renderer; |
||
23 | |||
24 | |||
25 | /** |
||
26 | * @param RendererInterface $renderer The rendering engine. |
||
27 | * @param string $file The file to load. |
||
28 | * @param array $data The data to inject. |
||
29 | */ |
||
30 | public function __construct(RendererInterface $renderer, $file, array $data = []) |
||
31 | { |
||
32 | $this->renderer = $renderer; |
||
33 | $this->file = $file; |
||
34 | $this->data = $data; |
||
35 | } |
||
36 | |||
37 | |||
38 | /** |
||
39 | * Binds data to the view. |
||
40 | * |
||
41 | * @param string $key The key. |
||
42 | * @param string $value The value. |
||
43 | */ |
||
44 | public function __set($key, $value) |
||
48 | |||
49 | |||
50 | /** |
||
51 | * Gets the view data |
||
52 | * |
||
53 | * @param string $key The key. |
||
54 | * @return mixed the view data. |
||
55 | */ |
||
56 | public function __get($key) |
||
60 | |||
61 | |||
62 | /** |
||
63 | * Binds data to the view. |
||
64 | * |
||
65 | * @param string $key The key. |
||
66 | * @param mixed $value The value. |
||
67 | */ |
||
68 | public function set($key, $value) |
||
72 | |||
73 | |||
74 | /** |
||
75 | * Gets the view data. |
||
76 | * |
||
77 | * @param string $key The key. |
||
78 | * @return mixed the view data. |
||
79 | */ |
||
80 | public function get($key) |
||
84 | |||
85 | |||
86 | /** |
||
87 | * Renders the view as a string. |
||
88 | * |
||
89 | * @return string The rendered view. |
||
90 | */ |
||
91 | public function __toString() |
||
95 | |||
96 | |||
97 | /** |
||
98 | * Renders the view. |
||
99 | * |
||
100 | * @throws \Exception |
||
101 | * @return string The rendered output. |
||
102 | */ |
||
103 | public function render() |
||
107 | } |
||
108 |