Completed
Pull Request — master (#52)
by Wilmer
01:36
created

View::pushDynamicContent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
declare(strict_types = 1);
3
4
namespace Yiisoft\View;
5
6
use Psr\EventDispatcher\EventDispatcherInterface;
7
use Psr\Log\LoggerInterface;
8
use Yiisoft\I18n\Locale;
9
use Yiisoft\View\Event\AfterRender;
10
use Yiisoft\View\Event\BeforeRender;
11
use Yiisoft\View\Event\PageBegin;
12
use Yiisoft\View\Event\PageEnd;
13
use Yiisoft\Widget\Block;
14
use Yiisoft\Widget\ContentDecorator;
15
use Yiisoft\Widget\FragmentCache;
16
17
/**
18
 * View represents a view object in the MVC pattern.
19
 *
20
 * View provides a set of methods (e.g. {@see render()}) for rendering purpose.
21
 *
22
 * For more details and usage information on View, see the [guide article on views](guide:structure-views).
23
 */
24
class View implements DynamicContentAwareInterface
25
{
26
    /**
27
     * @var string $basePath view path
28
     */
29
    private $basePath;
30
31
    /**
32
     * @var array a list of named output blocks. The keys are the block names and the values are the corresponding block
33
     * content. You can call {@see beginBlock()} and {@see endBlock()} to capture small fragments of a view.
34
     * They can be later accessed somewhere else through this property.
35
     */
36
    private $blocks;
37
38
    /**
39
     * @var ViewContextInterface the context under which the {@see {renderFile()} method is being invoked.
40
     */
41
    public $context;
42
43
    /**
44
     * @var string the default view file extension. This will be appended to view file names if they don't have file
45
     * extensions.
46
     */
47
    public $defaultExtension = 'php';
48
49
    /**
50
     * @var mixed custom parameters that are shared among view templates.
51
     */
52
    public $params = [];
53
54
    /**
55
     * @var EventDispatcherInterface $eventDispatcher
56
     */
57
    protected $eventDispatcher;
58
59
    /**
60
     * @var array a list of available renderers indexed by their corresponding supported file extensions. Each renderer
61
     * may be a view renderer object or the configuration for creating the renderer object. For example, the
62
     * following configuration enables the Twig view renderer:
63
     *
64
     * ```php
65
     * [
66
     *     'twig' => ['__class' => \Yiisoft\Yii\Twig\ViewRenderer::class],
67
     * ]
68
     * ```
69
     *
70
     * If no renderer is available for the given view file, the view file will be treated as a normal PHP and rendered
71
     * via PhpTemplateRenderer.
72
     */
73
    protected $renderers = [];
74
75
    /**
76
     * @var Theme the theme object.
77
     */
78
    protected $theme;
79
80
    /**
81
     * @var DynamicContentAwareInterface[] a list of currently active dynamic content class instances.
82
     */
83
    private $cacheStack = [];
84
85
    /**
86
     * @var array a list of placeholders for embedding dynamic contents.
87
     */
88
    private $dynamicPlaceholders = [];
89
90
    /**
91
     * @var string $language
92
     */
93
    private $language = 'en';
94
95
    /**
96
     * @var LoggerInterface $logger
97
     */
98
    private $logger;
99
100
    /**
101
     * @var string $sourceLanguage
102
     */
103
    private $sourceLanguage = 'en';
104
105
    /**
106
     * @var Locale source locale used to find localized view file.
107
     */
108
    private $sourceLocale;
109
110
    /**
111
     * @var array the view files currently being rendered. There may be multiple view files being
112
     * rendered at a moment because one view may be rendered within another.
113
     */
114
    private $viewFiles = [];
115
116 78
    public function __construct(string $basePath, Theme $theme, EventDispatcherInterface $eventDispatcher, LoggerInterface $logger)
117
    {
118 78
        $this->basePath = $basePath;
119 78
        $this->theme = $theme;
120 78
        $this->eventDispatcher = $eventDispatcher;
121 78
        $this->logger = $logger;
122
    }
123
124
    public function getBasePath(): string
125
    {
126
        return $this->basePath;
127
    }
128
129
    public function setRenderers(array $renderers): void
130
    {
131
        $this->renderers = $renderers;
132
    }
133
134
    public function setSourceLanguage(string $language): void
135
    {
136
        $this->sourceLanguage = $language;
137
    }
138
139
    public function setLanguage(string $language): void
140
    {
141
        $this->language = $language;
142
    }
143
144
    /**
145
     * {@see blocks}
146
     *
147
     * @param array $value
148
     *
149
     * @return void
150
     */
151 1
    public function setBlocks(string $id, string $value): void
152
    {
153 1
        $this->blocks[$id] = $value;
154
    }
155
156
    /**
157
     * {@see blocks}
158
     *
159
     * @param string $value
160
     *
161
     * @return string
162
     */
163 2
    public function getBlock(string $value): string
164
    {
165 2
        if (isset($this->blocks[$value])) {
166 1
            return $this->blocks[$value];
167
        } else {
168 1
            throw new \InvalidArgumentException('Block: ' . $value.  ' not found.');
169
        }
170
    }
171
172
    /**
173
     * Renders a view.
174
     *
175
     * The view to be rendered can be specified in one of the following formats:
176
     *
177
     * - [path alias](guide:concept-aliases) (e.g. "@app/views/site/index");
178
     * - absolute path within application (e.g. "//site/index"): the view name starts with double slashes. The actual
179
     *   view file will be looked for under the [[Application::viewPath|view path]] of the application.
180
     * - absolute path within current module (e.g. "/site/index"): the view name starts with a single slash. The actual
181
     *   view file will be looked for under the [[Module::viewPath|view path]] of the [[Controller::module|current module]].
182
     * - relative view (e.g. "index"): the view name does not start with `@` or `/`. The corresponding view file will be
183
     *   looked for under the {@see ViewContextInterface::getViewPath()|view path} of the view `$context`.
184
     *   If `$context` is not given, it will be looked for under the directory containing the view currently
185
     *   being rendered (i.e., this happens when rendering a view within another view).
186
     *
187
     * @param string $view the view name.
188
     * @param array $params the parameters (name-value pairs) that will be extracted and made available in the view
189
     * file.
190
     * @param object $context the context to be assigned to the view and can later be accessed via [[context]] in the
191
     * view. If the context implements {@see ViewContextInterface}, it may also be used to locate
192
     * the view file corresponding to a relative view name.
193
     *
194
     * @return string the rendering result
195
     *
196
     * @throws InvalidCallException  if the view cannot be resolved.
197
     * @throws ViewNotFoundException if the view file does not exist.
198
     *
199
     * {@see renderFile()}
200
     */
201 2
    public function render($view, $params = [], $context = null)
202
    {
203 2
        $viewFile = $this->findTemplateFile($view, $context);
204 2
        return $this->renderFile($viewFile, $params, $context);
205
    }
206
207
    /**
208
     * Finds the view file based on the given view name.
209
     *
210
     * @param string $view the view name or the [path alias](guide:concept-aliases) of the view file. Please refer to
211
     * {@see render()} on how to specify this parameter.
212
     * @param object $context the context to be assigned to the view and can later be accessed via [[context]] in the
213
     * view. If the context implements [[ViewContextInterface]], it may also be used to locate the view
214
     * file corresponding to a relative view name.
215
     *
216
     * @throws InvalidCallException if a relative view name is given while there is no active context to determine the
217
     * corresponding view file.
218
     *
219
     * @return string the view file path. Note that the file may not exist.
220
     */
221 2
    protected function findTemplateFile(string $view, $context = null): string
222
    {
223 2
        if (strncmp($view, '//', 2) === 0) {
224
            // path relative to basePath e.g. "//layouts/main"
225 2
            $file = $this->basePath . '/' . ltrim($view, '/');
226 1
        } elseif ($context instanceof ViewContextInterface) {
227
            // path provided by context
228
            $file = $context->getViewPath() . '/' . $view;
229 1
        } elseif (($currentViewFile = $this->getRequestedViewFile()) !== false) {
230
            // path relative to currently rendered view
231 1
            $file = dirname($currentViewFile) . '/' . $view;
0 ignored issues
show
Bug introduced by
It seems like $currentViewFile can also be of type true; however, parameter $path of dirname() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

231
            $file = dirname(/** @scrutinizer ignore-type */ $currentViewFile) . '/' . $view;
Loading history...
232
        } else {
233
            throw new \RuntimeException("Unable to resolve view file for view '$view': no active view context.");
234
        }
235
236 2
        if (pathinfo($file, PATHINFO_EXTENSION) !== '') {
237 1
            return $file;
238
        }
239
240 1
        $path = $file . '.' . $this->defaultExtension;
241
242 1
        if ($this->defaultExtension !== 'php' && !is_file($path)) {
243
            $path = $file . '.php';
244
        }
245
246 1
        return $path;
247
    }
248
249
    /**
250
     * Renders a view file.
251
     *
252
     * If {@see theme} is enabled (not null), it will try to render the themed version of the view file as long as it
253
     * is available.
254
     *
255
     * If {@see renderers|renderer} is enabled (not null), the method will use it to render the view file. Otherwise,
256
     * it will simply include the view file as a normal PHP file, capture its output and
257
     * return it as a string.
258
     *
259
     * @param string $viewFile the view file. This can be either an absolute file path or an alias of it.
260
     * @param array $params the parameters (name-value pairs) that will be extracted and made available in the view
261
     * file.
262
     * @param object $context the context that the view should use for rendering the view. If null, existing [[context]]
263
     * will be used.
264
     *
265
     * @throws ViewNotFoundException if the view file does not exist
266
     *
267
     * @return string the rendering result
268
     */
269 34
    public function renderFile(string $viewFile, array $params = [], object $context = null): string
270
    {
271
        // TODO: these two match now
272 34
        $requestedFile = $viewFile;
273
274 34
        if ($this->theme !== null) {
275 34
            $viewFile = $this->theme->applyTo($viewFile);
276
        }
277 34
        if (is_file($viewFile)) {
278 34
            $viewFile = $this->localize($viewFile);
279
        } else {
280
            throw new ViewNotFoundException("The view file does not exist: $viewFile");
281
        }
282
283 34
        $oldContext = $this->context;
284 34
        if ($context !== null) {
285
            $this->context = $context;
286
        }
287 34
        $output = '';
288 34
        $this->viewFiles[] = [
289 34
            'resolved' => $viewFile,
290 34
            'requested' => $requestedFile,
291
        ];
292
293 34
        if ($this->beforeRender($viewFile, $params)) {
294 34
            $this->logger->debug("Rendering view file: $viewFile");
295 34
            $ext = pathinfo($viewFile, PATHINFO_EXTENSION);
296 34
            $renderer = $this->renderers[$ext] ?? new PhpTemplateRenderer();
297 34
            $output = $renderer->render($this, $viewFile, $params);
298
299 34
            $this->afterRender($viewFile, $params, $output);
300
        }
301
302 34
        array_pop($this->viewFiles);
303 34
        $this->context = $oldContext;
304
305 34
        return $output;
306
    }
307
308
    /**
309
     * Returns the localized version of a specified file.
310
     *
311
     * The searching is based on the specified language code. In particular, a file with the same name will be looked
312
     * for under the subdirectory whose name is the same as the language code. For example, given the file
313
     * "path/to/view.php" and language code "zh-CN", the localized file will be looked for as path/to/zh-CN/view.php".
314
     * If the file is not found, it will try a fallback with just a language code that is "zh" i.e. "path/to/zh/view.php".
315
     * If it is not found as well the original file will be returned.
316
     *
317
     * If the target and the source language codes are the same, the original file will be returned.
318
     *
319
     * @param string $file the original file
320
     * @param string|null $language the target language that the file should be localized to.
321
     * @param string|null $sourceLanguage the language that the original file is in.
322
     *
323
     * @return string the matching localized file, or the original file if the localized version is not found.
324
     * If the target and the source language codes are the same, the original file will be returned.
325
     */
326 35
    public function localize(string $file, ?string $language = null, ?string $sourceLanguage = null): string
327
    {
328 35
        $language = $language ?? $this->language;
329 35
        $sourceLanguage = $sourceLanguage ?? $this->sourceLanguage;
330
331 35
        if ($language === $sourceLanguage) {
332 35
            return $file;
333
        }
334 1
        $desiredFile = dirname($file) . DIRECTORY_SEPARATOR . $language . DIRECTORY_SEPARATOR . basename($file);
335 1
        if (is_file($desiredFile)) {
336 1
            return $desiredFile;
337
        }
338
339
        $language = substr($language, 0, 2);
340
        if ($language === $sourceLanguage) {
341
            return $file;
342
        }
343
        $desiredFile = dirname($file) . DIRECTORY_SEPARATOR . $language . DIRECTORY_SEPARATOR . basename($file);
344
345
        return is_file($desiredFile) ? $desiredFile : $file;
346
    }
347
348
    /**
349
     * @return string|bool the view file currently being rendered. False if no view file is being rendered.
350
     */
351 32
    public function getViewFile()
352
    {
353 32
        return empty($this->viewFiles) ? false : end($this->viewFiles)['resolved'];
354
    }
355
356
    /**
357
     * @return string|bool the requested view currently being rendered. False if no view file is being rendered.
358
     */
359 1
    protected function getRequestedViewFile()
360
    {
361 1
        return empty($this->viewFiles) ? false : end($this->viewFiles)['requested'];
362
    }
363
364
    /**
365
     * This method is invoked right before {@see renderFile()} renders a view file.
366
     *
367
     * The default implementation will trigger the {@see BeforeRender()} event. If you override this method, make sure
368
     * you call the parent implementation first.
369
     *
370
     * @param string $viewFile the view file to be rendered.
371
     * @param array $params the parameter array passed to the {@see render()} method.
372
     *
373
     * @return bool whether to continue rendering the view file.
374
     */
375 34
    public function beforeRender(string $viewFile, array $params): bool
376
    {
377 34
        $event = new BeforeRender($viewFile, $params);
378 34
        $this->eventDispatcher->dispatch($event);
379
380 34
        return !$event->isPropagationStopped();
381
    }
382
383
    /**
384
     * This method is invoked right after {@see renderFile()} renders a view file.
385
     *
386
     * The default implementation will trigger the {@see AfterRender} event. If you override this method, make sure you
387
     * call the parent implementation first.
388
     *
389
     * @param string $viewFile the view file being rendered.
390
     * @param array  $params the parameter array passed to the {@see render()} method.
391
     * @param string $output the rendering result of the view file. Updates to this parameter
392
     * will be passed back and returned by {@see renderFile()}.
393
     */
394 34
    public function afterRender(string $viewFile, array $params, &$output): string
395
    {
396 34
        $event = new AfterRender($viewFile, $params, $output);
397 34
        $this->eventDispatcher->dispatch($event);
398
399 34
        return $event->getResult();
400
    }
401
402
    /**
403
     * Renders dynamic content returned by the given PHP statements.
404
     *
405
     * This method is mainly used together with content caching (fragment caching and page caching) when some portions
406
     * of the content (called *dynamic content*) should not be cached. The dynamic content must be returned by some PHP
407
     * statements. You can optionally pass additional parameters that will be available as variables in the PHP
408
     * statement:.
409
     *
410
     * ```php
411
     * <?= $this->renderDynamic('return foo($myVar);', [
412
     *     'myVar' => $model->getMyComplexVar(),
413
     * ]) ?>
414
     * ```
415
     *
416
     * @param string $statements the PHP statements for generating the dynamic content.
417
     * @param array  $params the parameters (name-value pairs) that will be extracted and made
418
     * available in the $statement context. The parameters will be stored in the cache and be reused
419
     * each time $statement is executed. You should make sure, that these are safely serializable.
420
     *
421
     * @return string the placeholder of the dynamic content, or the dynamic content if there is no active content
422
     *                cache currently.
423
     */
424
    public function renderDynamic(string $statements, array $params = []): string
425
    {
426
        if (!empty($params)) {
427
            $statements = 'extract(unserialize(\'' . str_replace(['\\', '\''], ['\\\\', '\\\''], serialize($params)) . '\'));' . $statements;
428
        }
429
430
        if (!empty($this->cacheStack)) {
431
            $n = count($this->dynamicPlaceholders);
432
            $placeholder = "<![CDATA[YII-DYNAMIC-$n]]>";
433
            $this->addDynamicPlaceholder($placeholder, $statements);
434
435
            return $placeholder;
436
        }
437
438
        return $this->evaluateDynamicContent($statements);
439
    }
440
441
    /**
442
     * Get source locale.
443
     *
444
     * @return Locale
445
     */
446
    public function getSourceLocale(): Locale
447
    {
448
        if ($this->sourceLocale === null) {
449
            $this->sourceLocale = Locale::create('en-US');
0 ignored issues
show
Bug introduced by
The method create() does not exist on Yiisoft\I18n\Locale. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

449
            /** @scrutinizer ignore-call */ 
450
            $this->sourceLocale = Locale::create('en-US');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
450
        }
451
452
        return $this->sourceLocale;
453
    }
454
455
    /**
456
     * Set source locale.
457
     *
458
     * @param string $locale
459
     * @return self
460
     */
461
    public function setSourceLocale(string $locale): self
462
    {
463
        $this->sourceLocale = Locale::create($locale);
464
465
        return $this;
466
    }
467
468
    public function getDynamicPlaceholders(): array
469
    {
470
        return $this->dynamicPlaceholders;
471
    }
472
473
    public function setDynamicPlaceholders(array $placeholders): void
474
    {
475
        $this->dynamicPlaceholders = $placeholders;
476
    }
477
478
    public function addDynamicPlaceholder(string $placeholder, string $statements): void
479
    {
480
        foreach ($this->cacheStack as $cache) {
481
            $cache->addDynamicPlaceholder($placeholder, $statements);
482
        }
483
484
        $this->dynamicPlaceholders[$placeholder] = $statements;
485
    }
486
487
    /**
488
     * Evaluates the given PHP statements.
489
     *
490
     * This method is mainly used internally to implement dynamic content feature.
491
     *
492
     * @param string $statements the PHP statements to be evaluated.
493
     *
494
     * @return mixed the return value of the PHP statements.
495
     */
496
    public function evaluateDynamicContent(string $statements)
497
    {
498
        return eval($statements);
0 ignored issues
show
introduced by
The use of eval() is discouraged.
Loading history...
499
    }
500
501
    /**
502
     * Returns a list of currently active dynamic content class instances.
503
     *
504
     * @return DynamicContentAwareInterface[] class instances supporting dynamic contents.
505
     */
506
    public function getDynamicContents()
507
    {
508
        return $this->cacheStack;
509
    }
510
511
    /**
512
     * Adds a class instance supporting dynamic contents to the end of a list of currently active dynamic content class
513
     * instances.
514
     *
515
     * @param DynamicContentAwareInterface $instance class instance supporting dynamic contents.
516
     *
517
     * @return void
518
     */
519
    public function pushDynamicContent(DynamicContentAwareInterface $instance): void
520
    {
521
        $this->cacheStack[] = $instance;
522
    }
523
524
    /**
525
     * Removes a last class instance supporting dynamic contents from a list of currently active dynamic content class
526
     * instances.
527
     *
528
     * @return void
529
     */
530
    public function popDynamicContent(): void
531
    {
532
        array_pop($this->cacheStack);
533
    }
534
535
    /**
536
     * Begins recording a block.
537
     *
538
     * This method is a shortcut to beginning {@see Block}.
539
     *
540
     * @param string $id the block ID.
541
     * @param bool $renderInPlace whether to render the block content in place.
542
     * Defaults to false, meaning the captured block will not be displayed.
543
     *
544
     * @return Block the Block widget instance
545
     */
546
    public function beginBlock(string $id, $renderInPlace = false): Block
547
    {
548
        return Block::begin()
549
            ->id($id)
550
            ->renderInPlace($renderInPlace);
551
    }
552
553
    /**
554
     * Ends recording a block.
555
     *
556
     * @return void
557
     */
558
    public function endBlock(): void
559
    {
560
        Block::end();
561
    }
562
563
    /**
564
     * Begins the rendering of content that is to be decorated by the specified view.
565
     *
566
     * This method can be used to implement nested layout. For example, a layout can be embedded in another layout file
567
     * specified as '@app/views/layouts/base.php' like the following:
568
     *
569
     * ```php
570
     * <?php $this->beginContent('@app/views/layouts/base.php'); ?>
571
     * //...layout content here...
572
     * <?php $this->endContent(); ?>
573
     * ```
574
     *
575
     * @param string $viewFile the view file that will be used to decorate the content enclosed by this widget. This can
576
     * be specified as either the view file path or [path alias](guide:concept-aliases).
577
     * @param array $params the variables (name => value) to be extracted and made available in the decorative view.
578
     *
579
     * @return ContentDecorator the ContentDecorator widget instance
580
     *
581
     * {@see ContentDecorator}
582
     */
583
    public function beginContent(string $viewFile, array $params = []): ContentDecorator
584
    {
585
        return ContentDecorator::begin()
586
            ->params($params)
587
            ->viewFile($viewFile);
588
    }
589
590
    /**
591
     * Ends the rendering of content.
592
     *
593
     * @return void
594
     */
595
    public function endContent(): void
596
    {
597
        ContentDecorator::end();
598
    }
599
600
    /**
601
     * Begins fragment caching.
602
     *
603
     * This method will display cached content if it is available. If not, it will start caching and would expect an
604
     * {@see endCache()} call to end the cache and save the content into cache. A typical usage of fragment caching is
605
     * as follows,
606
     *
607
     * ```php
608
     * if ($this->beginCache($id)) {
609
     *     // ...generate content here
610
     *     $this->endCache();
611
     * }
612
     * ```
613
     *
614
     * @param string $id a unique ID identifying the fragment to be cached.
615
     * @param array $properties initial property values for {@see FragmentCache}
616
     *
617
     * @return bool whether you should generate the content for caching.
618
     * False if the cached version is available.
619
     */
620
    public function beginCache(string $id, array $properties = []): bool
621
    {
622
        $properties['id'] = $id;
623
        $properties['view'] = $this;
624
        $cache = FragmentCache::begin($properties);
0 ignored issues
show
Unused Code introduced by
The call to Yiisoft\Widget\Widget::begin() has too many arguments starting with $properties. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

624
        /** @scrutinizer ignore-call */ 
625
        $cache = FragmentCache::begin($properties);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
625
        if ($cache->getCachedContent() !== false) {
626
            $this->endCache();
627
628
            return false;
629
        }
630
631
        return true;
632
    }
633
634
    /**
635
     * Ends fragment caching.
636
     *
637
     * @return void
638
     */
639
    public function endCache(): void
640
    {
641
        FragmentCache::end();
642
    }
643
644
    /**
645
     * Marks the beginning of a page.
646
     *
647
     * @return void
648
     */
649 32
    public function beginPage(): void
650
    {
651 32
        ob_start();
652 32
        ob_implicit_flush(0);
653
654 32
        $this->eventDispatcher->dispatch(new PageBegin($this->getViewFile()));
0 ignored issues
show
Bug introduced by
It seems like $this->getViewFile() can also be of type boolean; however, parameter $file of Yiisoft\View\Event\PageBegin::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

654
        $this->eventDispatcher->dispatch(new PageBegin(/** @scrutinizer ignore-type */ $this->getViewFile()));
Loading history...
655
    }
656
657
    /**
658
     * Marks the ending of a page.
659
     *
660
     * @return void
661
     */
662
    public function endPage(): void
663
    {
664
        $this->eventDispatcher->dispatch(new PageEnd($this->getViewFile()));
0 ignored issues
show
Bug introduced by
It seems like $this->getViewFile() can also be of type boolean; however, parameter $file of Yiisoft\View\Event\PageEnd::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

664
        $this->eventDispatcher->dispatch(new PageEnd(/** @scrutinizer ignore-type */ $this->getViewFile()));
Loading history...
665
        ob_end_flush();
666
    }
667
}
668