Completed
Push — master ( 337deb...272f99 )
by Andreas
17:43
created

midcom_response_styled::send()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
/**
3
 * @package midcom
4
 * @author CONTENT CONTROL http://www.contentcontrol-berlin.de/
5
 * @copyright CONTENT CONTROL http://www.contentcontrol-berlin.de/
6
 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
7
 */
8
9
use Symfony\Component\HttpFoundation\Response;
10
11
/**
12
 * Wrapper for style(engine)d responses
13
 *
14
 * @package midcom
15
 */
16
class midcom_response_styled extends Response
17
{
18
    /**
19
     *
20
     * @var string
21
     */
22
    private $root_element;
23
24
    /**
25
     *
26
     * @var midcom_core_context
27
     */
28
    private $context;
29
30 272
    public function __construct(midcom_core_context $context, $root_element = 'ROOT')
31
    {
32 272
        parent::__construct();
33 272
        $this->context = $context;
34 272
        $this->root_element = $root_element;
35 272
        $this->content = $this->render();
36 272
    }
37
38
    public function sendContent()
39
    {
40
        echo $this->getContent();
41
    }
42
43 272
    private function render()
44
    {
45
        // Retrieve Metadata
46 272
        $nav = new midcom_helper_nav();
47 272
        if ($nav->get_current_leaf() === false) {
0 ignored issues
show
introduced by
The condition $nav->get_current_leaf() === false is always false.
Loading history...
48 242
            $meta = $nav->get_node($nav->get_current_node());
49
        } else {
50 30
            $meta = $nav->get_leaf($nav->get_current_leaf());
51
        }
52
53 272
        if ($this->context->get_key(MIDCOM_CONTEXT_PERMALINKGUID) === null) {
54 224
            $this->context->set_key(MIDCOM_CONTEXT_PERMALINKGUID, $meta[MIDCOM_NAV_GUID]);
55
        }
56
57 272
        if ($this->context->get_key(MIDCOM_CONTEXT_PAGETITLE) == '') {
58 146
            $this->context->set_key(MIDCOM_CONTEXT_PAGETITLE, $meta[MIDCOM_NAV_NAME]);
59
        }
60
61 272
        midcom::get()->style->enter_context($this->context);
62 272
        ob_start();
63 272
        if (midcom::get()->skip_page_style) {
64 254
            $this->context->show();
65
        } else {
66 18
            if ($this->context->id == 0) {
67
                // Let metadata service add its meta tags
68
                midcom::get()->metadata->populate_meta_head();
69
            }
70 18
            midcom_show_style($this->root_element);
71
        }
72
73 272
        midcom::get()->style->leave_context();
74 272
        return ob_get_clean();
75
    }
76
}
77