|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* KNUT7 K7F (https://marciozebedeu.com/) |
|
5
|
|
|
* KNUT7 K7F (tm) : Rapid Development Framework (https://marciozebedeu.com/). |
|
6
|
|
|
* |
|
7
|
|
|
* Licensed under The MIT License |
|
8
|
|
|
* For full copyright and license information, please see the LICENSE.txt |
|
9
|
|
|
* Redistributions of files must retain the above copyright notice. |
|
10
|
|
|
* |
|
11
|
|
|
* @see https://github.com/knut7/framework/ for the canonical source repository |
|
12
|
|
|
* |
|
13
|
|
|
* @copyright (c) 2015. KNUT7 Software Technologies AO Inc. (https://marciozebedeu.com/) |
|
14
|
|
|
* @license https://marciozebedeu.com/license/new-bsd New BSD License |
|
15
|
|
|
* @author Marcio Zebedeu - [email protected] |
|
16
|
|
|
* |
|
17
|
|
|
* @version 1.0.2 |
|
18
|
|
|
* |
|
19
|
|
|
* Includes - Ability to include other views |
|
20
|
|
|
* |
|
21
|
|
|
* Captures - Ability to easily capture content within your view |
|
22
|
|
|
* |
|
23
|
|
|
* Layouts - Ability to inject data into a re-usable layout template |
|
24
|
|
|
* |
|
25
|
|
|
* Fetching - Ability to fetch view output instead of sending it to output buffer |
|
26
|
|
|
* |
|
27
|
|
|
* data - Ability to access the resulting data once the view is finished |
|
28
|
|
|
* |
|
29
|
|
|
* *NOTE* When a view uses a layout, the output of the view is ignored, as |
|
30
|
|
|
* as the view is expected to use capture() to send data to the layout. |
|
31
|
|
|
* @property UserData propriedade gerada e usada para pegar dados do model |
|
32
|
|
|
*/ |
|
33
|
|
|
|
|
34
|
|
|
namespace Ballybran\Core\View; |
|
35
|
|
|
|
|
36
|
|
|
use Ballybran\Core\Collections\Collection\IteratorDot; |
|
37
|
|
|
use Ballybran\Helpers\Security\RenderFiles; |
|
38
|
|
|
use \Ballybran\Helpers\Event\Registry; |
|
39
|
|
|
|
|
40
|
|
|
class View extends RenderFiles implements ViewrInterface, \ArrayAccess |
|
41
|
|
|
{ |
|
42
|
|
|
public string $view; |
|
43
|
|
|
public array $data = array(); |
|
44
|
|
|
protected string $controllers; |
|
45
|
|
|
private Form $form; |
|
|
|
|
|
|
46
|
|
|
private Registry $reg; |
|
47
|
|
|
public IteratorDot $dot; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @var string title for meta title |
|
51
|
|
|
*/ |
|
52
|
|
|
public $title; |
|
53
|
|
|
|
|
54
|
|
|
public function __construct() |
|
55
|
|
|
{ |
|
56
|
|
|
$this->reg = Registry::getInstance(); |
|
57
|
|
|
$this->data; |
|
58
|
|
|
$this->dot = new IteratorDot(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* render. |
|
63
|
|
|
* |
|
64
|
|
|
* @param mixed $controller |
|
65
|
|
|
* @param mixed $view |
|
66
|
|
|
* @param mixed $data |
|
67
|
|
|
* |
|
68
|
|
|
* @return string |
|
69
|
|
|
*/ |
|
70
|
|
|
public function render(object $controller, string $view): string |
|
71
|
|
|
{ |
|
72
|
|
|
ob_start(); |
|
73
|
|
|
$data = (null === $this->get_data()) ? array() : $this->get_data(); |
|
|
|
|
|
|
74
|
|
|
$this->dot->merge($data); |
|
75
|
|
|
$this->view = $view; |
|
76
|
|
|
$remove_namespace = explode('\\', get_class($controller)); |
|
77
|
|
|
$this->controllers = $remove_namespace[3]; |
|
78
|
|
|
extract($this->get_data()); |
|
79
|
|
|
$this->isHeader(); |
|
80
|
|
|
|
|
81
|
|
|
include VIEW . $this->controllers . DS . $this->view . $this->ex; |
|
82
|
|
|
$this->isFooter(); |
|
83
|
|
|
|
|
84
|
|
|
$content = ob_get_contents(); |
|
85
|
|
|
return $content; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
|
|
89
|
|
|
public function fetch($data = null) |
|
90
|
|
|
{ |
|
91
|
|
|
ob_start(); |
|
92
|
|
|
$this->render($this->controllers, $this->view, $data); |
|
|
|
|
|
|
93
|
|
|
|
|
94
|
|
|
return ob_get_clean(); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function add(array $data) : void |
|
98
|
|
|
{ |
|
99
|
|
|
$this->data = array_merge( $this->data, $data ); |
|
100
|
|
|
|
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function get_data() : array |
|
104
|
|
|
{ |
|
105
|
|
|
return $this->data; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
protected function capture() |
|
109
|
|
|
{ |
|
110
|
|
|
ob_start(); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
protected function end_capture($name) |
|
114
|
|
|
{ |
|
115
|
|
|
$this->data[$name] = ob_get_clean(); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
private function init(): bool |
|
|
|
|
|
|
119
|
|
|
{ |
|
120
|
|
|
$this->isViewPath($this->controllers); |
|
121
|
|
|
$this->isIndex($this->controllers, $this->view); |
|
122
|
|
|
|
|
123
|
|
|
return true; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
public function offsetExists($offset) : bool |
|
127
|
|
|
{ |
|
128
|
|
|
return isset($this->data[$offset]); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
public function offsetGet($offset) : string |
|
132
|
|
|
{ |
|
133
|
|
|
return $this->data[$offset]; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
public function offsetSet($offset, $value) : void |
|
137
|
|
|
{ |
|
138
|
|
|
$this->data[$offset] = $value; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
public function offsetUnset($offset) : void |
|
142
|
|
|
{ |
|
143
|
|
|
unset($this->data[$offset]); |
|
144
|
|
|
} |
|
145
|
|
|
} |
|
146
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths