diff options
author | Adam Cozzette <acozzette@google.com> | 2018-06-25 13:22:10 -0700 |
---|---|---|
committer | Adam Cozzette <acozzette@google.com> | 2018-06-25 13:22:10 -0700 |
commit | 82d3d7d250645322f8a7343188e5ae6246a76414 (patch) | |
tree | 34b7acb87b15c3b8395df3d311f2e795a1285d60 /php/src/Google/Protobuf/Internal/GPBUtil.php | |
parent | 35567c166842cca3ff6af3226ff526f25c79507f (diff) | |
parent | f7ada1280fac4af717d478e6a9765d3f02b418b3 (diff) |
Merge branch '3.6.x' into merge-3-6-x
Diffstat (limited to 'php/src/Google/Protobuf/Internal/GPBUtil.php')
-rw-r--r-- | php/src/Google/Protobuf/Internal/GPBUtil.php | 32 |
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; } } |