Completed
Branch dbal-improvement (06db1a)
by Anton
03:59
created

Stempler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 63
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A compile() 0 4 1
A compileString() 0 6 1
A supervisor() 0 4 1
1
<?php
2
/**
3
 * Spiral Framework.
4
 *
5
 * @license   MIT
6
 * @author    Anton Titov (Wolfy-J)
7
 */
8
namespace Spiral\Stempler;
9
10
use Spiral\Stempler\Syntaxes\WooSyntax;
11
12
/**
13
 * Provides ability to compose multiple html files together.
14
 */
15
class Stempler
16
{
17
    /**
18
     * @var LoaderInterface
19
     */
20
    protected $loader = null;
21
22
    /**
23
     * @var SyntaxInterface
24
     */
25
    protected $syntax = null;
26
27
    /**
28
     * @var array
29
     */
30
    protected $options = [];
31
32
    /**
33
     * @param LoaderInterface $loader
34
     * @param string          $syntax Syntax class to be used.
35
     * @param array           $options
36
     */
37
    public function __construct($loader, $syntax = WooSyntax::class, array $options = [])
38
    {
39
        $this->loader = $loader;
40
        $this->syntax = new $syntax(!empty($options['strict']));
41
        $this->options = $options;
42
    }
43
44
    /**
45
     * Compile path.
46
     *
47
     * @param string $path
48
     * @return string
49
     */
50
    public function compile($path)
51
    {
52
        return $this->supervisor()->createNode($path);
53
    }
54
55
    /**
56
     * Compile string template.
57
     *
58
     * @param string $source
59
     * @return string
60
     */
61
    public function compileString($source)
62
    {
63
        $node = new Node($this->supervisor(), 'root', $source);
64
65
        return $node->compile();
66
    }
67
68
    /**
69
     * Create new instance of supervisor.
70
     *
71
     * @return Supervisor
72
     */
73
    protected function supervisor()
74
    {
75
        return new Supervisor($this->loader, $this->syntax);
76
    }
77
}