aboutsummaryrefslogtreecommitdiffhomepage
path: root/php/src/Google/Protobuf/Internal/EnumDescriptor.php
diff options
context:
space:
mode:
authorGravatar Paul Yang <TeBoring@users.noreply.github.com>2017-06-30 12:14:09 -0700
committerGravatar GitHub <noreply@github.com>2017-06-30 12:14:09 -0700
commitecca6ea95d56a6f70ff7b223ec3f904758acc8b1 (patch)
tree728f4aff0d5f00c78a741cf737ea6de58f4ba645 /php/src/Google/Protobuf/Internal/EnumDescriptor.php
parent5a52b3588d35d2fa0b9ce4eda5630546966a26b4 (diff)
Add json encode/decode for php. (#3226)
* Add json encode/decode for php. * Fix php conformance test on 32-bit machines. * Fix conformance test for c extension. * Fix comments
Diffstat (limited to 'php/src/Google/Protobuf/Internal/EnumDescriptor.php')
-rw-r--r--php/src/Google/Protobuf/Internal/EnumDescriptor.php16
1 files changed, 16 insertions, 0 deletions
diff --git a/php/src/Google/Protobuf/Internal/EnumDescriptor.php b/php/src/Google/Protobuf/Internal/EnumDescriptor.php
index 7360a477..33a55a4a 100644
--- a/php/src/Google/Protobuf/Internal/EnumDescriptor.php
+++ b/php/src/Google/Protobuf/Internal/EnumDescriptor.php
@@ -8,6 +8,7 @@ class EnumDescriptor
private $klass;
private $full_name;
private $value;
+ private $name_to_value;
public function setFullName($full_name)
{
@@ -22,6 +23,17 @@ class EnumDescriptor
public function addValue($number, $value)
{
$this->value[$number] = $value;
+ $this->name_to_value[$value->getName()] = $value;
+ }
+
+ public function getValueByNumber($number)
+ {
+ return $this->value[$number];
+ }
+
+ public function getValueByName($name)
+ {
+ return $this->name_to_value[$name];
}
public function setClass($klass)
@@ -50,6 +62,10 @@ class EnumDescriptor
$fullname);
$desc->setFullName($fullname);
$desc->setClass($classname);
+ $values = $proto->getValue();
+ foreach ($values as $value) {
+ $desc->addValue($value->getNumber(), $value);
+ }
return $desc;
}