SmartyAdapter::isCached()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Adapter for Smarty
4
 *
5
 * @file      SmartyAdapter.php
6
 *
7
 * PHP version 8.0+
8
 * Smarty version 3+
9
 *
10
 * @author    Alexander Yancharuk <alex at itvault dot info>
11
 * @copyright © 2012-2021 Alexander Yancharuk
12
 * @date      2013-05-18 17:59
13
 * @license   The BSD 3-Clause License
14
 *            <https://tldrlegal.com/license/bsd-3-clause-license-(revised)>
15
 */
16
17
namespace Veles\View\Adapters;
18
19
use Exception;
20
use /** @noinspection PhpUndefinedClassInspection */ Smarty;
21
22
/**
23
 * Class SmartyAdapter
24
 *
25
 * @author  Alexander Yancharuk <alex at itvault dot info>
26
 */
27
class SmartyAdapter extends ViewAdapterAbstract
28
{
29
	/** @var  array */
30
	protected static $calls = [];
31
	/** @var $this */
32
	protected static $instance;
33
34
	/**
35
	 * Constructor
36
	 */
37 7
	public function __construct()
38
	{
39
		/** @noinspection PhpUndefinedClassInspection */
40 7
		$this->setDriver(new Smarty);
41
	}
42
43
	/**
44
	 * Method for output variables setup
45
	 *
46
	 * @param mixed $vars Output variables array or traversable class
47
	 */
48 1
	public function set($vars = [])
49
	{
50 1
		foreach ($vars as $name => $value) {
51 1
			$this->getDriver()->assign($name, $value);
52
		}
53
	}
54
55
	/**
56
	 * Output variables cleanup
57
	 *
58
	 * @param array $vars Variables array for cleanup
59
	 * @throws Exception
60
	 */
61 1
	public function del(array $vars)
62
	{
63 1
		foreach ($vars as $name) {
64 1
			$this->getDriver()->clearAssign($name);
65
		}
66
	}
67
68
	/**
69
	 * Output method
70
	 *
71
	 * @param string $path Path to template
72
	 */
73 1
	public function show($path)
74
	{
75 1
		$this->getDriver()->display($path);
76
	}
77
78
	/**
79
	 * Return value of View compilation
80
	 *
81
	 * @param string $path Path to template
82
	 * @return string View content
83
	 */
84 1
	public function get($path)
85
	{
86 1
		return $this->getDriver()->fetch($path);
87
	}
88
89
	/**
90
	 * Clear template cache
91
	 *
92
	 * @param string $tpl
93
	 * @return mixed
94
	 */
95 1
	public function clearCache($tpl)
96
	{
97 1
		return $this->getDriver()->clearCache($tpl);
98
	}
99
100
	/**
101
	 * Clear all template caches
102
	 *
103
	 * @param mixed $exp_time
104
	 * @return mixed
105
	 */
106 1
	public function clearAllCache($exp_time = null)
107
	{
108 1
		return $this->getDriver()->clearAllCache($exp_time);
109
	}
110
111
	/**
112
	 * Check is template already cached
113
	 * @param $tpl
114
	 * @return bool
115
	 */
116 1
	public function isCached($tpl)
117
	{
118 1
		return $this->getDriver()->isCached($tpl);
119
	}
120
}
121