ViewAdapterAbstract::set()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 2
b 0
f 0
nc 2
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 2
rs 10
1
<?php
2
/**
3
 * View adapter and singleton functionality
4
 *
5
 * @file      ViewAdapterAbstract.php
6
 *
7
 * PHP version 8.0+
8
 *
9
 * @author    Alexander Yancharuk <alex at itvault dot info>
10
 * @copyright © 2012-2021 Alexander Yancharuk
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\DriverInterface;
19
use Traits\LazyCallsInterface;
20
use Traits\SingletonInstanceInterface;
21
use Veles\Traits\LazyCalls;
22
23
/**
24
 * Class ViewAdapterAbstract
25
 *
26
 * @author  Alexander Yancharuk <alex at itvault dot info>
27
 */
28
abstract class ViewAdapterAbstract implements
29
	LazyCallsInterface,
30
	DriverInterface,
31
	SingletonInstanceInterface
32
{
33
	/** @var mixed */
34
	protected $variables = [];
35
36
	use LazyCalls;
37
38
	/**
39
	 * Driver initialization
40
	 */
41
	abstract protected function __construct();
42
43
	/**
44
	 * Output method
45
	 *
46
	 * @param string $path Path to template
47
	 */
48
	abstract public function show($path);
49
50
	/**
51
	 * Output View into buffer and save it in variable
52
	 *
53
	 * @param string $path Path to template
54
	 * @return string View content
55
	 */
56
	abstract public function get($path);
57
58
	/**
59
	 * Check template cache status
60
	 *
61
	 * @param string $tpl Template file
62
	 * @return bool Cache status
63
	 */
64
	abstract public function isCached($tpl);
65
66
	/**
67
	 * Method for output variables setup
68
	 *
69
	 * @param mixed $vars Output variables or traversable class
70
	 */
71 13
	public function set($vars = [])
72
	{
73 13
		foreach ($vars as $prop => $value) {
74 13
			$this->variables[$prop] = $value;
75
		}
76
	}
77
78
	/**
79
	 * Output variables cleanup
80
	 *
81
	 * @param array $vars Array of variables names
82
	 */
83 2
	public function del(array $vars)
84
	{
85 2
		foreach ($vars as $var_name) {
86 2
			if (isset($this->variables[$var_name])) {
87 2
				unset($this->variables[$var_name]);
88
			}
89
		}
90
	}
91
}
92