Passed
Push — master ( 2b3fea...b557be )
by Alexander
02:27
created

View::clear()   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
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\View;
6
7
use Psr\EventDispatcher\StoppableEventInterface;
8
use Yiisoft\View\Event\AfterRenderEventInterface;
9
use Yiisoft\View\Event\View\AfterRender;
10
use Yiisoft\View\Event\View\BeforeRender;
11
use Yiisoft\View\Event\View\PageBegin;
12
use Yiisoft\View\Event\View\PageEnd;
13
14
use function ob_end_flush;
15
use function ob_implicit_flush;
16
use function ob_start;
17
18
/**
19
 * View represents an instance of a view for use in an any environment.
20
 *
21
 * View provides a set of methods (e.g. {@see View::render()}) for rendering purpose.
22
 *
23
 * @psalm-suppress PropertyNotSetInConstructor
24
 */
25
final class View implements ViewInterface
26
{
27
    use ViewTrait;
28
29
    /**
30
     * Clears the data for working with the event loop.
31
     */
32
    public function clear(): void
33
    {
34
        $this->viewFiles = [];
35
    }
36
37
    /**
38
     * Marks the beginning of a view.
39
     */
40 1
    public function beginPage(): void
41
    {
42 1
        ob_start();
43
        /** @psalm-suppress InvalidArgument */
44 1
        PHP_VERSION_ID >= 80000 ? ob_implicit_flush(false) : ob_implicit_flush(0);
45
46 1
        $this->eventDispatcher->dispatch(new PageBegin($this));
47 1
    }
48
49
    /**
50
     * Marks the ending of a view.
51
     */
52 1
    public function endPage(): void
53
    {
54 1
        $this->eventDispatcher->dispatch(new PageEnd($this));
55
56 1
        ob_end_flush();
57 1
    }
58
59 7
    protected function createBeforeRenderEvent(string $viewFile, array $parameters): StoppableEventInterface
60
    {
61 7
        return new BeforeRender($this, $viewFile, $parameters);
62
    }
63
64 7
    protected function createAfterRenderEvent(
65
        string $viewFile,
66
        array $parameters,
67
        string $result
68
    ): AfterRenderEventInterface {
69 7
        return new AfterRender($this, $viewFile, $parameters, $result);
70
    }
71
}
72