1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Anax\View; |
4
|
|
|
|
5
|
|
|
use \Anax\Configure\ConfigureInterface; |
6
|
|
|
use \Anax\Configure\ConfigureTrait; |
7
|
|
|
use \Anax\DI\InjectionAwareInterface; |
8
|
|
|
use \Anax\DI\InjectionAwareTrait; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Render a view based on a template file and a dataset. |
12
|
|
|
*/ |
13
|
|
|
class ViewRenderFile2 implements |
14
|
|
|
ViewRenderFileInterface, |
15
|
|
|
ConfigureInterface, |
16
|
|
|
InjectionAwareInterface |
17
|
|
|
{ |
18
|
|
|
use ConfigureTrait, |
19
|
|
|
InjectionAwareTrait; |
20
|
|
|
|
21
|
|
|
|
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Render the view file. |
25
|
|
|
* |
26
|
|
|
* @param string $file to include as view file. |
27
|
|
|
* @param array $data to expose within the view. |
28
|
|
|
* |
29
|
|
|
* @throws \Anax\View\Exception when template file is not found. |
30
|
|
|
* |
31
|
|
|
* @return void |
32
|
|
|
* |
33
|
|
|
* @SuppressWarnings(PHPMD.UnusedLocalVariable) |
34
|
|
|
*/ |
35
|
|
View Code Duplication |
public function render($file, $data) |
|
|
|
|
36
|
|
|
{ |
37
|
|
|
if (!is_readable($file)) { |
38
|
|
|
throw new Exception("Could not find template file: " . $this->template); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
global $app; |
42
|
|
|
$di = $this->di; |
43
|
|
|
extract($data); |
44
|
|
|
require $file; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* TODO: Remove when updating oophp to new view classes. Its here for |
51
|
|
|
* backward compability with views from oophp that used the trait |
52
|
|
|
* ViewHelperTrait for view helpers which is now obsolete. |
53
|
|
|
*/ |
54
|
|
|
public function asset($url = "") |
55
|
|
|
{ |
56
|
|
|
return asset($url); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function url($url = "") |
60
|
|
|
{ |
61
|
|
|
return url($url); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function renderView($template, $data = []) |
65
|
|
|
{ |
66
|
|
|
return renderView($template, $data); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function regionHasContent($region) |
70
|
|
|
{ |
71
|
|
|
return regionHasContent($region); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function renderRegion($region) |
75
|
|
|
{ |
76
|
|
|
return renderRegion($region); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function classList(...$args) |
80
|
|
|
{ |
81
|
|
|
return classList($args); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function currentUrl() |
85
|
|
|
{ |
86
|
|
|
return currentUrl(); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function currentRoute() |
90
|
|
|
{ |
91
|
|
|
return currentRoute(); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.