Completed
Push — master ( cbb4bb...9fe020 )
by Mikael
10:38
created

Page::render()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 24
ccs 0
cts 9
cp 0
rs 8.9713
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 2
crap 2
1
<?php
2
3
namespace Anax\Page;
4
5
use \Anax\DI\InjectionAwareInterface;
6
use \Anax\DI\InjectionAwareTrait;
7
8
/**
9
 * A default page rendering class.
10
 */
11
class Page implements /* PageRenderInterface, */ InjectionAwareInterface
12
{
13
    use InjectionAwareTrait;
14
15
16
17
    /**
18
     * @var string $namespace A namespace to prepend each template file.
19
     */
20
    private $namespace = "anax/v1";
21
22
23
24
    /**
25
     * Render a standard web page using a specific layout.
26
     *
27
     * @param array   $data   variables to expose to layout view.
28
     * @param integer $status code to use when delivering the result.
29
     *
30
     * @return void
31
     *
32
     * @SuppressWarnings(PHPMD.ExitExpression)
33
     */
34
    public function render($data, $status = 200)
35
    {
36
        // Get the view container, holding all views
37
        $view = $this->di->get("view");
38
39
        // Add static assets
40
        // $data["favicon"] = "favicon.ico";
41
        // $data["stylesheets"] = ["css/style.css"];
42
        // $data["javascripts"] = ["js/main.js"];
43
44
        // Add views for common header, navbar and footer
45
        $view->add("{$this->namespace}/header/default", $data, "header");
46
        $view->add("{$this->namespace}/navbar/default", $data, "navbar");
47
        $view->add("{$this->namespace}/footer/default", $data, "footer");
48
49
        // Add view for the overall layout, use region "layout"
50
        $view->add("{$this->namespace}/layout/default", $data, "layout");
51
52
        // Render all views, using the region "layout",
53
        // add to response and send.
54
        $body = $view->renderBuffered("layout");
55
        $this->di->get("response")->setBody($body)->send($status);
56
        exit;
57
    }
58
}
59