Completed
Push — master ( 32cb15...ce22ce )
by Alexander
05:39 queued 02:43
created

ViewAdapterAbstract::set()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 6
rs 9.4286
cc 2
eloc 3
nc 2
nop 1
1
<?php
2
/**
3
 * View adapter and singleton functionality
4
 *
5
 * @file      ViewAdapterAbstract.php
6
 *
7
 * PHP version 5.4+
8
 *
9
 * @author    Alexander Yancharuk <alex at itvault dot info>
10
 * @copyright © 2012-2015 Alexander Yancharuk <alex at itvault at info>
11
 * @date      Чтв Сен  5 15:10:46 MSK 2013
12
 * @license   The BSD 3-Clause License
13
 *            <https://tldrlegal.com/license/bsd-3-clause-license-(revised)>
14
 */
15
16
namespace Veles\View\Adapters;
17
18
use Traits\LazyCalls;
19
20
/**
21
 * Class ViewAdapterAbstract
22
 *
23
 * @author  Alexander Yancharuk <alex at itvault dot info>
24
 */
25
abstract class ViewAdapterAbstract
26
{
27
	/** @var mixed */
28
	protected $variables;
29
30
	use LazyCalls;
31
32
	/**
33
	 * Driver initialization
34
	 */
35
	abstract protected function __construct();
36
37
	/**
38
	 * Output method
39
	 *
40
	 * @param string $path Path to template
41
	 */
42
	abstract public function show($path);
43
44
	/**
45
	 * Output View into buffer and save it in variable
46
	 *
47
	 * @param string $path Path to template
48
	 * @return string View content
49
	 */
50
	abstract public function get($path);
51
52
	/**
53
	 * Check template cache status
54
	 *
55
	 * @param string $tpl Template file
56
	 * @return bool Cache status
57
	 */
58
	abstract public function isCached($tpl);
59
60
	/**
61
	 * Method for output variables setup
62
	 *
63
	 * @param mixed $vars Output variables or traversable class
64
	 */
65
	public function set($vars = [])
66
	{
67
		foreach ($vars as $prop => $value) {
68
			$this->variables[$prop] = $value;
69
		}
70
	}
71
72
	/**
73
	 * Output variables cleanup
74
	 *
75
	 * @param array $vars Array of variables names
76
	 */
77
	public function del(array $vars)
78
	{
79
		foreach ($vars as $var_name) {
80
			if (isset($this->variables[$var_name])) {
81
				unset($this->variables[$var_name]);
82
			}
83
		}
84
	}
85
}
86