mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-31 12:10:10 +02:00
add pattern Interpreter
This commit is contained in:
24
Behavioral/Interpreter/Context.php
Normal file
24
Behavioral/Interpreter/Context.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace DesignPatterns\Behavioral\Interpreter;
|
||||
|
||||
use Exception;
|
||||
|
||||
class Context
|
||||
{
|
||||
private array $poolVariable;
|
||||
|
||||
public function lookUp(string $name): bool
|
||||
{
|
||||
if (!key_exists($name, $this->poolVariable)) {
|
||||
throw new Exception("no exist variable: $name");
|
||||
}
|
||||
|
||||
return $this->poolVariable[$name];
|
||||
}
|
||||
|
||||
public function assign(VariableExp $variable, bool $val)
|
||||
{
|
||||
$this->poolVariable[$variable->getName()] = $val;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user