Completed
Push — master ( 272f99...43018c )
by Andreas
34:10 queued 15:31
created

midcom_response_styled::sendContent()   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 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 0
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 272
    private function render()
39
    {
40
        // Retrieve Metadata
41 272
        $nav = new midcom_helper_nav();
42 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...
43 242
            $meta = $nav->get_node($nav->get_current_node());
44
        } else {
45 30
            $meta = $nav->get_leaf($nav->get_current_leaf());
46
        }
47
48 272
        if ($this->context->get_key(MIDCOM_CONTEXT_PERMALINKGUID) === null) {
49 224
            $this->context->set_key(MIDCOM_CONTEXT_PERMALINKGUID, $meta[MIDCOM_NAV_GUID]);
50
        }
51
52 272
        if ($this->context->get_key(MIDCOM_CONTEXT_PAGETITLE) == '') {
53 146
            $this->context->set_key(MIDCOM_CONTEXT_PAGETITLE, $meta[MIDCOM_NAV_NAME]);
54
        }
55
56 272
        midcom::get()->style->enter_context($this->context);
57 272
        ob_start();
58 272
        if (midcom::get()->skip_page_style) {
59 254
            $this->context->show();
60
        } else {
61 18
            if ($this->context->id == 0) {
62
                // Let metadata service add its meta tags
63
                midcom::get()->metadata->populate_meta_head();
64
            }
65 18
            midcom_show_style($this->root_element);
66
        }
67
68 272
        midcom::get()->style->leave_context();
69 272
        return ob_get_clean();
70
    }
71
}
72