Completed
Push — v4.0-dev ( b01e70 )
by
unknown
01:53
created

Sections::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace League\Plates\Template;
4
5
/** A simple store for managing section content. This needs to be a mutable object
6
    so that references can be shared across templates. */
7
final class Sections
8
{
9
    private $sections;
10
11
    public function __construct(array $sections = []) {
12
        $this->sections = $sections;
13
    }
14
15
    public function add($name, $content) {
16
        $this->sections[$name] = $content;
17
    }
18
19
    public function append($name, $content) {
20
        $this->sections[$name] = ($this->get($name) ?: '') . $content;
21
    }
22
23
    public function prepend($name, $content) {
24
        $this->sections[$name] = $content . ($this->get($name) ?: '');
25
    }
26
27
    public function clear($name) {
28
        unset($this->sections[$name]);
29
    }
30
31
    public function get($name) {
32
        return array_key_exists($name, $this->sections)
33
            ? $this->sections[$name]
34
            : null;
35
    }
36
37
    public function merge(Sections $sections) {
38
        return new self(array_merge($this->sections, $sections->sections));
39
    }
40
}
41