Completed
Pull Request — master (#399)
by Anton
04:15
created

Layout::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 8
ccs 0
cts 5
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Bluz Framework Component
4
 *
5
 * @copyright Bluz PHP Team
6
 * @link https://github.com/bluzphp/framework
7
 */
8
9
declare(strict_types=1);
10
11
namespace Bluz\Layout;
12
13
use Bluz\Common\Container\RegularAccess;
14
use Bluz\View\View;
15
16
/**
17
 * Layout
18
 *
19
 * @package Bluz\Layout
20
 * @author  Anton Shevchuk
21
 * @link    https://github.com/bluzphp/framework/wiki/Layout
22
 *
23
 * @method array|null  breadCrumbs(array $data = [])
24
 * @method string|null headScript(string $src = null, array $attributes = [])
25
 * @method string|null headScriptBlock(string $code = null)
26
 * @method string|null headStyle(string $href = null, string $media = 'all')
27
 * @method string|null link(string $src = null, string $rel = 'stylesheet')
28
 * @method string|null meta(string $name = null, string $content = null)
29
 * @method string|null title(string $title = null, $position = 'replace', $separator = ' :: ')
30
 */
31
class Layout extends View
32
{
33
    use RegularAccess;
34
35
    /**
36
     * @var mixed content container, usually is instance of View
37
     */
38
    protected $content;
39
40
    /**
41
     * Layout constructor
42
     *  - init Layout helpers
43
     *  - call parent View constructor
44
     */
45
    public function __construct()
46
    {
47
        // init layout helper path
48
        $this->addHelperPath(dirname(__FILE__) . '/Helper/');
49
50
        // init view helper path
51
        parent::__construct();
52
    }
53
54
    /**
55
     * Get content
56
     *
57
     * @return View
58
     */
59
    public function getContent()
60
    {
61
        return $this->content;
62
    }
63
64
    /**
65
     * Set content
66
     *
67
     * @param  View|callable $content
68
     * @return void
69
     */
70
    public function setContent($content)
71
    {
72
        try {
73
            if (is_callable($content)) {
74
                $content = $content();
75
            }
76
            $this->content = $content;
77
        } catch (\Exception $e) {
78
            $this->content = $e->getMessage();
79
        }
80
    }
81
}
82