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

View   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 30.76%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 5
eloc 8
c 2
b 1
f 0
dl 0
loc 34
ccs 4
cts 13
cp 0.3076
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A createAfterRenderEvent() 0 6 1
A createBeforeRenderEvent() 0 3 1
A beginPage() 0 6 2
A endPage() 0 5 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
    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