1: <?php
2:
3: namespace BN\Compiler\Postfix;
4:
5: use BN\Compiler\Token\Token;
6:
7: class Variables
8: {
9: private $object;
10:
11: public function __construct()
12: {
13: $this->object = new \stdClass();
14: }
15:
16: public function setVariables(\stdClass $object)
17: {
18: $this->object = $object;
19: }
20:
21: public function exists(Token $token)
22: {
23: $variable = $this->tokenToVariableName($token);
24: return property_exists($this->object, $variable);
25: }
26:
27: public function get(Token $token)
28: {
29: $variable = $this->tokenToVariableName($token);
30: return $this->object->$variable;
31: }
32:
33: public function set(Token $token, $value)
34: {
35: $variable = $this->tokenToVariableName($token);
36: $this->object->$variable = $value;
37: }
38:
39: private function tokenToVariableName($token)
40: {
41: return substr($token->value, 1);
42: }
43: }
44: