aboutsummaryrefslogtreecommitdiffhomepage
path: root/php/src/Google/Protobuf/Internal/GPBUtil.php
diff options
context:
space:
mode:
authorGravatar Brent Shaffer <betterbrent@google.com>2018-05-23 16:43:30 -0700
committerGravatar Paul Yang <TeBoring@users.noreply.github.com>2018-05-24 13:39:41 -0700
commit6737954661ed26105dd87a4c78fe3f333c978961 (patch)
treea0bd8f91dfde4576790961e6896a5fa20ceba019 /php/src/Google/Protobuf/Internal/GPBUtil.php
parent839f71e30567498284061ea92a9f1a5216b46e14 (diff)
PHP namespaces for nested messages and enums (#4536)
* uses namespaces for nested messages and enums * fixes namespaces for PHP dist * fixes namespace for Descriptors, adds Cardinality and Kind * fixes nested namespaces for reserved words and adds tests * adds tests and generator fix for php class prefixes * fixes escaping of protobuf packages, enum comments, misc others * nice refactor of generated code * adds class files for backwards compatibility * simplifies code with templates * adds compatibility files to makefile * cleanup of generator and fixes nested namespace bug * regenerates proto types * remove internal BC classes * adds deprecated warning, adds methods back * simplifies if statement * fixes dist files * addresses review comments * adds back TYPE_URL_PREFIX constant * adds @deprecated to old nested class files * skips tests which require a separate process when protobuf.so is enabled * Adds tests for legacy nested classes that do not require separate processes to test * uses legacy names for GPBUtil message check * adds block for IDE @deprecated message * Namespace for nested message/enum in c extension * Remove unused code
Diffstat (limited to 'php/src/Google/Protobuf/Internal/GPBUtil.php')
-rw-r--r--php/src/Google/Protobuf/Internal/GPBUtil.php18
1 files changed, 13 insertions, 5 deletions
diff --git a/php/src/Google/Protobuf/Internal/GPBUtil.php b/php/src/Google/Protobuf/Internal/GPBUtil.php
index 05d5c393..023b07f4 100644
--- a/php/src/Google/Protobuf/Internal/GPBUtil.php
+++ b/php/src/Google/Protobuf/Internal/GPBUtil.php
@@ -191,7 +191,7 @@ class GPBUtil
$var = boolval($var);
}
- public static function checkMessage(&$var, $klass)
+ public static function checkMessage(&$var, $klass, $newClass = null)
{
if (!$var instanceof $klass && !is_null($var)) {
throw new \Exception("Expect $klass.");
@@ -303,8 +303,11 @@ class GPBUtil
$name,
$file_proto)
{
- $classname = implode('_', explode('.', $name));
- return static::getClassNamePrefix($classname, $file_proto) . $classname;
+ $parts = explode('.', $name);
+ foreach ($parts as $i => $part) {
+ $parts[$i] = static::getClassNamePrefix($parts[$i], $file_proto) . $parts[$i];
+ }
+ return implode('\\', $parts);
}
public static function getFullClassName(
@@ -347,9 +350,14 @@ class GPBUtil
if ($package === "") {
$classname = $class_name_without_package;
} else {
+ $parts = array_map('ucwords', explode('.', $package));
+ foreach ($parts as $i => $part) {
+ $parts[$i] = self::getClassNamePrefix($part, $file_proto).$part;
+ }
$classname =
- implode('\\', array_map('ucwords', explode('.', $package))).
- "\\".$class_name_without_package;
+ implode('\\', $parts) .
+ "\\".self::getClassNamePrefix($class_name_without_package,$file_proto).
+ $class_name_without_package;
}
}