1: <?php
2:
3: namespace Csim\Model;
4:
5: /**
6: * An enum for instruction types.
7: */
8: final class InstructionType {
9:
10: private static $constCache = NULL;
11:
12: /**
13: * The load instruction.
14: */
15: const LOAD = "LOAD";
16:
17: /**
18: * The store instruction.
19: */
20: const STORE = "STORE";
21:
22: private function __construct() {
23:
24: }
25:
26: private static function getConstants() {
27: if (self::$constCache === NULL) {
28: $reflect = new \ReflectionClass(get_called_class());
29: self::$constCache = $reflect->getConstants();
30: }
31:
32: return self::$constCache;
33: }
34:
35: /**
36: * Returns the constant that has the specified name. Throws InvalidInstructionException
37: * if no matching constant is found.
38: *
39: * @param string $name The name of the searched constant.
40: * @return string the searched constant (if found).
41: */
42: public static function valueOf($name) {
43: $values = self::getConstants();
44:
45: foreach ($values as $value) {
46: if ($value == \strtoupper($name)) {
47: return $value;
48: }
49: }
50: throw new \Csim\Model\InvalidInstructionException($name);
51: }
52:
53: }
54: