use Setono\VariableResolver\Parser\ParserInterface;
9
use Setono\VariableResolver\Variable\Value\ValueInterface;
10
11
final class VariableResolver implements VariableResolverInterface
12
{
13
/** @var ValueInterface[] */
14
private array $values = [];
15
16
private ParserInterface $parser;
17
18
public function __construct(ParserInterface $parser)
19
{
20
$this->parser = $parser;
21
}
22
23
public function resolve(string $str): string
24
{
25
$variables = $this->parser->parse($str);
26
27
if (count($variables) === 0) {
28
return $str;
29
}
30
31
foreach ($variables as $variable) {
32
if (!isset($this->values[$variable->getName()])) {
33
throw new \InvalidArgumentException(sprintf('The variable, "%s" does not have a corresponding variable value. Please add one.', $variable->getName())); // todo better exception