aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTravis Staley <travis.staley@gmail.com>2019-02-04 17:33:57 -0500
committerWouter van Oortmerssen <aardappel@gmail.com>2019-02-04 23:33:57 +0100
commit31e34faa15b4c7e3eb056d58ceb41f67334b66cd (patch)
tree09bac8ead940121b2f6c8c9bdd76874211a57593
parent4d98faa5155e5474161aa1757a0721892ac73a05 (diff)
downloadflatbuffers-31e34faa15b4c7e3eb056d58ceb41f67334b66cd.tar.gz
Changing array to be an associative array so that the Name function can work with non-sequential enums as well as those beginning at something other than zero. (#5151)
Also including the resulting changes in php files.
-rw-r--r--src/idl_gen_php.cpp2
-rw-r--r--tests/MyGame/Example/Any.php8
-rw-r--r--tests/MyGame/Example/AnyAmbiguousAliases.php8
-rw-r--r--tests/MyGame/Example/AnyUniqueAliases.php8
-rw-r--r--tests/MyGame/Example/Color.php6
-rw-r--r--tests/namespace_test/NamespaceA/NamespaceB/EnumInNestedNS.php6
-rw-r--r--tests/union_vector/Character.php14
7 files changed, 26 insertions, 26 deletions
diff --git a/src/idl_gen_php.cpp b/src/idl_gen_php.cpp
index ae567548..3d391c71 100644
--- a/src/idl_gen_php.cpp
+++ b/src/idl_gen_php.cpp
@@ -828,7 +828,7 @@ class PhpGenerator : public BaseGenerator {
for (auto it = enum_def.vals.vec.begin(); it != enum_def.vals.vec.end();
++it) {
auto &ev = **it;
- code += Indent + Indent + "\"" + ev.name + "\",\n";
+ code += Indent + Indent + enum_def.name + "::" + ev.name + "=>" + "\"" + ev.name + "\",\n";
}
code += Indent + ");\n\n";
diff --git a/tests/MyGame/Example/Any.php b/tests/MyGame/Example/Any.php
index da691760..929caaf6 100644
--- a/tests/MyGame/Example/Any.php
+++ b/tests/MyGame/Example/Any.php
@@ -11,10 +11,10 @@ class Any
const MyGame_Example2_Monster = 3;
private static $names = array(
- "NONE",
- "Monster",
- "TestSimpleTableWithEnum",
- "MyGame_Example2_Monster",
+ Any::NONE=>"NONE",
+ Any::Monster=>"Monster",
+ Any::TestSimpleTableWithEnum=>"TestSimpleTableWithEnum",
+ Any::MyGame_Example2_Monster=>"MyGame_Example2_Monster",
);
public static function Name($e)
diff --git a/tests/MyGame/Example/AnyAmbiguousAliases.php b/tests/MyGame/Example/AnyAmbiguousAliases.php
index 8d824621..13d318a0 100644
--- a/tests/MyGame/Example/AnyAmbiguousAliases.php
+++ b/tests/MyGame/Example/AnyAmbiguousAliases.php
@@ -11,10 +11,10 @@ class AnyAmbiguousAliases
const M3 = 3;
private static $names = array(
- "NONE",
- "M1",
- "M2",
- "M3",
+ AnyAmbiguousAliases::NONE=>"NONE",
+ AnyAmbiguousAliases::M1=>"M1",
+ AnyAmbiguousAliases::M2=>"M2",
+ AnyAmbiguousAliases::M3=>"M3",
);
public static function Name($e)
diff --git a/tests/MyGame/Example/AnyUniqueAliases.php b/tests/MyGame/Example/AnyUniqueAliases.php
index 5d51f826..fe551cce 100644
--- a/tests/MyGame/Example/AnyUniqueAliases.php
+++ b/tests/MyGame/Example/AnyUniqueAliases.php
@@ -11,10 +11,10 @@ class AnyUniqueAliases
const M2 = 3;
private static $names = array(
- "NONE",
- "M",
- "T",
- "M2",
+ AnyUniqueAliases::NONE=>"NONE",
+ AnyUniqueAliases::M=>"M",
+ AnyUniqueAliases::T=>"T",
+ AnyUniqueAliases::M2=>"M2",
);
public static function Name($e)
diff --git a/tests/MyGame/Example/Color.php b/tests/MyGame/Example/Color.php
index 70c7bfd9..d89529e8 100644
--- a/tests/MyGame/Example/Color.php
+++ b/tests/MyGame/Example/Color.php
@@ -10,9 +10,9 @@ class Color
const Blue = 8;
private static $names = array(
- "Red",
- "Green",
- "Blue",
+ Color::Red=>"Red",
+ Color::Green=>"Green",
+ Color::Blue=>"Blue",
);
public static function Name($e)
diff --git a/tests/namespace_test/NamespaceA/NamespaceB/EnumInNestedNS.php b/tests/namespace_test/NamespaceA/NamespaceB/EnumInNestedNS.php
index d51cb41c..bcb22b75 100644
--- a/tests/namespace_test/NamespaceA/NamespaceB/EnumInNestedNS.php
+++ b/tests/namespace_test/NamespaceA/NamespaceB/EnumInNestedNS.php
@@ -10,9 +10,9 @@ class EnumInNestedNS
const C = 2;
private static $names = array(
- "A",
- "B",
- "C",
+ EnumInNestedNS::A=>"A",
+ EnumInNestedNS::B=>"B",
+ EnumInNestedNS::C=>"C",
);
public static function Name($e)
diff --git a/tests/union_vector/Character.php b/tests/union_vector/Character.php
index bf73c361..755958bc 100644
--- a/tests/union_vector/Character.php
+++ b/tests/union_vector/Character.php
@@ -12,13 +12,13 @@ class Character
const Unused = 6;
private static $names = array(
- "NONE",
- "MuLan",
- "Rapunzel",
- "Belle",
- "BookFan",
- "Other",
- "Unused",
+ Character::NONE=>"NONE",
+ Character::MuLan=>"MuLan",
+ Character::Rapunzel=>"Rapunzel",
+ Character::Belle=>"Belle",
+ Character::BookFan=>"BookFan",
+ Character::Other=>"Other",
+ Character::Unused=>"Unused",
);
public static function Name($e)