aboutsummaryrefslogtreecommitdiff
path: root/php/src/Google/Protobuf/Internal/Descriptor.php
diff options
context:
space:
mode:
authorPaul Yang <TeBoring@users.noreply.github.com>2017-06-30 12:14:09 -0700
committerGitHub <noreply@github.com>2017-06-30 12:14:09 -0700
commitecca6ea95d56a6f70ff7b223ec3f904758acc8b1 (patch)
tree728f4aff0d5f00c78a741cf737ea6de58f4ba645 /php/src/Google/Protobuf/Internal/Descriptor.php
parent5a52b3588d35d2fa0b9ce4eda5630546966a26b4 (diff)
downloadprotobuf-ecca6ea95d56a6f70ff7b223ec3f904758acc8b1.tar.gz
protobuf-ecca6ea95d56a6f70ff7b223ec3f904758acc8b1.tar.bz2
protobuf-ecca6ea95d56a6f70ff7b223ec3f904758acc8b1.zip
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/Descriptor.php')
-rw-r--r--php/src/Google/Protobuf/Internal/Descriptor.php32
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)