1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Zikula package. |
7
|
|
|
* |
8
|
|
|
* Copyright Zikula - 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\Twig\Runtime; |
15
|
|
|
|
16
|
|
|
use InvalidArgumentException; |
17
|
|
|
use Symfony\Contracts\Translation\TranslatorInterface; |
18
|
|
|
use Twig\Extension\RuntimeExtensionInterface; |
19
|
|
|
use Zikula\ExtensionsModule\Api\ApiInterface\VariableApiInterface; |
20
|
|
|
|
21
|
|
|
class ModVarRuntime implements RuntimeExtensionInterface |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var TranslatorInterface |
25
|
|
|
*/ |
26
|
|
|
private $translator; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var VariableApiInterface |
30
|
|
|
*/ |
31
|
|
|
private $variableApi; |
32
|
|
|
|
33
|
|
|
public function __construct( |
34
|
|
|
TranslatorInterface $translator, |
35
|
|
|
VariableApiInterface $variableApi |
36
|
|
|
) { |
37
|
|
|
$this->translator = $translator; |
38
|
|
|
$this->variableApi = $variableApi; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function getModVar(string $module, string $name, $default = null) |
42
|
|
|
{ |
43
|
|
|
if (empty($module) || empty($name)) { |
44
|
|
|
throw new InvalidArgumentException($this->translator->trans('Empty argument at') . ':' . __FILE__ . '::' . __LINE__); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
return $this->variableApi->get($module, $name, $default); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function getSystemVar(string $name, $default = null) |
51
|
|
|
{ |
52
|
|
|
if (empty($name)) { |
53
|
|
|
throw new InvalidArgumentException($this->translator->trans('Empty argument at') . ':' . __FILE__ . '::' . __LINE__); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return $this->variableApi->getSystemVar($name, $default); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|