Completed
Push — 183-default-layout-ext ( a97107 )
by
unknown
10:37
created

DefaultLayoutRenderTemplate::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace League\Plates\Extension\LayoutSections;
4
5
use League\Plates;
6
7
final class DefaultLayoutRenderTemplate extends Plates\RenderTemplate\RenderTemplateDecorator
8
{
9
    private $layout_path;
10
11
    public function __construct(Plates\RenderTemplate $render, $layout_path) {
12
        parent::__construct($render);
13
        $this->layout_path = $layout_path;
14
    }
15
16
    public function renderTemplate(Plates\Template $template, Plates\RenderTemplate $rt = null) {
17
        $ref = $template->reference;
18
        $contents = $this->render->renderTemplate($template, $rt ?: $this);
19
20
        if ($ref()->get('layout') || $ref()->get('is_default_layout')) {
21
            return $contents;
22
        }
23
24
        $layout = $ref()->fork($this->layout_path, [], ['is_default_layout' => true]);
25
        $ref()->with('layout', $layout->reference);
26
27
        return $contents;
28
    }
29
30
    public static function factory($layout_path) {
31
        return function(Plates\RenderTemplate $rt) use ($layout_path) {
32
            return new self($rt, $layout_path);
33
        };
34
    }
35
}
36
37
38