Completed
Push — auto-escape ( ea99df )
by
unknown
13:49
created

EscapedProxy::__unwrap()   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 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace League\Plates\Extension\AutoEscape;
4
5
abstract class EscapedProxy
6
{
7
    protected $escape;
8
    protected $wrapped;
9
10
    protected function __construct($wrapped, callable $escape) {
11
        $this->wrapped = $wrapped;
12
        $this->escape = $escape;
13
    }
14
15
    public function __unwrap() {
16
        return $this->wrapped;
17
    }
18
19
    public function __toString() {
20
        return ($this->escape)($this->wrapped);
21
    }
22
23
    public static function create($wrapped, callable $escape) {
24
        if (is_object($wrapped) || is_array($wrapped)) {
25
            return new ObjectEscapedProxy($wrapped, $escape);
26
        }
27
        if (is_string($wrapped)) {
28
            return new ScalarEscapedProxy($wrapped, $escape);
29
        }
30
31
        return $wrapped;
32
    }
33
}
34