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

LazyContent::__toString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 9
rs 9.6666
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