aboutsummaryrefslogtreecommitdiffhomepage
path: root/php/src/Google/Protobuf/Internal/GPBUtil.php
diff options
context:
space:
mode:
authorGravatar Adam Cozzette <acozzette@gmail.com>2018-06-25 15:52:29 -0700
committerGravatar GitHub <noreply@github.com>2018-06-25 15:52:29 -0700
commitd6f346b4d55ae5112934297593ec1c56c3d178a5 (patch)
tree021b5476160e465a20ef7d4ae4c0524351667233 /php/src/Google/Protobuf/Internal/GPBUtil.php
parent3d603f481ed142d0be5e8e4dd6d1cb4457a51405 (diff)
parent82d3d7d250645322f8a7343188e5ae6246a76414 (diff)
Merge pull request #4827 from acozzette/merge-3-6-x
Merge 3.6.x branch into master
Diffstat (limited to 'php/src/Google/Protobuf/Internal/GPBUtil.php')
-rw-r--r--php/src/Google/Protobuf/Internal/GPBUtil.php32
1 files changed, 28 insertions, 4 deletions
diff --git a/php/src/Google/Protobuf/Internal/GPBUtil.php b/php/src/Google/Protobuf/Internal/GPBUtil.php
index 023b07f4..b75d9bab 100644
--- a/php/src/Google/Protobuf/Internal/GPBUtil.php
+++ b/php/src/Google/Protobuf/Internal/GPBUtil.php
@@ -215,9 +215,10 @@ class GPBUtil
"Expect repeated field of different type.");
}
if ($var->getType() === GPBType::MESSAGE &&
- $var->getClass() !== $klass) {
+ $var->getClass() !== $klass &&
+ $var->getLegacyClass() !== $klass) {
throw new \Exception(
- "Expect repeated field of different message.");
+ "Expect repeated field of " . $klass . ".");
}
return $var;
}
@@ -242,9 +243,10 @@ class GPBUtil
throw new \Exception("Expect map field of value type.");
}
if ($var->getValueType() === GPBType::MESSAGE &&
- $var->getValueClass() !== $klass) {
+ $var->getValueClass() !== $klass &&
+ $var->getLegacyValueClass() !== $klass) {
throw new \Exception(
- "Expect map field of different value message.");
+ "Expect map field of " . $klass . ".");
}
return $var;
}
@@ -299,6 +301,17 @@ class GPBUtil
return "";
}
+ public static function getLegacyClassNameWithoutPackage(
+ $name,
+ $file_proto)
+ {
+ $parts = explode('.', $name);
+ foreach ($parts as $i => $part) {
+ $parts[$i] = static::getClassNamePrefix($parts[$i], $file_proto) . $parts[$i];
+ }
+ return implode('\\', $parts);
+ }
+
public static function getClassNameWithoutPackage(
$name,
$file_proto)
@@ -316,6 +329,7 @@ class GPBUtil
$file_proto,
&$message_name_without_package,
&$classname,
+ &$legacy_classname,
&$fullname)
{
// Full name needs to start with '.'.
@@ -334,21 +348,28 @@ class GPBUtil
$class_name_without_package =
static::getClassNameWithoutPackage($message_name_without_package, $file_proto);
+ $legacy_class_name_without_package =
+ static::getLegacyClassNameWithoutPackage(
+ $message_name_without_package, $file_proto);
$option = $file_proto->getOptions();
if (!is_null($option) && $option->hasPhpNamespace()) {
$namespace = $option->getPhpNamespace();
if ($namespace !== "") {
$classname = $namespace . "\\" . $class_name_without_package;
+ $legacy_classname =
+ $namespace . "\\" . $legacy_class_name_without_package;
return;
} else {
$classname = $class_name_without_package;
+ $legacy_classname = $legacy_class_name_without_package;
return;
}
}
if ($package === "") {
$classname = $class_name_without_package;
+ $legacy_classname = $legacy_class_name_without_package;
} else {
$parts = array_map('ucwords', explode('.', $package));
foreach ($parts as $i => $part) {
@@ -358,6 +379,9 @@ class GPBUtil
implode('\\', $parts) .
"\\".self::getClassNamePrefix($class_name_without_package,$file_proto).
$class_name_without_package;
+ $legacy_classname =
+ implode('\\', array_map('ucwords', explode('.', $package))).
+ "\\".$legacy_class_name_without_package;
}
}