1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Zikula package. |
7
|
|
|
* |
8
|
|
|
* Copyright Zikula Foundation - https://ziku.la/ |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Zikula\ExtensionsModule; |
15
|
|
|
|
16
|
|
|
use Zikula\ExtensionsModule\Api\ApiInterface\VariableApiInterface; |
17
|
|
|
use Zikula\ExtensionsModule\Api\VariableApi; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class ExtensionVariablesTrait |
21
|
|
|
*/ |
22
|
|
|
trait ExtensionVariablesTrait |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var VariableApi |
26
|
|
|
*/ |
27
|
|
|
private $variableApi; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var string the name of the extension in use |
31
|
|
|
*/ |
32
|
|
|
private $extensionName; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Convenience shortcut to get extension variable. |
36
|
|
|
* |
37
|
|
|
* @param mixed $default |
38
|
|
|
* @return mixed |
39
|
|
|
*/ |
40
|
|
|
public function getVar(string $variableName, $default = false) |
41
|
|
|
{ |
42
|
|
|
return $this->variableApi->get($this->extensionName, $variableName, $default); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Convenience shortcut to get all extension variables. |
47
|
|
|
*/ |
48
|
|
|
public function getVars(): array |
49
|
|
|
{ |
50
|
|
|
return $this->variableApi->getAll($this->extensionName); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Convenience shortcut to set extension variable. |
55
|
|
|
* |
56
|
|
|
* @param string|integer|boolean $value |
57
|
|
|
*/ |
58
|
|
|
public function setVar(string $variableName, $value = ''): bool |
59
|
|
|
{ |
60
|
|
|
return $this->variableApi->set($this->extensionName, $variableName, $value); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Convenience shortcut to set many extension variables. |
65
|
|
|
*/ |
66
|
|
|
public function setVars(array $variables = []): bool |
67
|
|
|
{ |
68
|
|
|
return $this->variableApi->setAll($this->extensionName, $variables); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Convenience shortcut to delete an extension variable. |
73
|
|
|
*/ |
74
|
|
|
public function delVar(string $variableName): bool |
75
|
|
|
{ |
76
|
|
|
return $this->variableApi->del($this->extensionName, $variableName); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Convenience shortcut to delete all extension variables. |
81
|
|
|
*/ |
82
|
|
|
public function delVars(): bool |
83
|
|
|
{ |
84
|
|
|
return $this->variableApi->delAll($this->extensionName); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function getVariableApi(): VariableApiInterface |
88
|
|
|
{ |
89
|
|
|
return $this->variableApi; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|