Passed
Push — master ( 2af18a...ebd8c1 )
by Alexander
03:43
created

View::createAfterRenderEvent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 6
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 3
crap 1
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
/**
15
 * View represents a view object in the MVC pattern.
16
 *
17
 * View provides a set of methods (e.g. {@see View::render()}) for rendering purpose.
18
 *
19
 * For more details and usage information on View, see the [guide article on views](guide:structure-views).
20
 */
21
final class View extends BaseView
22
{
23
    /**
24
     * Marks the beginning of a view.
25
     */
26 1
    public function beginPage(): void
27
    {
28 1
        ob_start();
29
        /** @psalm-suppress PossiblyFalseArgument */
30 1
        PHP_VERSION_ID >= 80000 ? ob_implicit_flush(false) : ob_implicit_flush(0);
31
32 1
        $this->eventDispatcher->dispatch(new PageBegin($this));
33 1
    }
34
35
    /**
36
     * Marks the ending of a view.
37
     */
38 1
    public function endPage(): void
39
    {
40 1
        $this->eventDispatcher->dispatch(new PageEnd($this));
41
42 1
        ob_end_flush();
43 1
    }
44
45 6
    protected function createBeforeRenderEvent(string $viewFile, array $parameters): StoppableEventInterface
46
    {
47 6
        return new BeforeRender($this, $viewFile, $parameters);
48
    }
49
50 6
    protected function createAfterRenderEvent(
51
        string $viewFile,
52
        array $parameters,
53
        string $result
54
    ): AfterRenderEventInterface {
55 6
        return new AfterRender($this, $viewFile, $parameters, $result);
56
    }
57
}
58