@@ -33,193 +33,193 @@ |
||
33 | 33 | */ |
34 | 34 | trait ManagesLayouts |
35 | 35 | { |
36 | - /** |
|
37 | - * Started blocks. |
|
38 | - * |
|
39 | - * @var array $sections |
|
40 | - */ |
|
41 | - protected $sections = []; |
|
36 | + /** |
|
37 | + * Started blocks. |
|
38 | + * |
|
39 | + * @var array $sections |
|
40 | + */ |
|
41 | + protected $sections = []; |
|
42 | 42 | |
43 | - /** |
|
44 | - * The stack of in-progress sections. |
|
45 | - * |
|
46 | - * @var array $sectionStack |
|
47 | - */ |
|
48 | - protected $sectionStack = []; |
|
43 | + /** |
|
44 | + * The stack of in-progress sections. |
|
45 | + * |
|
46 | + * @var array $sectionStack |
|
47 | + */ |
|
48 | + protected $sectionStack = []; |
|
49 | 49 | |
50 | - /** |
|
51 | - * Starting section. |
|
52 | - * |
|
53 | - * @param string $section |
|
54 | - * @param string|null $content (null by default) |
|
55 | - * |
|
56 | - * @return array |
|
57 | - */ |
|
58 | - public function beginSection($section, $content = null) |
|
59 | - { |
|
60 | - if (null === $content) |
|
61 | - { |
|
62 | - if (ob_start()) |
|
63 | - { |
|
64 | - $this->sectionStack[] = $section; |
|
65 | - } |
|
66 | - } |
|
67 | - else |
|
68 | - { |
|
69 | - $this->extendSection($section, $content instanceof View ? $content : e($content)); |
|
70 | - } |
|
71 | - } |
|
50 | + /** |
|
51 | + * Starting section. |
|
52 | + * |
|
53 | + * @param string $section |
|
54 | + * @param string|null $content (null by default) |
|
55 | + * |
|
56 | + * @return array |
|
57 | + */ |
|
58 | + public function beginSection($section, $content = null) |
|
59 | + { |
|
60 | + if (null === $content) |
|
61 | + { |
|
62 | + if (ob_start()) |
|
63 | + { |
|
64 | + $this->sectionStack[] = $section; |
|
65 | + } |
|
66 | + } |
|
67 | + else |
|
68 | + { |
|
69 | + $this->extendSection($section, $content instanceof View ? $content : e($content)); |
|
70 | + } |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * Append content to a given section. |
|
75 | - * |
|
76 | - * @param string $section |
|
77 | - * @param string $content |
|
78 | - * |
|
79 | - * @return void |
|
80 | - */ |
|
81 | - protected function extendSection($section, $content) |
|
82 | - { |
|
83 | - if (isset($this->sections[$section])) |
|
84 | - { |
|
85 | - $content = str_replace(static::parent(), $content, $this->sections[$section]); |
|
86 | - } |
|
73 | + /** |
|
74 | + * Append content to a given section. |
|
75 | + * |
|
76 | + * @param string $section |
|
77 | + * @param string $content |
|
78 | + * |
|
79 | + * @return void |
|
80 | + */ |
|
81 | + protected function extendSection($section, $content) |
|
82 | + { |
|
83 | + if (isset($this->sections[$section])) |
|
84 | + { |
|
85 | + $content = str_replace(static::parent(), $content, $this->sections[$section]); |
|
86 | + } |
|
87 | 87 | |
88 | - $this->sections[$section] = $content; |
|
89 | - } |
|
88 | + $this->sections[$section] = $content; |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * Close and printing section. |
|
93 | - * |
|
94 | - * @return string |
|
95 | - */ |
|
96 | - public function showSection() |
|
97 | - { |
|
98 | - if (empty($this->sectionStack)) |
|
99 | - { |
|
100 | - return ''; |
|
101 | - } |
|
91 | + /** |
|
92 | + * Close and printing section. |
|
93 | + * |
|
94 | + * @return string |
|
95 | + */ |
|
96 | + public function showSection() |
|
97 | + { |
|
98 | + if (empty($this->sectionStack)) |
|
99 | + { |
|
100 | + return ''; |
|
101 | + } |
|
102 | 102 | |
103 | - return $this->giveContent($this->stopSection()); |
|
104 | - } |
|
103 | + return $this->giveContent($this->stopSection()); |
|
104 | + } |
|
105 | 105 | |
106 | - /** |
|
107 | - * Give sections the page view from the master page. |
|
108 | - * |
|
109 | - * @param string $name |
|
110 | - * |
|
111 | - * @return string |
|
112 | - */ |
|
113 | - public function giveContent($name, $default = '') |
|
114 | - { |
|
115 | - $sectionContent = $default instanceof View ? $default : e($default); |
|
106 | + /** |
|
107 | + * Give sections the page view from the master page. |
|
108 | + * |
|
109 | + * @param string $name |
|
110 | + * |
|
111 | + * @return string |
|
112 | + */ |
|
113 | + public function giveContent($name, $default = '') |
|
114 | + { |
|
115 | + $sectionContent = $default instanceof View ? $default : e($default); |
|
116 | 116 | |
117 | - if (isset($this->sections[$name])) |
|
118 | - { |
|
119 | - $sectionContent = $this->sections[$name]; |
|
120 | - } |
|
117 | + if (isset($this->sections[$name])) |
|
118 | + { |
|
119 | + $sectionContent = $this->sections[$name]; |
|
120 | + } |
|
121 | 121 | |
122 | - return str_replace(static::parent(), '', $sectionContent); |
|
123 | - } |
|
122 | + return str_replace(static::parent(), '', $sectionContent); |
|
123 | + } |
|
124 | 124 | |
125 | - /** |
|
126 | - * Closing section. |
|
127 | - * |
|
128 | - * @param bool $overwrite (false by default) |
|
129 | - * |
|
130 | - * @return mixed |
|
131 | - * |
|
132 | - * @throws \InvalidArgumentException |
|
133 | - */ |
|
134 | - public function stopSection($overwrite = false) |
|
135 | - { |
|
136 | - if (empty($this->sectionStack)) |
|
137 | - { |
|
138 | - throw new InvalidArgumentException('You cannot finish a section without first starting with one.'); |
|
139 | - } |
|
125 | + /** |
|
126 | + * Closing section. |
|
127 | + * |
|
128 | + * @param bool $overwrite (false by default) |
|
129 | + * |
|
130 | + * @return mixed |
|
131 | + * |
|
132 | + * @throws \InvalidArgumentException |
|
133 | + */ |
|
134 | + public function stopSection($overwrite = false) |
|
135 | + { |
|
136 | + if (empty($this->sectionStack)) |
|
137 | + { |
|
138 | + throw new InvalidArgumentException('You cannot finish a section without first starting with one.'); |
|
139 | + } |
|
140 | 140 | |
141 | - $last = array_pop($this->sectionStack); |
|
141 | + $last = array_pop($this->sectionStack); |
|
142 | 142 | |
143 | - if ($overwrite) |
|
144 | - { |
|
145 | - $this->sections[$last] = ob_get_clean(); |
|
146 | - } |
|
147 | - else |
|
148 | - { |
|
149 | - $this->extendSection($last, ob_get_clean()); |
|
150 | - } |
|
143 | + if ($overwrite) |
|
144 | + { |
|
145 | + $this->sections[$last] = ob_get_clean(); |
|
146 | + } |
|
147 | + else |
|
148 | + { |
|
149 | + $this->extendSection($last, ob_get_clean()); |
|
150 | + } |
|
151 | 151 | |
152 | - return $last; |
|
153 | - } |
|
152 | + return $last; |
|
153 | + } |
|
154 | 154 | |
155 | - /** |
|
156 | - * Stop injecting content into a section and append it. |
|
157 | - * |
|
158 | - * @return string |
|
159 | - * |
|
160 | - * @throws \InvalidArgumentException |
|
161 | - */ |
|
162 | - public function appendSection() |
|
163 | - { |
|
164 | - if (empty($this->sectionStack)) |
|
165 | - { |
|
166 | - throw new InvalidArgumentException('You cannot finish a section without first starting with one.'); |
|
167 | - } |
|
155 | + /** |
|
156 | + * Stop injecting content into a section and append it. |
|
157 | + * |
|
158 | + * @return string |
|
159 | + * |
|
160 | + * @throws \InvalidArgumentException |
|
161 | + */ |
|
162 | + public function appendSection() |
|
163 | + { |
|
164 | + if (empty($this->sectionStack)) |
|
165 | + { |
|
166 | + throw new InvalidArgumentException('You cannot finish a section without first starting with one.'); |
|
167 | + } |
|
168 | 168 | |
169 | - $last = array_pop($this->sectionStack); |
|
169 | + $last = array_pop($this->sectionStack); |
|
170 | 170 | |
171 | - if (isset($this->sections[$last])) |
|
172 | - { |
|
173 | - $this->sections[$last] .= ob_get_clean(); |
|
174 | - } |
|
175 | - else |
|
176 | - { |
|
177 | - $this->sections[$last] = ob_get_clean(); |
|
178 | - } |
|
171 | + if (isset($this->sections[$last])) |
|
172 | + { |
|
173 | + $this->sections[$last] .= ob_get_clean(); |
|
174 | + } |
|
175 | + else |
|
176 | + { |
|
177 | + $this->sections[$last] = ob_get_clean(); |
|
178 | + } |
|
179 | 179 | |
180 | - return $last; |
|
181 | - } |
|
180 | + return $last; |
|
181 | + } |
|
182 | 182 | |
183 | - /** |
|
184 | - * Check if section exists. |
|
185 | - * |
|
186 | - * @param string $name |
|
187 | - * |
|
188 | - * @return bool |
|
189 | - */ |
|
190 | - public function hasSection($name) |
|
191 | - { |
|
192 | - return array_key_exists($name, $this->sections); |
|
193 | - } |
|
183 | + /** |
|
184 | + * Check if section exists. |
|
185 | + * |
|
186 | + * @param string $name |
|
187 | + * |
|
188 | + * @return bool |
|
189 | + */ |
|
190 | + public function hasSection($name) |
|
191 | + { |
|
192 | + return array_key_exists($name, $this->sections); |
|
193 | + } |
|
194 | 194 | |
195 | - /** |
|
196 | - * Get the entire array of sections. |
|
197 | - * |
|
198 | - * @return array |
|
199 | - */ |
|
200 | - public function getSections() |
|
201 | - { |
|
202 | - return $this->sections; |
|
203 | - } |
|
195 | + /** |
|
196 | + * Get the entire array of sections. |
|
197 | + * |
|
198 | + * @return array |
|
199 | + */ |
|
200 | + public function getSections() |
|
201 | + { |
|
202 | + return $this->sections; |
|
203 | + } |
|
204 | 204 | |
205 | - /** |
|
206 | - * Replace the @parent directive to a placeholder. |
|
207 | - * |
|
208 | - * @return string |
|
209 | - */ |
|
210 | - public static function parent() |
|
211 | - { |
|
212 | - return '@parent'; |
|
213 | - } |
|
205 | + /** |
|
206 | + * Replace the @parent directive to a placeholder. |
|
207 | + * |
|
208 | + * @return string |
|
209 | + */ |
|
210 | + public static function parent() |
|
211 | + { |
|
212 | + return '@parent'; |
|
213 | + } |
|
214 | 214 | |
215 | - /** |
|
216 | - * Flush all of the section contents. |
|
217 | - * |
|
218 | - * @return void |
|
219 | - */ |
|
220 | - public function flushSections() |
|
221 | - { |
|
222 | - $this->sections = []; |
|
223 | - $this->sectionStack = []; |
|
224 | - } |
|
215 | + /** |
|
216 | + * Flush all of the section contents. |
|
217 | + * |
|
218 | + * @return void |
|
219 | + */ |
|
220 | + public function flushSections() |
|
221 | + { |
|
222 | + $this->sections = []; |
|
223 | + $this->sectionStack = []; |
|
224 | + } |
|
225 | 225 | } |
226 | 226 | \ No newline at end of file |
@@ -63,8 +63,7 @@ discard block |
||
63 | 63 | { |
64 | 64 | $this->sectionStack[] = $section; |
65 | 65 | } |
66 | - } |
|
67 | - else |
|
66 | + } else |
|
68 | 67 | { |
69 | 68 | $this->extendSection($section, $content instanceof View ? $content : e($content)); |
70 | 69 | } |
@@ -143,8 +142,7 @@ discard block |
||
143 | 142 | if ($overwrite) |
144 | 143 | { |
145 | 144 | $this->sections[$last] = ob_get_clean(); |
146 | - } |
|
147 | - else |
|
145 | + } else |
|
148 | 146 | { |
149 | 147 | $this->extendSection($last, ob_get_clean()); |
150 | 148 | } |
@@ -171,8 +169,7 @@ discard block |
||
171 | 169 | if (isset($this->sections[$last])) |
172 | 170 | { |
173 | 171 | $this->sections[$last] .= ob_get_clean(); |
174 | - } |
|
175 | - else |
|
172 | + } else |
|
176 | 173 | { |
177 | 174 | $this->sections[$last] = ob_get_clean(); |
178 | 175 | } |
@@ -104,12 +104,10 @@ |
||
104 | 104 | if (func_num_args() > 2) |
105 | 105 | { |
106 | 106 | throw new ViewException("You passed too many arguments to the [$name] slot."); |
107 | - } |
|
108 | - elseif (func_num_args() === 2) |
|
107 | + } elseif (func_num_args() === 2) |
|
109 | 108 | { |
110 | 109 | $this->components[$this->currentComponent()]['slots'][$name] = $content; |
111 | - } |
|
112 | - elseif (ob_start()) |
|
110 | + } elseif (ob_start()) |
|
113 | 111 | { |
114 | 112 | $this->components[$this->currentComponent()]['slots'][] = $name; |
115 | 113 | } |
@@ -43,489 +43,489 @@ |
||
43 | 43 | */ |
44 | 44 | class View implements ArrayAccess, Webable, ViewContract |
45 | 45 | { |
46 | - /** |
|
47 | - * Array of local variables. |
|
48 | - * |
|
49 | - * @var array $data |
|
50 | - */ |
|
51 | - protected $data = []; |
|
52 | - |
|
53 | - /** |
|
54 | - * The engine implementation. |
|
55 | - * |
|
56 | - * @var \Syscodes\Contracts\View\Engine $engine |
|
57 | - */ |
|
58 | - protected $engine; |
|
59 | - |
|
60 | - /** |
|
61 | - * The view factory instance. |
|
62 | - * |
|
63 | - * @var \Syscodes\View\factory $factory |
|
64 | - */ |
|
65 | - protected $factory; |
|
66 | - |
|
67 | - /** |
|
68 | - * The path to the view file. |
|
69 | - * |
|
70 | - * @var string $path |
|
71 | - */ |
|
72 | - protected $path; |
|
73 | - |
|
74 | - /** |
|
75 | - * Get the name of the view. |
|
76 | - * |
|
77 | - * @var string $view |
|
78 | - */ |
|
79 | - protected $view; |
|
80 | - |
|
81 | - /** |
|
82 | - * Constructor: Create a new view instance. |
|
83 | - * |
|
84 | - * @param \Syscodes\View\factory $factory |
|
85 | - * @param \Syscodes\Contracts\View\Engine $engine |
|
86 | - * @param string $view |
|
87 | - * @param string $path |
|
88 | - * @param array $data |
|
89 | - * |
|
90 | - * @return void |
|
91 | - * |
|
92 | - * @throws \InvalidArgumentException |
|
93 | - */ |
|
94 | - public function __construct(Factory $factory, Engine $engine, $view, $path, $data = []) |
|
95 | - { |
|
96 | - $this->factory = $factory; |
|
97 | - $this->engine = $engine; |
|
98 | - $this->view = $view; |
|
99 | - $this->path = $path; |
|
100 | - $this->data = $data instanceof Arrayable ? $data->toArray() : (array) $data; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Get the string contents of the view. |
|
105 | - * |
|
106 | - * @example View::render(); |
|
107 | - * |
|
108 | - * @param \Callable|null $callback (null by default) |
|
109 | - * |
|
110 | - * @return array|string |
|
111 | - * |
|
112 | - * @throws \Throwable |
|
113 | - */ |
|
114 | - public function render(Callable $callback = null) |
|
115 | - { |
|
116 | - try |
|
117 | - { |
|
118 | - $contents = $this->renderContents(); |
|
119 | - |
|
120 | - $response = isset($callback) ? $callback($this, $contents) : null; |
|
121 | - |
|
122 | - $this->factory->flushStateIfDoneRendering(); |
|
123 | - |
|
124 | - return ! is_null($response) ? $response : $contents; |
|
125 | - } |
|
126 | - catch(Throwable $e) |
|
127 | - { |
|
128 | - $this->factory->flushState(); |
|
129 | - |
|
130 | - throw $e; |
|
131 | - } |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Get the contents of the view instance. |
|
136 | - * |
|
137 | - * @return void |
|
138 | - */ |
|
139 | - protected function renderContents() |
|
140 | - { |
|
141 | - $this->factory->increment(); |
|
142 | - |
|
143 | - $contents = $this->getContents(); |
|
144 | - |
|
145 | - $this->factory->decrement(); |
|
146 | - |
|
147 | - return $contents; |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Get the evaluated contents of the view. |
|
152 | - * |
|
153 | - * @return void |
|
154 | - */ |
|
155 | - protected function getContents() |
|
156 | - { |
|
157 | - return $this->engine->get($this->path, $this->getArrayData()); |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * The view data will be extracted. |
|
162 | - * |
|
163 | - * @return array |
|
164 | - */ |
|
165 | - public function getArrayData() |
|
166 | - { |
|
167 | - $data = array_merge($this->factory->getShared(), $this->data); |
|
46 | + /** |
|
47 | + * Array of local variables. |
|
48 | + * |
|
49 | + * @var array $data |
|
50 | + */ |
|
51 | + protected $data = []; |
|
52 | + |
|
53 | + /** |
|
54 | + * The engine implementation. |
|
55 | + * |
|
56 | + * @var \Syscodes\Contracts\View\Engine $engine |
|
57 | + */ |
|
58 | + protected $engine; |
|
59 | + |
|
60 | + /** |
|
61 | + * The view factory instance. |
|
62 | + * |
|
63 | + * @var \Syscodes\View\factory $factory |
|
64 | + */ |
|
65 | + protected $factory; |
|
66 | + |
|
67 | + /** |
|
68 | + * The path to the view file. |
|
69 | + * |
|
70 | + * @var string $path |
|
71 | + */ |
|
72 | + protected $path; |
|
73 | + |
|
74 | + /** |
|
75 | + * Get the name of the view. |
|
76 | + * |
|
77 | + * @var string $view |
|
78 | + */ |
|
79 | + protected $view; |
|
80 | + |
|
81 | + /** |
|
82 | + * Constructor: Create a new view instance. |
|
83 | + * |
|
84 | + * @param \Syscodes\View\factory $factory |
|
85 | + * @param \Syscodes\Contracts\View\Engine $engine |
|
86 | + * @param string $view |
|
87 | + * @param string $path |
|
88 | + * @param array $data |
|
89 | + * |
|
90 | + * @return void |
|
91 | + * |
|
92 | + * @throws \InvalidArgumentException |
|
93 | + */ |
|
94 | + public function __construct(Factory $factory, Engine $engine, $view, $path, $data = []) |
|
95 | + { |
|
96 | + $this->factory = $factory; |
|
97 | + $this->engine = $engine; |
|
98 | + $this->view = $view; |
|
99 | + $this->path = $path; |
|
100 | + $this->data = $data instanceof Arrayable ? $data->toArray() : (array) $data; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Get the string contents of the view. |
|
105 | + * |
|
106 | + * @example View::render(); |
|
107 | + * |
|
108 | + * @param \Callable|null $callback (null by default) |
|
109 | + * |
|
110 | + * @return array|string |
|
111 | + * |
|
112 | + * @throws \Throwable |
|
113 | + */ |
|
114 | + public function render(Callable $callback = null) |
|
115 | + { |
|
116 | + try |
|
117 | + { |
|
118 | + $contents = $this->renderContents(); |
|
119 | + |
|
120 | + $response = isset($callback) ? $callback($this, $contents) : null; |
|
121 | + |
|
122 | + $this->factory->flushStateIfDoneRendering(); |
|
123 | + |
|
124 | + return ! is_null($response) ? $response : $contents; |
|
125 | + } |
|
126 | + catch(Throwable $e) |
|
127 | + { |
|
128 | + $this->factory->flushState(); |
|
129 | + |
|
130 | + throw $e; |
|
131 | + } |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Get the contents of the view instance. |
|
136 | + * |
|
137 | + * @return void |
|
138 | + */ |
|
139 | + protected function renderContents() |
|
140 | + { |
|
141 | + $this->factory->increment(); |
|
142 | + |
|
143 | + $contents = $this->getContents(); |
|
144 | + |
|
145 | + $this->factory->decrement(); |
|
146 | + |
|
147 | + return $contents; |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * Get the evaluated contents of the view. |
|
152 | + * |
|
153 | + * @return void |
|
154 | + */ |
|
155 | + protected function getContents() |
|
156 | + { |
|
157 | + return $this->engine->get($this->path, $this->getArrayData()); |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * The view data will be extracted. |
|
162 | + * |
|
163 | + * @return array |
|
164 | + */ |
|
165 | + public function getArrayData() |
|
166 | + { |
|
167 | + $data = array_merge($this->factory->getShared(), $this->data); |
|
168 | 168 | |
169 | - return array_map(function ($value) { |
|
170 | - return ($value instanceof Renderable) ? $value->render() : $value; |
|
171 | - }, $data); |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * Get the sections of the rendered view. |
|
176 | - * |
|
177 | - * @return array |
|
178 | - * |
|
179 | - * @throws \Throwable |
|
180 | - */ |
|
181 | - public function renderSections() |
|
182 | - { |
|
183 | - return $this->render(function () { |
|
184 | - return $this->factory->getSections(); |
|
185 | - }); |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * Add a piece of data to the view. |
|
190 | - * |
|
191 | - * @example $view->assign($content, $data); |
|
192 | - * |
|
193 | - * @param string|array $key |
|
194 | - * @param mixed $value (null by default) |
|
195 | - * |
|
196 | - * @return $this |
|
197 | - */ |
|
198 | - public function assign($key, $value = null) |
|
199 | - { |
|
200 | - if (is_array($key)) |
|
201 | - { |
|
202 | - $this->data = array_merge($this->data, $key); |
|
203 | - } |
|
204 | - else |
|
205 | - { |
|
206 | - $this->data = [$key => $value]; |
|
207 | - } |
|
208 | - |
|
209 | - return $this; |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * Assigns a value by reference. The benefit of binding is that values can be altered |
|
214 | - * without re-setting them. It is also possible to bind variables before they have values. |
|
215 | - * Assigned values will be available as a variable within the view file: |
|
216 | - * |
|
217 | - * @example $view->bind('ref', $bar); |
|
218 | - * |
|
219 | - * @param string $key Variable name |
|
220 | - * @param mixed $value Referenced variable |
|
221 | - * |
|
222 | - * @return $this |
|
223 | - */ |
|
224 | - public function bind($key, & $value) |
|
225 | - { |
|
226 | - $this->data[$key] =& $value; |
|
227 | - |
|
228 | - return $this; |
|
229 | - } |
|
230 | - |
|
231 | - /** |
|
232 | - * Get the array of view data. |
|
233 | - * |
|
234 | - * @return array |
|
235 | - */ |
|
236 | - public function getData() |
|
237 | - { |
|
238 | - return $this->data; |
|
239 | - } |
|
240 | - |
|
241 | - /** |
|
242 | - * Get the name of the view. |
|
243 | - * |
|
244 | - * @return string |
|
245 | - */ |
|
246 | - public function getView() |
|
247 | - { |
|
248 | - return $this->view; |
|
249 | - } |
|
250 | - |
|
251 | - /** |
|
252 | - * Get the path to the view file. |
|
253 | - * |
|
254 | - * @return string |
|
255 | - */ |
|
256 | - public function getPath() |
|
257 | - { |
|
258 | - return $this->path; |
|
259 | - } |
|
260 | - |
|
261 | - /** |
|
262 | - * Set the path to the view file. |
|
263 | - * |
|
264 | - * @param string $path |
|
265 | - * |
|
266 | - * @return void |
|
267 | - */ |
|
268 | - public function setPath($path) |
|
269 | - { |
|
270 | - $this->path = $path; |
|
271 | - } |
|
272 | - |
|
273 | - /** |
|
274 | - * Get the view factory instance. |
|
275 | - * |
|
276 | - * @return \Syscodes\View\factory |
|
277 | - */ |
|
278 | - public function getFactory() |
|
279 | - { |
|
280 | - return $this->factory; |
|
281 | - } |
|
282 | - |
|
283 | - /** |
|
284 | - * Get the view's rendering engine. |
|
285 | - * |
|
286 | - * @return \Syscodes\Contracts\View\Engine |
|
287 | - */ |
|
288 | - public function getEngine() |
|
289 | - { |
|
290 | - return $this->engine; |
|
291 | - } |
|
292 | - |
|
293 | - /** |
|
294 | - * Searches for the given variable and returns its value. |
|
295 | - * Local variables will be returned before global variables. |
|
296 | - * |
|
297 | - * @example $value = $view->get('foo', 'bar'); |
|
298 | - * |
|
299 | - * If the key is not given or null, the entire data array is returned. |
|
300 | - * |
|
301 | - * @param string $key The variable name |
|
302 | - * @param mixed $default The default value to return |
|
303 | - * |
|
304 | - * @return mixed |
|
305 | - * |
|
306 | - * @uses \Syscodes\Contracts\Core\Lenevor |
|
307 | - * |
|
308 | - * @throws \InvalidArgumentException |
|
309 | - */ |
|
310 | - public function &get($key, $default = null) |
|
311 | - { |
|
312 | - if (strpos($key, '.') === false) |
|
313 | - { |
|
314 | - if (array_key_exists($key, $this->data)) |
|
315 | - { |
|
316 | - return $this->data[$key]; |
|
317 | - } |
|
318 | - else |
|
319 | - { |
|
320 | - throw new InvalidArgumentException(__('view.variableNotSet')); |
|
321 | - } |
|
322 | - } |
|
323 | - else |
|
324 | - { |
|
325 | - return value($default); |
|
326 | - } |
|
327 | - } |
|
328 | - |
|
329 | - /** |
|
330 | - * Assigns a variable by name. Assigned values will be available as a |
|
331 | - * variable within the view file: |
|
332 | - * |
|
333 | - * This value can be accessed as $var within the view |
|
334 | - * @example $view->set(array('food' => 'bread', 'beverage' => 'water')); |
|
335 | - * |
|
336 | - * @param string|array $key Variable name |
|
337 | - * @param mixed $value Value |
|
338 | - * |
|
339 | - * @return $this |
|
340 | - * |
|
341 | - * @uses instanceof \Traversable |
|
342 | - */ |
|
343 | - public function set($key, $value = null) |
|
344 | - { |
|
345 | - if (is_array($key) || $key instanceof Traversable) |
|
346 | - { |
|
347 | - foreach ($key as $name => $value) |
|
348 | - { |
|
349 | - $this->set($name, $value); |
|
350 | - } |
|
351 | - } |
|
352 | - else |
|
353 | - { |
|
354 | - if (strpos($key, '.') === false) |
|
355 | - { |
|
356 | - $this->data[$key] = $value; |
|
357 | - } |
|
358 | - else |
|
359 | - { |
|
360 | - Arr::set($this->data, $key, $value); |
|
361 | - } |
|
362 | - } |
|
363 | - |
|
364 | - return $this; |
|
365 | - } |
|
366 | - |
|
367 | - /* |
|
169 | + return array_map(function ($value) { |
|
170 | + return ($value instanceof Renderable) ? $value->render() : $value; |
|
171 | + }, $data); |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * Get the sections of the rendered view. |
|
176 | + * |
|
177 | + * @return array |
|
178 | + * |
|
179 | + * @throws \Throwable |
|
180 | + */ |
|
181 | + public function renderSections() |
|
182 | + { |
|
183 | + return $this->render(function () { |
|
184 | + return $this->factory->getSections(); |
|
185 | + }); |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * Add a piece of data to the view. |
|
190 | + * |
|
191 | + * @example $view->assign($content, $data); |
|
192 | + * |
|
193 | + * @param string|array $key |
|
194 | + * @param mixed $value (null by default) |
|
195 | + * |
|
196 | + * @return $this |
|
197 | + */ |
|
198 | + public function assign($key, $value = null) |
|
199 | + { |
|
200 | + if (is_array($key)) |
|
201 | + { |
|
202 | + $this->data = array_merge($this->data, $key); |
|
203 | + } |
|
204 | + else |
|
205 | + { |
|
206 | + $this->data = [$key => $value]; |
|
207 | + } |
|
208 | + |
|
209 | + return $this; |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * Assigns a value by reference. The benefit of binding is that values can be altered |
|
214 | + * without re-setting them. It is also possible to bind variables before they have values. |
|
215 | + * Assigned values will be available as a variable within the view file: |
|
216 | + * |
|
217 | + * @example $view->bind('ref', $bar); |
|
218 | + * |
|
219 | + * @param string $key Variable name |
|
220 | + * @param mixed $value Referenced variable |
|
221 | + * |
|
222 | + * @return $this |
|
223 | + */ |
|
224 | + public function bind($key, & $value) |
|
225 | + { |
|
226 | + $this->data[$key] =& $value; |
|
227 | + |
|
228 | + return $this; |
|
229 | + } |
|
230 | + |
|
231 | + /** |
|
232 | + * Get the array of view data. |
|
233 | + * |
|
234 | + * @return array |
|
235 | + */ |
|
236 | + public function getData() |
|
237 | + { |
|
238 | + return $this->data; |
|
239 | + } |
|
240 | + |
|
241 | + /** |
|
242 | + * Get the name of the view. |
|
243 | + * |
|
244 | + * @return string |
|
245 | + */ |
|
246 | + public function getView() |
|
247 | + { |
|
248 | + return $this->view; |
|
249 | + } |
|
250 | + |
|
251 | + /** |
|
252 | + * Get the path to the view file. |
|
253 | + * |
|
254 | + * @return string |
|
255 | + */ |
|
256 | + public function getPath() |
|
257 | + { |
|
258 | + return $this->path; |
|
259 | + } |
|
260 | + |
|
261 | + /** |
|
262 | + * Set the path to the view file. |
|
263 | + * |
|
264 | + * @param string $path |
|
265 | + * |
|
266 | + * @return void |
|
267 | + */ |
|
268 | + public function setPath($path) |
|
269 | + { |
|
270 | + $this->path = $path; |
|
271 | + } |
|
272 | + |
|
273 | + /** |
|
274 | + * Get the view factory instance. |
|
275 | + * |
|
276 | + * @return \Syscodes\View\factory |
|
277 | + */ |
|
278 | + public function getFactory() |
|
279 | + { |
|
280 | + return $this->factory; |
|
281 | + } |
|
282 | + |
|
283 | + /** |
|
284 | + * Get the view's rendering engine. |
|
285 | + * |
|
286 | + * @return \Syscodes\Contracts\View\Engine |
|
287 | + */ |
|
288 | + public function getEngine() |
|
289 | + { |
|
290 | + return $this->engine; |
|
291 | + } |
|
292 | + |
|
293 | + /** |
|
294 | + * Searches for the given variable and returns its value. |
|
295 | + * Local variables will be returned before global variables. |
|
296 | + * |
|
297 | + * @example $value = $view->get('foo', 'bar'); |
|
298 | + * |
|
299 | + * If the key is not given or null, the entire data array is returned. |
|
300 | + * |
|
301 | + * @param string $key The variable name |
|
302 | + * @param mixed $default The default value to return |
|
303 | + * |
|
304 | + * @return mixed |
|
305 | + * |
|
306 | + * @uses \Syscodes\Contracts\Core\Lenevor |
|
307 | + * |
|
308 | + * @throws \InvalidArgumentException |
|
309 | + */ |
|
310 | + public function &get($key, $default = null) |
|
311 | + { |
|
312 | + if (strpos($key, '.') === false) |
|
313 | + { |
|
314 | + if (array_key_exists($key, $this->data)) |
|
315 | + { |
|
316 | + return $this->data[$key]; |
|
317 | + } |
|
318 | + else |
|
319 | + { |
|
320 | + throw new InvalidArgumentException(__('view.variableNotSet')); |
|
321 | + } |
|
322 | + } |
|
323 | + else |
|
324 | + { |
|
325 | + return value($default); |
|
326 | + } |
|
327 | + } |
|
328 | + |
|
329 | + /** |
|
330 | + * Assigns a variable by name. Assigned values will be available as a |
|
331 | + * variable within the view file: |
|
332 | + * |
|
333 | + * This value can be accessed as $var within the view |
|
334 | + * @example $view->set(array('food' => 'bread', 'beverage' => 'water')); |
|
335 | + * |
|
336 | + * @param string|array $key Variable name |
|
337 | + * @param mixed $value Value |
|
338 | + * |
|
339 | + * @return $this |
|
340 | + * |
|
341 | + * @uses instanceof \Traversable |
|
342 | + */ |
|
343 | + public function set($key, $value = null) |
|
344 | + { |
|
345 | + if (is_array($key) || $key instanceof Traversable) |
|
346 | + { |
|
347 | + foreach ($key as $name => $value) |
|
348 | + { |
|
349 | + $this->set($name, $value); |
|
350 | + } |
|
351 | + } |
|
352 | + else |
|
353 | + { |
|
354 | + if (strpos($key, '.') === false) |
|
355 | + { |
|
356 | + $this->data[$key] = $value; |
|
357 | + } |
|
358 | + else |
|
359 | + { |
|
360 | + Arr::set($this->data, $key, $value); |
|
361 | + } |
|
362 | + } |
|
363 | + |
|
364 | + return $this; |
|
365 | + } |
|
366 | + |
|
367 | + /* |
|
368 | 368 | |----------------------------------------------------------------- |
369 | 369 | | ArrayAccess Methods |
370 | 370 | |----------------------------------------------------------------- |
371 | 371 | */ |
372 | 372 | |
373 | - /** |
|
374 | - * Whether or not an offset exists. |
|
375 | - * |
|
376 | - * @param string $offset |
|
377 | - * |
|
378 | - * @return bool |
|
379 | - */ |
|
380 | - public function offsetExists($offset) |
|
381 | - { |
|
382 | - return array_key_exists($offset, $this->data); |
|
383 | - } |
|
384 | - |
|
385 | - /** |
|
386 | - * Returns the value at specified offset. |
|
387 | - * |
|
388 | - * @param string $offset |
|
389 | - * |
|
390 | - * @return mixed |
|
391 | - */ |
|
392 | - public function offsetGet($offset) |
|
393 | - { |
|
394 | - return $this->data[$offset]; |
|
395 | - } |
|
396 | - |
|
397 | - /** |
|
398 | - * Assigns a value to the specified offset |
|
399 | - * |
|
400 | - * @param string $offset |
|
401 | - * @param mixed $value |
|
402 | - * |
|
403 | - * @return void |
|
404 | - */ |
|
405 | - public function offsetSet($offset, $value) |
|
406 | - { |
|
407 | - $this->assign($offset, $value); |
|
408 | - } |
|
409 | - |
|
410 | - /** |
|
411 | - * Unsets an offset. |
|
412 | - * |
|
413 | - * @param string $offset |
|
414 | - * |
|
415 | - * @return void |
|
416 | - */ |
|
417 | - public function offsetUnset($offset) |
|
418 | - { |
|
419 | - unset($this->data[$offset]); |
|
420 | - } |
|
421 | - |
|
422 | - /** |
|
423 | - * Magic method. Searches for the given variable and returns its value. |
|
424 | - * Local variables will be returned before global variables. |
|
425 | - * |
|
426 | - * @example $value = $view->var; |
|
427 | - * |
|
428 | - * @param string $key Variable name |
|
429 | - * |
|
430 | - * @return mixed |
|
431 | - * |
|
432 | - * @throws \Syscodes\LenevorException |
|
433 | - */ |
|
434 | - public function &__get($key) |
|
435 | - { |
|
436 | - return $this->get($key); |
|
437 | - } |
|
438 | - |
|
439 | - /** |
|
440 | - * Magic method. Calls [$this->set] with the same parameters. |
|
441 | - * |
|
442 | - * @example $view->var = 'something'; |
|
443 | - * |
|
444 | - * @param string $key Variable name |
|
445 | - * @param mixed $value Value |
|
446 | - * |
|
447 | - * @return void |
|
448 | - */ |
|
449 | - public function __set($key, $value) |
|
450 | - { |
|
451 | - $this->set($key, $value); |
|
452 | - } |
|
453 | - |
|
454 | - /** |
|
455 | - * Magic method. Determines if a variable is set. |
|
456 | - * |
|
457 | - * @example isset($view->foo); |
|
458 | - * |
|
459 | - * Variables are not considered to be set. |
|
460 | - * |
|
461 | - * @param string $key variable name |
|
462 | - * |
|
463 | - * @return boolean |
|
464 | - */ |
|
465 | - public function __isset($key) |
|
466 | - { |
|
467 | - return isset($this->data[$key]); |
|
468 | - } |
|
469 | - |
|
470 | - /** |
|
471 | - * Magic method. Unsets a given variable. |
|
472 | - * |
|
473 | - * @example unset($view->var); |
|
474 | - * |
|
475 | - * @param string $key Variable name |
|
476 | - * |
|
477 | - * @return void |
|
478 | - */ |
|
479 | - public function __unset($key) |
|
480 | - { |
|
481 | - unset($this->data[$key]); |
|
482 | - } |
|
483 | - |
|
484 | - /** |
|
485 | - * Magic Method for handling dynamic functions. |
|
486 | - * |
|
487 | - * @param string $method |
|
488 | - * @param array $parameters |
|
489 | - * |
|
490 | - * @return mixed |
|
491 | - * |
|
492 | - * @throws \BadMethodCallException; |
|
493 | - */ |
|
494 | - public function __call($method, $parameters) |
|
495 | - { |
|
496 | - if (Str::startsWith($method, 'assign')) |
|
497 | - { |
|
498 | - $name = Str::camelcase(substr($method, 4)); |
|
499 | - |
|
500 | - return $this->assign($name, $parameters[0]); |
|
501 | - } |
|
502 | - |
|
503 | - throw new BadMethodCallException(sprintf( |
|
504 | - 'Method %s::%s does not exist.', static::class, $method) |
|
505 | - ); |
|
506 | - } |
|
507 | - |
|
508 | - /** |
|
509 | - * Get content as a string of HTML. |
|
510 | - * |
|
511 | - * @return string |
|
512 | - */ |
|
513 | - public function toHtml() |
|
514 | - { |
|
515 | - return $this->render(); |
|
516 | - } |
|
517 | - |
|
518 | - /** |
|
519 | - * Magic method. Returns the output of [static::render]. |
|
520 | - * |
|
521 | - * @return string |
|
522 | - * |
|
523 | - * @uses View->render() |
|
524 | - * |
|
525 | - * @throws \Throwable |
|
526 | - */ |
|
527 | - public function __toString() |
|
528 | - { |
|
529 | - return $this->render(); |
|
530 | - } |
|
373 | + /** |
|
374 | + * Whether or not an offset exists. |
|
375 | + * |
|
376 | + * @param string $offset |
|
377 | + * |
|
378 | + * @return bool |
|
379 | + */ |
|
380 | + public function offsetExists($offset) |
|
381 | + { |
|
382 | + return array_key_exists($offset, $this->data); |
|
383 | + } |
|
384 | + |
|
385 | + /** |
|
386 | + * Returns the value at specified offset. |
|
387 | + * |
|
388 | + * @param string $offset |
|
389 | + * |
|
390 | + * @return mixed |
|
391 | + */ |
|
392 | + public function offsetGet($offset) |
|
393 | + { |
|
394 | + return $this->data[$offset]; |
|
395 | + } |
|
396 | + |
|
397 | + /** |
|
398 | + * Assigns a value to the specified offset |
|
399 | + * |
|
400 | + * @param string $offset |
|
401 | + * @param mixed $value |
|
402 | + * |
|
403 | + * @return void |
|
404 | + */ |
|
405 | + public function offsetSet($offset, $value) |
|
406 | + { |
|
407 | + $this->assign($offset, $value); |
|
408 | + } |
|
409 | + |
|
410 | + /** |
|
411 | + * Unsets an offset. |
|
412 | + * |
|
413 | + * @param string $offset |
|
414 | + * |
|
415 | + * @return void |
|
416 | + */ |
|
417 | + public function offsetUnset($offset) |
|
418 | + { |
|
419 | + unset($this->data[$offset]); |
|
420 | + } |
|
421 | + |
|
422 | + /** |
|
423 | + * Magic method. Searches for the given variable and returns its value. |
|
424 | + * Local variables will be returned before global variables. |
|
425 | + * |
|
426 | + * @example $value = $view->var; |
|
427 | + * |
|
428 | + * @param string $key Variable name |
|
429 | + * |
|
430 | + * @return mixed |
|
431 | + * |
|
432 | + * @throws \Syscodes\LenevorException |
|
433 | + */ |
|
434 | + public function &__get($key) |
|
435 | + { |
|
436 | + return $this->get($key); |
|
437 | + } |
|
438 | + |
|
439 | + /** |
|
440 | + * Magic method. Calls [$this->set] with the same parameters. |
|
441 | + * |
|
442 | + * @example $view->var = 'something'; |
|
443 | + * |
|
444 | + * @param string $key Variable name |
|
445 | + * @param mixed $value Value |
|
446 | + * |
|
447 | + * @return void |
|
448 | + */ |
|
449 | + public function __set($key, $value) |
|
450 | + { |
|
451 | + $this->set($key, $value); |
|
452 | + } |
|
453 | + |
|
454 | + /** |
|
455 | + * Magic method. Determines if a variable is set. |
|
456 | + * |
|
457 | + * @example isset($view->foo); |
|
458 | + * |
|
459 | + * Variables are not considered to be set. |
|
460 | + * |
|
461 | + * @param string $key variable name |
|
462 | + * |
|
463 | + * @return boolean |
|
464 | + */ |
|
465 | + public function __isset($key) |
|
466 | + { |
|
467 | + return isset($this->data[$key]); |
|
468 | + } |
|
469 | + |
|
470 | + /** |
|
471 | + * Magic method. Unsets a given variable. |
|
472 | + * |
|
473 | + * @example unset($view->var); |
|
474 | + * |
|
475 | + * @param string $key Variable name |
|
476 | + * |
|
477 | + * @return void |
|
478 | + */ |
|
479 | + public function __unset($key) |
|
480 | + { |
|
481 | + unset($this->data[$key]); |
|
482 | + } |
|
483 | + |
|
484 | + /** |
|
485 | + * Magic Method for handling dynamic functions. |
|
486 | + * |
|
487 | + * @param string $method |
|
488 | + * @param array $parameters |
|
489 | + * |
|
490 | + * @return mixed |
|
491 | + * |
|
492 | + * @throws \BadMethodCallException; |
|
493 | + */ |
|
494 | + public function __call($method, $parameters) |
|
495 | + { |
|
496 | + if (Str::startsWith($method, 'assign')) |
|
497 | + { |
|
498 | + $name = Str::camelcase(substr($method, 4)); |
|
499 | + |
|
500 | + return $this->assign($name, $parameters[0]); |
|
501 | + } |
|
502 | + |
|
503 | + throw new BadMethodCallException(sprintf( |
|
504 | + 'Method %s::%s does not exist.', static::class, $method) |
|
505 | + ); |
|
506 | + } |
|
507 | + |
|
508 | + /** |
|
509 | + * Get content as a string of HTML. |
|
510 | + * |
|
511 | + * @return string |
|
512 | + */ |
|
513 | + public function toHtml() |
|
514 | + { |
|
515 | + return $this->render(); |
|
516 | + } |
|
517 | + |
|
518 | + /** |
|
519 | + * Magic method. Returns the output of [static::render]. |
|
520 | + * |
|
521 | + * @return string |
|
522 | + * |
|
523 | + * @uses View->render() |
|
524 | + * |
|
525 | + * @throws \Throwable |
|
526 | + */ |
|
527 | + public function __toString() |
|
528 | + { |
|
529 | + return $this->render(); |
|
530 | + } |
|
531 | 531 | } |
532 | 532 | \ No newline at end of file |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | |
124 | 124 | return ! is_null($response) ? $response : $contents; |
125 | 125 | } |
126 | - catch(Throwable $e) |
|
126 | + catch (Throwable $e) |
|
127 | 127 | { |
128 | 128 | $this->factory->flushState(); |
129 | 129 | |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | { |
167 | 167 | $data = array_merge($this->factory->getShared(), $this->data); |
168 | 168 | |
169 | - return array_map(function ($value) { |
|
169 | + return array_map(function($value) { |
|
170 | 170 | return ($value instanceof Renderable) ? $value->render() : $value; |
171 | 171 | }, $data); |
172 | 172 | } |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | */ |
181 | 181 | public function renderSections() |
182 | 182 | { |
183 | - return $this->render(function () { |
|
183 | + return $this->render(function() { |
|
184 | 184 | return $this->factory->getSections(); |
185 | 185 | }); |
186 | 186 | } |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | */ |
224 | 224 | public function bind($key, & $value) |
225 | 225 | { |
226 | - $this->data[$key] =& $value; |
|
226 | + $this->data[$key] = & $value; |
|
227 | 227 | |
228 | 228 | return $this; |
229 | 229 | } |
@@ -122,8 +122,7 @@ discard block |
||
122 | 122 | $this->factory->flushStateIfDoneRendering(); |
123 | 123 | |
124 | 124 | return ! is_null($response) ? $response : $contents; |
125 | - } |
|
126 | - catch(Throwable $e) |
|
125 | + } catch(Throwable $e) |
|
127 | 126 | { |
128 | 127 | $this->factory->flushState(); |
129 | 128 | |
@@ -200,8 +199,7 @@ discard block |
||
200 | 199 | if (is_array($key)) |
201 | 200 | { |
202 | 201 | $this->data = array_merge($this->data, $key); |
203 | - } |
|
204 | - else |
|
202 | + } else |
|
205 | 203 | { |
206 | 204 | $this->data = [$key => $value]; |
207 | 205 | } |
@@ -314,13 +312,11 @@ discard block |
||
314 | 312 | if (array_key_exists($key, $this->data)) |
315 | 313 | { |
316 | 314 | return $this->data[$key]; |
317 | - } |
|
318 | - else |
|
315 | + } else |
|
319 | 316 | { |
320 | 317 | throw new InvalidArgumentException(__('view.variableNotSet')); |
321 | 318 | } |
322 | - } |
|
323 | - else |
|
319 | + } else |
|
324 | 320 | { |
325 | 321 | return value($default); |
326 | 322 | } |
@@ -348,14 +344,12 @@ discard block |
||
348 | 344 | { |
349 | 345 | $this->set($name, $value); |
350 | 346 | } |
351 | - } |
|
352 | - else |
|
347 | + } else |
|
353 | 348 | { |
354 | 349 | if (strpos($key, '.') === false) |
355 | 350 | { |
356 | 351 | $this->data[$key] = $value; |
357 | - } |
|
358 | - else |
|
352 | + } else |
|
359 | 353 | { |
360 | 354 | Arr::set($this->data, $key, $value); |
361 | 355 | } |
@@ -30,45 +30,45 @@ |
||
30 | 30 | */ |
31 | 31 | trait Extensions |
32 | 32 | { |
33 | - /** |
|
34 | - * The file extension. |
|
35 | - * |
|
36 | - * @var array $extension |
|
37 | - */ |
|
38 | - protected $extension = [ |
|
39 | - 'plaze.php', |
|
40 | - 'php', |
|
41 | - 'html', |
|
42 | - ]; |
|
33 | + /** |
|
34 | + * The file extension. |
|
35 | + * |
|
36 | + * @var array $extension |
|
37 | + */ |
|
38 | + protected $extension = [ |
|
39 | + 'plaze.php', |
|
40 | + 'php', |
|
41 | + 'html', |
|
42 | + ]; |
|
43 | 43 | |
44 | - /** |
|
45 | - * The type to engine bindings. |
|
46 | - * |
|
47 | - * @var array $extensions |
|
48 | - */ |
|
49 | - protected $extensions = [ |
|
50 | - 'plaze.php' => 'plaze', |
|
51 | - 'php' => 'php', |
|
52 | - 'html' => 'file', |
|
53 | - ]; |
|
44 | + /** |
|
45 | + * The type to engine bindings. |
|
46 | + * |
|
47 | + * @var array $extensions |
|
48 | + */ |
|
49 | + protected $extensions = [ |
|
50 | + 'plaze.php' => 'plaze', |
|
51 | + 'php' => 'php', |
|
52 | + 'html' => 'file', |
|
53 | + ]; |
|
54 | 54 | |
55 | - /** |
|
56 | - * Get the template file extension. |
|
57 | - * |
|
58 | - * @return array |
|
59 | - */ |
|
60 | - public function getExtensions() |
|
61 | - { |
|
62 | - return $this->extension; |
|
63 | - } |
|
55 | + /** |
|
56 | + * Get the template file extension. |
|
57 | + * |
|
58 | + * @return array |
|
59 | + */ |
|
60 | + public function getExtensions() |
|
61 | + { |
|
62 | + return $this->extension; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * Get type to engine bindings. |
|
67 | - * |
|
68 | - * @return array |
|
69 | - */ |
|
70 | - public function getKeysToExtensions() |
|
71 | - { |
|
72 | - return array_keys($this->extensions); |
|
73 | - } |
|
65 | + /** |
|
66 | + * Get type to engine bindings. |
|
67 | + * |
|
68 | + * @return array |
|
69 | + */ |
|
70 | + public function getKeysToExtensions() |
|
71 | + { |
|
72 | + return array_keys($this->extensions); |
|
73 | + } |
|
74 | 74 | } |
75 | 75 | \ No newline at end of file |
@@ -69,8 +69,7 @@ |
||
69 | 69 | { |
70 | 70 | $this->key = $key; |
71 | 71 | $this->cipher = $cipher; |
72 | - } |
|
73 | - else |
|
72 | + } else |
|
74 | 73 | { |
75 | 74 | throw new RuntimeException('The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths.'); |
76 | 75 | } |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public function register() |
43 | 43 | { |
44 | - $this->app->singleton('encrypter', function ($app) { |
|
44 | + $this->app->singleton('encrypter', function($app) { |
|
45 | 45 | |
46 | 46 | $config = $app->make('config')->get('security'); |
47 | 47 | |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | */ |
67 | 67 | protected function key(array $config) |
68 | 68 | { |
69 | - return take($config['key'], function ($key) { |
|
69 | + return take($config['key'], function($key) { |
|
70 | 70 | |
71 | 71 | if (empty($key)) |
72 | 72 | { |
@@ -36,10 +36,10 @@ |
||
36 | 36 | class LogManager implements LoggerInterface |
37 | 37 | { |
38 | 38 | /** |
39 | - * The application implementation. |
|
40 | - * |
|
41 | - * @var \Syscodes\Contracts\Core\Application $app |
|
42 | - */ |
|
39 | + * The application implementation. |
|
40 | + * |
|
41 | + * @var \Syscodes\Contracts\Core\Application $app |
|
42 | + */ |
|
43 | 43 | protected $app; |
44 | 44 | |
45 | 45 | /** |
@@ -40,10 +40,10 @@ |
||
40 | 40 | use ParseLogEnvironment; |
41 | 41 | |
42 | 42 | /** |
43 | - * The application implementation. |
|
44 | - * |
|
45 | - * @var \Syscodes\Contracts\Core\Application $app |
|
46 | - */ |
|
43 | + * The application implementation. |
|
44 | + * |
|
45 | + * @var \Syscodes\Contracts\Core\Application $app |
|
46 | + */ |
|
47 | 47 | protected $app; |
48 | 48 | |
49 | 49 | /** |
@@ -161,7 +161,7 @@ |
||
161 | 161 | { |
162 | 162 | if ($key === 'exception' && $value instanceof Throwable) |
163 | 163 | { |
164 | - $value = $value->getMessage() . ' ' . $this->cleanFileNames($value->getFile()) . ':' . $value->getLine(); |
|
164 | + $value = $value->getMessage().' '.$this->cleanFileNames($value->getFile()).':'.$value->getLine(); |
|
165 | 165 | // Todo - sanitize input before writing to file? |
166 | 166 | $replace["{{$key}}"] = $value; |
167 | 167 | } |
@@ -164,20 +164,16 @@ |
||
164 | 164 | $value = $value->getMessage() . ' ' . $this->cleanFileNames($value->getFile()) . ':' . $value->getLine(); |
165 | 165 | // Todo - sanitize input before writing to file? |
166 | 166 | $replace["{{$key}}"] = $value; |
167 | - } |
|
168 | - elseif (null === $value || is_scalar($value) || (is_object($value) && method_exists($value, '__toString'))) |
|
167 | + } elseif (null === $value || is_scalar($value) || (is_object($value) && method_exists($value, '__toString'))) |
|
169 | 168 | { |
170 | 169 | $replace["{{$key}}"] = $value; |
171 | - } |
|
172 | - elseif ($value instanceof DateTime) |
|
170 | + } elseif ($value instanceof DateTime) |
|
173 | 171 | { |
174 | 172 | $replace["{{$key}}"] = $value->format(DateTime::RFC3339); |
175 | - } |
|
176 | - elseif (is_object($value)) |
|
173 | + } elseif (is_object($value)) |
|
177 | 174 | { |
178 | 175 | $replace["{{$key}}"] = '[object '.get_class($value).']'; |
179 | - } |
|
180 | - else |
|
176 | + } else |
|
181 | 177 | { |
182 | 178 | $replace["{{$key}}"] = '['.gettype($value).']'; |
183 | 179 | } |
@@ -39,7 +39,7 @@ |
||
39 | 39 | */ |
40 | 40 | public function register() |
41 | 41 | { |
42 | - $this->app->singleton('log', function () { |
|
42 | + $this->app->singleton('log', function() { |
|
43 | 43 | return new LogManager($this->app); |
44 | 44 | }); |
45 | 45 | } |