aboutsummaryrefslogtreecommitdiff
path: root/php/src/Google
diff options
context:
space:
mode:
authorPaul Yang <TeBoring@users.noreply.github.com>2017-04-20 01:19:03 -0700
committerGitHub <noreply@github.com>2017-04-20 01:19:03 -0700
commit4c57e8475f78ccac80407f03c2d23d30014785f9 (patch)
treefa9c6ca31796db77c3367acac83233a44938e117 /php/src/Google
parentb97cd573e405dd511b09a9fae124427a29741395 (diff)
downloadprotobuf-4c57e8475f78ccac80407f03c2d23d30014785f9.tar.gz
protobuf-4c57e8475f78ccac80407f03c2d23d30014785f9.tar.bz2
protobuf-4c57e8475f78ccac80407f03c2d23d30014785f9.zip
Prepend "PB" to generated classes whose name are reserved words. (#2990)
Diffstat (limited to 'php/src/Google')
-rw-r--r--php/src/Google/Protobuf/Internal/Message.php1
-rw-r--r--php/src/Google/Protobuf/descriptor.php36
2 files changed, 27 insertions, 10 deletions
diff --git a/php/src/Google/Protobuf/Internal/Message.php b/php/src/Google/Protobuf/Internal/Message.php
index 887c86ca..0fb6cdc0 100644
--- a/php/src/Google/Protobuf/Internal/Message.php
+++ b/php/src/Google/Protobuf/Internal/Message.php
@@ -71,6 +71,7 @@ class Message
return;
}
$pool = DescriptorPool::getGeneratedPool();
+ var_dump(get_class($this));
$this->desc = $pool->getDescriptorByClassName(get_class($this));
foreach ($this->desc->getField() as $field) {
$setter = $field->getSetter();
diff --git a/php/src/Google/Protobuf/descriptor.php b/php/src/Google/Protobuf/descriptor.php
index 2263af6e..9c744a8a 100644
--- a/php/src/Google/Protobuf/descriptor.php
+++ b/php/src/Google/Protobuf/descriptor.php
@@ -220,20 +220,36 @@ class Descriptor
}
}
+function getClassNamePrefix(
+ $classname,
+ $file_proto)
+{
+ $option = $file_proto->getOptions();
+ $prefix = is_null($option) ? "" : $option->getPhpClassPrefix();
+ if ($prefix !== "") {
+ return $prefix;
+ }
+
+ $reserved_words = array("Empty");
+ foreach ($reserved_words as $reserved_word) {
+ if ($classname === $reserved_word) {
+ if ($file_proto->getPackage() === "google.protobuf") {
+ return "GPB";
+ } else {
+ return "PB";
+ }
+ }
+ }
+
+ return "";
+}
+
function getClassNameWithoutPackage(
$name,
$file_proto)
{
- if ($name === "Empty" && $file_proto->getPackage() === "google.protobuf") {
- return "GPBEmpty";
- } else {
- $option = $file_proto->getOptions();
- $prefix = is_null($option) ? "" : $option->getPhpClassPrefix();
- // Nested message class names are seperated by '_', and package names
- // are seperated by '\'.
- return $prefix . implode('_', array_map('ucwords',
- explode('.', $name)));
- }
+ $classname = implode('_', array_map('ucwords', explode('.', $name)));
+ return getClassNamePrefix($classname, $file_proto) . $classname;
}
function getFullClassName(