Completed
Push — v4.0 ( 3a8f05...488a49 )
by
unknown
03:09
created

LazyContent::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace League\Plates\Content;
4
5
use League\Plates;
6
7
class LazyContent implements Plates\Content
8
{
9
    private $build_content;
10
    private $content;
11
12
    public function __construct(callable $build_content) {
13
        $this->build_content = $build_content;
14
    }
15
16
    public static function fromTemplate(Plates\Template $template) {
17
        return new self([$template, 'getContent']);
18
    }
19
20
    public function __toString() {
21
        if ($this->content !== null) {
22
            return $this->content;
23
        }
24
25
        $this->content = (string) call_user_func($this->build_content);
26
27
        return $this->content;
28
    }
29
}
30