<?php
namespace App\Component\Configuration\Twig;
use App\Component\Configuration\Util\Config;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
class ConfigExtension extends AbstractExtension
{
private Config $config;
/**
* ConfigExtension constructor.
*/
public function __construct(Config $config)
{
$this->config = $config;
}
public function getFunctions(): array
{
return [
new TwigFunction('config_setting', [$this, 'getSetting'], ['is_safe' => ['html']]),
new TwigFunction('config_list', [$this, 'getSettingList']),
];
}
/**
* @param string $name name of the setting
*
* @return mixed value of the setting
*/
public function getSetting(string $name)
{
return $this->config->get($name);
}
/**
* Get a array list of all available config settings.
*
* @return array list of all config settings
*/
public function getSettingList(): array
{
return $this->config->getList();
}
}