Completed
Push — master ( 4b2726...162df7 )
by Hong
03:18
created

Template::getOutput()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 2
eloc 8
nc 2
nop 1
1
<?php
2
/**
3
 * Phossa Project
4
 *
5
 * PHP version 5.4
6
 *
7
 * @category  Library
8
 * @package   Phossa2\Query
9
 * @copyright Copyright (c) 2016 phossa.com
10
 * @license   http://mit-license.org/ MIT License
11
 * @link      http://www.phossa.com/
12
 */
13
/*# declare(strict_types=1); */
14
15
namespace Phossa2\Query\Misc;
16
17
use Phossa2\Query\Traits\Clause\QuoteTrait;
18
use Phossa2\Query\Interfaces\TemplateInterface;
19
20
/**
21
 * Template
22
 *
23
 * Clause template
24
 *
25
 * @package Phossa2\Query
26
 * @author  Hong Zhang <[email protected]>
27
 * @see     TemplateInterface
28
 * @version 2.0.0
29
 * @since   2.0.0 added
30
 */
31
class Template implements TemplateInterface
32
{
33
    use QuoteTrait;
34
35
    /**
36
     * @var    string
37
     * @access protected
38
     */
39
    protected $template;
40
41
    /**
42
     * @var    string|string[]
43
     * @access protected
44
     */
45
    protected $col;
46
47
    /**
48
     * @param  string $template
49
     * @param  string|string[] $col column[s]
50
     * @access public
51
     */
52
    public function __construct(/*# string */ $template, $col)
53
    {
54
        $this->template = $template;
55
        $this->col = $col;
56
    }
57
58
    /**
59
     * Get output of the template base on settings
60
     *
61
     * @param  array $settings
62
     * @return string
63
     * @access public
64
     * @api
65
     */
66
    public function getOutput(array $settings)/*# : string */
67
    {
68
        $quoted = [];
69
        foreach ((array) $this->col as $c) {
70
            $quoted[] = $this->quote(
71
                $c,
72
                $settings['quotePrefix'],
73
                $settings['quoteSuffix']
74
            );
75
        }
76
        return vsprintf($this->template, $quoted);
77
    }
78
}
79