Completed
Push — master ( 816e5a...57fb58 )
by Restu
11:24
created

BasicConvert::setContent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
namespace JayaCode\Framework\Core\View\Converter;
3
4
class BasicConvert implements Converter
5
{
6
    protected $content;
7
8
    protected $options = [
9
        "preg_replace" => [
10
            [
11
                '/{{/',
12
                '/}}/',
13
                '/\[\[/',
14
                '/\]\]/',
15
                '/^\s*@(.*)$/m',
16
                '/^\s*\[@\s*parent\s*(\w*)\s*@\]\s*$/m',
17
                '/\s*\[@\s*content\s*(\w*)\s*@\](.*)\[@\s*endcontent\s*@\]/Usm'
18
            ],
19
            [
20
                '<?php echo(htmlspecialchars(',
21
22
                ")); ?>",
23
24
                '<?php ',
25
26
                " ?>",
27
28
                "<?php \\1 ?>",
29
30
                "<?php \$this->setParent('\\1'); ?>",
31
32
                " <?php if (array_key_exists('\\1', \$this->contentParent)) {
33
                    print(\$this->contentParent['\\1']);
34
                } elseif (!\$this->parent) { ?>
35
                    \\2
36
                <?php } else { ?>
37
                    <?php ob_start(); ?> \\2 <?php \$this->contentParent['\\1'] = ob_get_contents(); ob_end_clean(); ?>
38
                <?php } ?>"
39
            ]
40
        ],
41
    ];
42
43
    public function setContent($content)
44
    {
45
        $this->content = $content;
46
    }
47
48
    public function build($content = null, $options = array())
49
    {
50
        $this->options = $options + $this->options;
51
52
        if (!is_null($this->content)) {
53
            $content = $this->content;
54
        }
55
56
        return preg_replace($this->options['preg_replace'][0], $this->options['preg_replace'][1], $content);
57
    }
58
}
59