diff options
author | Yilun Chong <chongyilun250@sina.com> | 2017-06-30 17:38:50 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-30 17:38:50 -0700 |
commit | e82ba0b8026eb16c40ceba861f02c643c36e8232 (patch) | |
tree | 2aa89a917c6091923682221026507aa9eea1aba4 /php/src/Google/Protobuf/Internal/Descriptor.php | |
parent | 726ba33d98cd06c268f88b7dedf2a9a7916d978d (diff) | |
parent | ecca6ea95d56a6f70ff7b223ec3f904758acc8b1 (diff) | |
download | protobuf-e82ba0b8026eb16c40ceba861f02c643c36e8232.tar.gz protobuf-e82ba0b8026eb16c40ceba861f02c643c36e8232.tar.bz2 protobuf-e82ba0b8026eb16c40ceba861f02c643c36e8232.zip |
Merge branch 'master' into ConformanceTestYilunChong
Diffstat (limited to 'php/src/Google/Protobuf/Internal/Descriptor.php')
-rw-r--r-- | php/src/Google/Protobuf/Internal/Descriptor.php | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/php/src/Google/Protobuf/Internal/Descriptor.php b/php/src/Google/Protobuf/Internal/Descriptor.php index f8d24e45..44225ad2 100644 --- a/php/src/Google/Protobuf/Internal/Descriptor.php +++ b/php/src/Google/Protobuf/Internal/Descriptor.php @@ -37,6 +37,8 @@ class Descriptor private $full_name; private $field = []; + private $json_to_field = []; + private $name_to_field = []; private $nested_type = []; private $enum_type = []; private $klass; @@ -66,6 +68,8 @@ class Descriptor public function addField($field) { $this->field[$field->getNumber()] = $field; + $this->json_to_field[$field->getJsonName()] = $field; + $this->name_to_field[$field->getName()] = $field; } public function getField() @@ -95,11 +99,29 @@ class Descriptor public function getFieldByNumber($number) { - if (!isset($this->field[$number])) { - return NULL; - } else { - return $this->field[$number]; - } + if (!isset($this->field[$number])) { + return NULL; + } else { + return $this->field[$number]; + } + } + + public function getFieldByJsonName($json_name) + { + if (!isset($this->json_to_field[$json_name])) { + return NULL; + } else { + return $this->json_to_field[$json_name]; + } + } + + public function getFieldByName($name) + { + if (!isset($this->name_to_field[$name])) { + return NULL; + } else { + return $this->name_to_field[$name]; + } } public function setClass($klass) |