mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-24 16:51:19 +02:00
add pattern Interpreter
This commit is contained in:
23
Behavioral/Interpreter/VariableExp.php
Normal file
23
Behavioral/Interpreter/VariableExp.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace DesignPatterns\Behavioral\Interpreter;
|
||||
|
||||
class VariableExp extends AbstractExp
|
||||
{
|
||||
private string $name;
|
||||
|
||||
public function __construct(string $name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function interpret(Context $context): bool
|
||||
{
|
||||
return $context->lookUp($this->name);
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user