1: <?php
2:
3: /**
4: * Copyright 2015, Eduardo Trujillo
5: *
6: * For the full copyright and license information, please view the LICENSE
7: * file that was distributed with this source code.
8: *
9: * This file is part of the Nucleus package
10: */
11:
12: namespace Chromabits\Nucleus\Foundation;
13:
14: use Chromabits\Nucleus\Data\ArrayList;
15: use Chromabits\Nucleus\Data\ArrayMap;
16: use Chromabits\Nucleus\Data\Interfaces\ListInterface;
17: use Chromabits\Nucleus\Data\Interfaces\MapInterface;
18: use ReflectionClass;
19:
20: /**
21: * Class Enum.
22: *
23: * An enumeration emulation.
24: *
25: * @author Eduardo Trujillo <ed@chromabits.com>
26: * @package Chromabits\Nucleus\Foundation
27: */
28: abstract class Enum extends BaseObject
29: {
30: /**
31: * Get the names of possible constants in the enumeration.
32: *
33: * @return array
34: */
35: public static function getKeys()
36: {
37: return ArrayList::of(static::getValues())->toArray();
38: }
39:
40: /**
41: * Get the value of all constants in the enumeration.
42: *
43: * @return array
44: */
45: public static function getValues()
46: {
47: $self = new ReflectionClass(static::class);
48:
49: return $self->getConstants();
50: }
51:
52: /**
53: * @return MapInterface
54: */
55: public static function toMap()
56: {
57: return ArrayMap::of(static::getValues());
58: }
59:
60: /**
61: * @return ListInterface
62: */
63: public static function toList()
64: {
65: return ArrayList::of(static::getValues());
66: }
67:
68: /**
69: * @return ListInterface
70: */
71: public static function toValuesList()
72: {
73: return ArrayMap::of(static::getValues())->values();
74: }
75: }
76: