• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ICanBoogie / View / 4140329668

pending completion
4140329668

push

github

Olivier Laviale
Change partial() param order

69 of 102 relevant lines covered (67.65%)

1.1 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

45.45
/lib/RenderTrait.php
1
<?php
2

3
namespace ICanBoogie\View;
4

5
use ICanBoogie\Routing\ControllerAbstract;
6

7
use function assert;
8

9
/**
10
 * A trait for {@link ControllerAbstract}.
11
 */
12
trait RenderTrait
13
{
14
    /**
15
     * Creates a view.
16
     *
17
     * The `template` and the `layout` are pre-determined by the view provider,
18
     * but can be overloaded.
19
     *
20
     * @param array<string, mixed>|null $locals
21
     */
22
    private function view(
23
        mixed $content = null,
24
        string $template = null,
25
        string $layout = null,
26
        array $locals = null,
27
    ): View {
28
        assert($this instanceof ControllerAbstract);
29
        assert(($this->view_provider ?? null) instanceof ViewProvider);
30

31
        $view = $this->view_provider->view_for_controller($this);
1✔
32

33
        if ($content !== null) {
1✔
34
            $view->content = $content;
1✔
35
        }
36
        if ($template !== null) {
1✔
37
            $view->template = $template;
1✔
38
        }
39
        if ($layout !== null) {
1✔
40
            $view->layout = $layout;
1✔
41
        }
42
        if ($locals !== null) {
1✔
43
            $view->assign($locals);
1✔
44
        }
45

46
        return $view;
1✔
47
    }
48

49
    /**
50
     * Creates a view with {@link view()} and renders a string.
51
     *
52
     * @param array<string, mixed>|null $locals
53
     */
54
    private function render_to_string(
55
        mixed $content = null,
56
        string $template = null,
57
        string $layout = null,
58
        array $locals = null,
59
    ): string {
60
        return $this->view(
×
61
            content: $content,
×
62
            template: $template,
×
63
            layout: $layout,
×
64
            locals: $locals,
×
65
        )->render();
×
66
    }
67

68
    /**
69
     * Creates a view with {@link view()} and renders as response's body.
70
     *
71
     * @param array<string, mixed>|null $locals
72
     */
73
    private function render(
74
        mixed $content = null,
75
        string $template = null,
76
        string $layout = null,
77
        array $locals = null,
78
    ): void {
79
        $this->response->body = $this->view(
×
80
            content: $content,
×
81
            template: $template,
×
82
            layout: $layout,
×
83
            locals: $locals,
×
84
        )->render();
×
85
    }
86
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc