Skip to content

Commit 505041c

Browse files
authored
Merge pull request #7534 from kenjis/refactor-View
refactor: View
2 parents 1e8e60e + ec607be commit 505041c

1 file changed

Lines changed: 31 additions & 10 deletions

File tree

system/View/View.php

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -171,20 +171,27 @@ public function render(string $view, ?array $options = null, ?bool $saveData = n
171171
// multiple views are called in a view, it won't
172172
// clean it unless we mean it to.
173173
$saveData ??= $this->saveData;
174-
$fileExt = pathinfo($view, PATHINFO_EXTENSION);
175-
$realPath = empty($fileExt) ? $view . '.php' : $view; // allow Views as .html, .tpl, etc (from CI3)
176-
$this->renderVars['view'] = $realPath;
174+
175+
$fileExt = pathinfo($view, PATHINFO_EXTENSION);
176+
// allow Views as .html, .tpl, etc (from CI3)
177+
$this->renderVars['view'] = empty($fileExt) ? $view . '.php' : $view;
178+
177179
$this->renderVars['options'] = $options ?? [];
178180

179181
// Was it cached?
180182
if (isset($this->renderVars['options']['cache'])) {
181-
$cacheName = $this->renderVars['options']['cache_name'] ?? str_replace('.php', '', $this->renderVars['view']);
183+
$cacheName = $this->renderVars['options']['cache_name']
184+
?? str_replace('.php', '', $this->renderVars['view']);
182185
$cacheName = str_replace(['\\', '/'], '', $cacheName);
183186

184187
$this->renderVars['cacheName'] = $cacheName;
185188

186189
if ($output = cache($this->renderVars['cacheName'])) {
187-
$this->logPerformance($this->renderVars['start'], microtime(true), $this->renderVars['view']);
190+
$this->logPerformance(
191+
$this->renderVars['start'],
192+
microtime(true),
193+
$this->renderVars['view']
194+
);
188195

189196
return $output;
190197
}
@@ -193,7 +200,11 @@ public function render(string $view, ?array $options = null, ?bool $saveData = n
193200
$this->renderVars['file'] = $this->viewPath . $this->renderVars['view'];
194201

195202
if (! is_file($this->renderVars['file'])) {
196-
$this->renderVars['file'] = $this->loader->locateFile($this->renderVars['view'], 'Views', empty($fileExt) ? 'php' : $fileExt);
203+
$this->renderVars['file'] = $this->loader->locateFile(
204+
$this->renderVars['view'],
205+
'Views',
206+
empty($fileExt) ? 'php' : $fileExt
207+
);
197208
}
198209

199210
// locateFile will return an empty string if the file cannot be found.
@@ -233,10 +244,16 @@ public function render(string $view, ?array $options = null, ?bool $saveData = n
233244

234245
$output = $this->decorateOutput($output);
235246

236-
$this->logPerformance($this->renderVars['start'], microtime(true), $this->renderVars['view']);
247+
$this->logPerformance(
248+
$this->renderVars['start'],
249+
microtime(true),
250+
$this->renderVars['view']
251+
);
237252

238-
if (($this->debug && (! isset($options['debug']) || $options['debug'] === true))
239-
&& in_array(DebugToolbar::class, service('filters')->getFiltersClass()['after'], true)
253+
$afterFilters = service('filters')->getFiltersClass()['after'];
254+
if (
255+
($this->debug && (! isset($options['debug']) || $options['debug'] === true))
256+
&& in_array(DebugToolbar::class, $afterFilters, true)
240257
) {
241258
$toolbarCollectors = config(Toolbar::class)->collectors;
242259

@@ -253,7 +270,11 @@ public function render(string $view, ?array $options = null, ?bool $saveData = n
253270

254271
// Should we cache?
255272
if (isset($this->renderVars['options']['cache'])) {
256-
cache()->save($this->renderVars['cacheName'], $output, (int) $this->renderVars['options']['cache']);
273+
cache()->save(
274+
$this->renderVars['cacheName'],
275+
$output,
276+
(int) $this->renderVars['options']['cache']
277+
);
257278
}
258279

259280
$this->tempData = null;

0 commit comments

Comments
 (0)