Passed
Push — master ( 43bacd...21e282 )
by Alexander
02:43
created

View::beginPage()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 6
ccs 0
cts 4
cp 0
rs 10
cc 2
nc 2
nop 0
crap 6
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
    public function beginPage(): void
27
    {
28
        ob_start();
29
        PHP_VERSION_ID >= 80000 ? ob_implicit_flush(false) : ob_implicit_flush(0);
30
31
        $this->eventDispatcher->dispatch(new PageBegin($this));
32
    }
33
34
    /**
35
     * Marks the ending of a view.
36
     */
37
    public function endPage(): void
38
    {
39
        $this->eventDispatcher->dispatch(new PageEnd($this));
40
41
        ob_end_flush();
42
    }
43
44 5
    protected function createBeforeRenderEvent(string $viewFile, array $parameters): StoppableEventInterface
45
    {
46 5
        return new BeforeRender($this, $viewFile, $parameters);
47
    }
48
49 5
    protected function createAfterRenderEvent(
50
        string $viewFile,
51
        array $parameters,
52
        string $result
53
    ): AfterRenderEventInterface {
54 5
        return new AfterRender($this, $viewFile, $parameters, $result);
55
    }
56
}
57