diff options
author | Brent Shaffer <betterbrent@google.com> | 2017-06-14 15:57:11 -0700 |
---|---|---|
committer | Paul Yang <TeBoring@users.noreply.github.com> | 2017-06-14 15:57:11 -0700 |
commit | b9b34e9b1167d89c4df8f0abffe31262aebe7a39 (patch) | |
tree | 90bd518f966f24ea48fe2472e68409868501abfa /php/src/Google/Protobuf/Internal/GPBUtil.php | |
parent | 09d2994b1f68160508d9188f9bdb1a2a3b527e1e (diff) | |
download | protobuf-b9b34e9b1167d89c4df8f0abffe31262aebe7a39.tar.gz protobuf-b9b34e9b1167d89c4df8f0abffe31262aebe7a39.tar.bz2 protobuf-b9b34e9b1167d89c4df8f0abffe31262aebe7a39.zip |
Follows proper autoloading standards (#3123)
* Follows proper autoloading standards
- Splits PHP classes in descriptor.php into separate files
- Splits MapFieldIter and RepeatedFieldIter into separate files
- Moves descriptor.php to Internal/functions.php
- Moves all namespaced functions into Iternal/functions.php
* fixes Makefile.am for added php files
* [PHP] moves all functions to GPBUtil
* removes description.php from the makefile
Diffstat (limited to 'php/src/Google/Protobuf/Internal/GPBUtil.php')
-rw-r--r-- | php/src/Google/Protobuf/Internal/GPBUtil.php | 100 |
1 files changed, 99 insertions, 1 deletions
diff --git a/php/src/Google/Protobuf/Internal/GPBUtil.php b/php/src/Google/Protobuf/Internal/GPBUtil.php index 0e66ae6f..1b71f7b7 100644 --- a/php/src/Google/Protobuf/Internal/GPBUtil.php +++ b/php/src/Google/Protobuf/Internal/GPBUtil.php @@ -67,7 +67,6 @@ class GPBUtil } } - public static function checkString(&$var, $check_utf8) { if (is_array($var) || is_object($var)) { @@ -242,4 +241,103 @@ class GPBUtil { return new Uint64($value); } + + public static 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 ""; + } + + public static function getClassNameWithoutPackage( + $name, + $file_proto) + { + $classname = implode('_', array_map('ucwords', explode('.', $name))); + return static::getClassNamePrefix($classname, $file_proto) . $classname; + } + + public static function getFullClassName( + $proto, + $containing, + $file_proto, + &$message_name_without_package, + &$classname, + &$fullname) + { + // Full name needs to start with '.'. + $message_name_without_package = $proto->getName(); + if ($containing !== "") { + $message_name_without_package = + $containing . "." . $message_name_without_package; + } + + $package = $file_proto->getPackage(); + if ($package === "") { + $fullname = "." . $message_name_without_package; + } else { + $fullname = "." . $package . "." . $message_name_without_package; + } + + $class_name_without_package = + static::getClassNameWithoutPackage($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; + return; + } else { + $classname = $class_name_without_package; + return; + } + } + + if ($package === "") { + $classname = $class_name_without_package; + } else { + $classname = + implode('\\', array_map('ucwords', explode('.', $package))). + "\\".$class_name_without_package; + } + } + + public static function combineInt32ToInt64($high, $low) + { + $isNeg = $high < 0; + if ($isNeg) { + $high = ~$high; + $low = ~$low; + $low++; + if (!$low) { + $high++; + } + } + $result = bcadd(bcmul($high, 4294967296), $low); + if ($low < 0) { + $result = bcadd($result, 4294967296); + } + if ($isNeg) { + $result = bcsub(0, $result); + } + return $result; + } } |