Conditions | 6 |
Paths | 6 |
Total Lines | 43 |
Code Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
16 | public function render() |
||
17 | { |
||
18 | // Ensure that the directory exists |
||
19 | if (!is_dir($this->directory)) { |
||
20 | throw new \Exception("Could not find directory when rendering view: \"{$this->directory}\""); |
||
21 | } |
||
22 | |||
23 | // Ensure that the selected template file exists |
||
24 | $path = $this->directory . '/' . $this->file; |
||
25 | |||
26 | if (!is_file($path)) { |
||
27 | throw new \Exception("Could not find file when rendering view: \"$path\""); |
||
28 | } |
||
29 | |||
30 | // Change the working directory |
||
31 | $cwd = null; |
||
32 | |||
33 | if ($this->directory) { |
||
34 | $cwd = getcwd(); |
||
35 | chdir($this->directory); |
||
36 | } |
||
37 | |||
38 | // Change error reporting |
||
39 | $error_reporting = error_reporting(); |
||
40 | error_reporting(error_reporting() & ~E_NOTICE & ~E_WARNING); |
||
41 | |||
42 | // Extract view arguments |
||
43 | extract($this->arguments); |
||
44 | |||
45 | // Run the template |
||
46 | ob_start(); |
||
47 | include $this->file; |
||
48 | $output = ob_get_clean(); |
||
49 | |||
50 | // Restore the working directory |
||
51 | if ($this->directory && $cwd) { |
||
52 | chdir($cwd); |
||
53 | } |
||
54 | |||
55 | // Restore error reporting |
||
56 | error_reporting($error_reporting); |
||
57 | |||
58 | return $output; |
||
59 | } |
||
61 |