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