|
@@ -12,6 +12,60 @@ use Cache;
|
|
|
use DB\SQL;
|
|
use DB\SQL;
|
|
|
use PDO;
|
|
use PDO;
|
|
|
use PDOException;
|
|
use PDOException;
|
|
|
|
|
+use ReflectionClass;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * Class Enum
|
|
|
|
|
+ * ---
|
|
|
|
|
+ * Implement basic ENUMERATORS, support auto numbering of integer default number and custom start number
|
|
|
|
|
+ *
|
|
|
|
|
+ * It's possible to get enum name by add suffix "ToString" to enum name:<br/>
|
|
|
|
|
+ * >$enum->START<br/>
|
|
|
|
|
+ * $enum->STARTToString (return 'START')<br/>
|
|
|
|
|
+ *
|
|
|
|
|
+ * @package OpenMind\System
|
|
|
|
|
+ */
|
|
|
|
|
+abstract class Enum
|
|
|
|
|
+{
|
|
|
|
|
+ public function __construct()
|
|
|
|
|
+ {
|
|
|
|
|
+ $counter = 0;
|
|
|
|
|
+ foreach((new ReflectionClass($this))->getProperties() as $property) {
|
|
|
|
|
+ $propertyValue = $property->getValue($this);
|
|
|
|
|
+
|
|
|
|
|
+ switch (gettype($propertyValue)) {
|
|
|
|
|
+ case 'integer':
|
|
|
|
|
+ $counter = $propertyValue + 1;
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 'NULL':
|
|
|
|
|
+ $propertyValue = $counter++;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ $property->setValue($this, $propertyValue);
|
|
|
|
|
+ $this->{"{$property->name}ToString"} = $property->name;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Get the variable name as string by its value
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param $value
|
|
|
|
|
+ * @return string|null the variable name
|
|
|
|
|
+ */
|
|
|
|
|
+ public function getNameByValue($value): ?string
|
|
|
|
|
+ {
|
|
|
|
|
+ try {
|
|
|
|
|
+ foreach((new ReflectionClass($this))->getProperties() as $property) {
|
|
|
|
|
+ if ($property->getValue($this) === $value) {
|
|
|
|
|
+ return $property->name;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (\ReflectionException $e) {
|
|
|
|
|
+ return $e->getMessage();
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
class System extends PluginStrategy
|
|
class System extends PluginStrategy
|
|
|
{
|
|
{
|