Commit 6b27c1f9 authored by Paul Yang's avatar Paul Yang Committed by GitHub

Add file option php_class_prefix (#2849)

This option will be prepended to generated classes of all messages in
the containing file.
parent c0871aa4
...@@ -584,6 +584,21 @@ objectivec_EXTRA_DIST= \ ...@@ -584,6 +584,21 @@ objectivec_EXTRA_DIST= \
Protobuf.podspec Protobuf.podspec
php_EXTRA_DIST= \ php_EXTRA_DIST= \
php/ext/google/protobuf/utf8.h \
php/ext/google/protobuf/message.c \
php/ext/google/protobuf/utf8.c \
php/ext/google/protobuf/package.xml \
php/ext/google/protobuf/upb.h \
php/ext/google/protobuf/array.c \
php/ext/google/protobuf/encode_decode.c \
php/ext/google/protobuf/protobuf.h \
php/ext/google/protobuf/type_check.c \
php/ext/google/protobuf/def.c \
php/ext/google/protobuf/storage.c \
php/ext/google/protobuf/map.c \
php/ext/google/protobuf/config.m4 \
php/ext/google/protobuf/upb.c \
php/ext/google/protobuf/protobuf.c \
php/src/phpdoc.dist.xml \ php/src/phpdoc.dist.xml \
php/src/Google/Protobuf/Internal/DescriptorPool.php \ php/src/Google/Protobuf/Internal/DescriptorPool.php \
php/src/Google/Protobuf/Internal/GeneratedCodeInfo.php \ php/src/Google/Protobuf/Internal/GeneratedCodeInfo.php \
...@@ -632,39 +647,26 @@ php_EXTRA_DIST= \ ...@@ -632,39 +647,26 @@ php_EXTRA_DIST= \
php/src/Google/Protobuf/Internal/FieldOptions_CType.php \ php/src/Google/Protobuf/Internal/FieldOptions_CType.php \
php/src/Google/Protobuf/descriptor.php \ php/src/Google/Protobuf/descriptor.php \
php/src/GPBMetadata/Google/Protobuf/Internal/Descriptor.php \ php/src/GPBMetadata/Google/Protobuf/Internal/Descriptor.php \
php/tests/array_test.php \
php/tests/autoload.php \ php/tests/autoload.php \
php/tests/encode_decode_test.php \ php/tests/encode_decode_test.php \
php/tests/test.sh \
php/tests/gdb_test.sh \ php/tests/gdb_test.sh \
php/tests/generated_class_test.php \ php/tests/generated_class_test.php \
php/tests/array_test.php \ php/tests/map_field_test.php \
php/tests/memory_leak_test.php \
php/tests/php_implementation_test.php \ php/tests/php_implementation_test.php \
php/tests/proto/test_include.proto \ php/tests/proto/test_include.proto \
php/tests/map_field_test.php \ php/tests/proto/test.proto \
php/tests/test_base.php \ php/tests/proto/test_prefix.proto \
php/tests/proto/test_no_namespace.proto \ php/tests/proto/test_no_namespace.proto \
php/tests/test.sh \
php/tests/test_base.php \
php/tests/test_util.php \ php/tests/test_util.php \
php/tests/proto/test.proto \
php/tests/memory_leak_test.php \
php/tests/well_known_test.php \ php/tests/well_known_test.php \
php/README.md \ php/README.md \
php/ext/google/protobuf/utf8.h \
php/ext/google/protobuf/message.c \
php/ext/google/protobuf/utf8.c \
php/ext/google/protobuf/package.xml \
php/ext/google/protobuf/upb.h \
php/ext/google/protobuf/array.c \
php/ext/google/protobuf/encode_decode.c \
php/ext/google/protobuf/protobuf.h \
php/ext/google/protobuf/type_check.c \
php/ext/google/protobuf/def.c \
php/ext/google/protobuf/storage.c \
php/ext/google/protobuf/map.c \
php/ext/google/protobuf/config.m4 \
php/ext/google/protobuf/upb.c \
php/ext/google/protobuf/protobuf.c \
php/phpunit.xml \ php/phpunit.xml \
php/composer.json \ php/composer.json \
php/generate_descriptor_protos.sh \
composer.json composer.json
python_EXTRA_DIST= \ python_EXTRA_DIST= \
......
...@@ -104,3 +104,8 @@ if test -x csharp/generate_protos.sh; then ...@@ -104,3 +104,8 @@ if test -x csharp/generate_protos.sh; then
echo "Generating messages for C#." echo "Generating messages for C#."
csharp/generate_protos.sh $@ csharp/generate_protos.sh $@
fi fi
if test -x php/generate_descriptor_protos.sh; then
echo "Generating messages for PHP."
php/generate_descriptor_protos.sh $@
fi
...@@ -18,7 +18,8 @@ ...@@ -18,7 +18,8 @@
"Google\\Protobuf\\": "tests/generated/Google/Protobuf", "Google\\Protobuf\\": "tests/generated/Google/Protobuf",
"Google\\Protobuf\\Internal\\": "src/Google/Protobuf/Internal", "Google\\Protobuf\\Internal\\": "src/Google/Protobuf/Internal",
"GPBMetadata\\": "tests/generated/GPBMetadata", "GPBMetadata\\": "tests/generated/GPBMetadata",
"GPBMetadata\\Google\\Protobuf\\Internal\\": "src/GPBMetadata/Google/Protobuf/Internal" "GPBMetadata\\Google\\Protobuf\\Internal\\": "src/GPBMetadata/Google/Protobuf/Internal",
"": "tests/generated"
}, },
"files": [ "files": [
"src/Google/Protobuf/descriptor.php" "src/Google/Protobuf/descriptor.php"
......
...@@ -252,39 +252,54 @@ PHP_METHOD(DescriptorPool, getGeneratedPool) { ...@@ -252,39 +252,54 @@ PHP_METHOD(DescriptorPool, getGeneratedPool) {
static void convert_to_class_name_inplace(char *class_name, static void convert_to_class_name_inplace(char *class_name,
const char* fullname, const char* fullname,
const char* prefix,
const char* package_name) { const char* package_name) {
size_t i; size_t i = 0, j;
bool first_char = false; bool first_char = true;
size_t pkg_name_len = package_name == NULL ? 0 : strlen(package_name); size_t pkg_name_len = package_name == NULL ? 0 : strlen(package_name);
size_t prefix_len = prefix == NULL ? 0 : strlen(prefix);
size_t message_name_start = package_name == NULL ? 0 : pkg_name_len + 1;
size_t message_len = (strlen(fullname) - message_name_start);
// In php, class name cannot be Empty. // In php, class name cannot be Empty.
if (strcmp("google.protobuf.Empty", fullname) == 0) { if (strcmp("google.protobuf.Empty", fullname) == 0) {
fullname = "google.protobuf.GPBEmpty"; strcpy(class_name, "\\Google\\Protobuf\\GPBEmpty");
return;
} }
if (pkg_name_len == 0) { if (pkg_name_len != 0) {
strcpy(class_name, fullname); class_name[i++] = '\\';
} else { for (j = 0; j < pkg_name_len; j++) {
class_name[0] = '.';
strcpy(&class_name[1], fullname);
for (i = 0; i <= pkg_name_len + 1; i++) {
// PHP package uses camel case.
if (!first_char && class_name[i] != '.') {
first_char = true;
class_name[i] += 'A' - 'a';
}
// php packages are divided by '\'. // php packages are divided by '\'.
if (class_name[i] == '.') { if (package_name[j] == '.') {
class_name[i++] = '\\';
first_char = true;
} else if (first_char) {
// PHP package uses camel case.
if (package_name[j] < 'A' || package_name[j] > 'Z') {
class_name[i++] = package_name[j] + 'A' - 'a';
} else {
class_name[i++] = package_name[j];
}
first_char = false; first_char = false;
class_name[i] = '\\'; } else {
class_name[i++] = package_name[j];
} }
} }
class_name[i++] = '\\';
}
if (prefix_len > 0) {
strcpy(class_name + i, prefix);
i += prefix_len;
} }
// Submessage is concatenated with its containing messages by '_'. // Submessage is concatenated with its containing messages by '_'.
for (i = pkg_name_len; i < strlen(class_name); i++) { for (j = message_name_start; j < message_name_start + message_len; j++) {
if (class_name[i] == '.') { if (fullname[j] == '.') {
class_name[i] = '_'; class_name[i++] = '_';
} else {
class_name[i++] = fullname[j];
} }
} }
} }
...@@ -339,8 +354,13 @@ PHP_METHOD(DescriptorPool, internalAddGeneratedFile) { ...@@ -339,8 +354,13 @@ PHP_METHOD(DescriptorPool, internalAddGeneratedFile) {
* bytes allocated, one for '.', one for trailing 0, and 3 for 'GPB' if \ * bytes allocated, one for '.', one for trailing 0, and 3 for 'GPB' if \
* given message is google.protobuf.Empty.*/ \ * given message is google.protobuf.Empty.*/ \
const char *fullname = upb_##def_type_lower##_fullname(def_type_lower); \ const char *fullname = upb_##def_type_lower##_fullname(def_type_lower); \
char *klass_name = ecalloc(sizeof(char), 5 + strlen(fullname)); \ const char *prefix = upb_filedef_phpprefix(files[0]); \
convert_to_class_name_inplace(klass_name, fullname, \ size_t klass_name_len = strlen(fullname) + 5; \
if (prefix != NULL) { \
klass_name_len += strlen(prefix); \
} \
char *klass_name = ecalloc(sizeof(char), klass_name_len); \
convert_to_class_name_inplace(klass_name, fullname, prefix, \
upb_filedef_package(files[0])); \ upb_filedef_package(files[0])); \
zend_class_entry **pce; \ zend_class_entry **pce; \
if (zend_lookup_class(klass_name, strlen(klass_name), &pce TSRMLS_CC) == \ if (zend_lookup_class(klass_name, strlen(klass_name), &pce TSRMLS_CC) == \
......
This diff is collapsed.
...@@ -2972,6 +2972,11 @@ class upb::FileDef { ...@@ -2972,6 +2972,11 @@ class upb::FileDef {
const char* package() const; const char* package() const;
bool set_package(const char* package, Status* s); bool set_package(const char* package, Status* s);
/* Sets the php class prefix which is prepended to all php generated classes
/ from this .proto. Default is empty. */
const char* phpprefix() const;
bool set_phpprefix(const char* phpprefix, Status* s);
/* Syntax for the file. Defaults to proto2. */ /* Syntax for the file. Defaults to proto2. */
upb_syntax_t syntax() const; upb_syntax_t syntax() const;
void set_syntax(upb_syntax_t syntax); void set_syntax(upb_syntax_t syntax);
...@@ -3025,6 +3030,7 @@ UPB_REFCOUNTED_CMETHODS(upb_filedef, upb_filedef_upcast) ...@@ -3025,6 +3030,7 @@ UPB_REFCOUNTED_CMETHODS(upb_filedef, upb_filedef_upcast)
const char *upb_filedef_name(const upb_filedef *f); const char *upb_filedef_name(const upb_filedef *f);
const char *upb_filedef_package(const upb_filedef *f); const char *upb_filedef_package(const upb_filedef *f);
const char *upb_filedef_phpprefix(const upb_filedef *f);
upb_syntax_t upb_filedef_syntax(const upb_filedef *f); upb_syntax_t upb_filedef_syntax(const upb_filedef *f);
size_t upb_filedef_defcount(const upb_filedef *f); size_t upb_filedef_defcount(const upb_filedef *f);
size_t upb_filedef_depcount(const upb_filedef *f); size_t upb_filedef_depcount(const upb_filedef *f);
...@@ -3034,6 +3040,8 @@ const upb_filedef *upb_filedef_dep(const upb_filedef *f, size_t i); ...@@ -3034,6 +3040,8 @@ const upb_filedef *upb_filedef_dep(const upb_filedef *f, size_t i);
bool upb_filedef_freeze(upb_filedef *f, upb_status *s); bool upb_filedef_freeze(upb_filedef *f, upb_status *s);
bool upb_filedef_setname(upb_filedef *f, const char *name, upb_status *s); bool upb_filedef_setname(upb_filedef *f, const char *name, upb_status *s);
bool upb_filedef_setpackage(upb_filedef *f, const char *package, upb_status *s); bool upb_filedef_setpackage(upb_filedef *f, const char *package, upb_status *s);
bool upb_filedef_setphpprefix(upb_filedef *f, const char *phpprefix,
upb_status *s);
bool upb_filedef_setsyntax(upb_filedef *f, upb_syntax_t syntax, upb_status *s); bool upb_filedef_setsyntax(upb_filedef *f, upb_syntax_t syntax, upb_status *s);
bool upb_filedef_adddef(upb_filedef *f, upb_def *def, const void *ref_donor, bool upb_filedef_adddef(upb_filedef *f, upb_def *def, const void *ref_donor,
...@@ -3792,6 +3800,12 @@ inline const char* FileDef::package() const { ...@@ -3792,6 +3800,12 @@ inline const char* FileDef::package() const {
inline bool FileDef::set_package(const char* package, Status* s) { inline bool FileDef::set_package(const char* package, Status* s) {
return upb_filedef_setpackage(this, package, s); return upb_filedef_setpackage(this, package, s);
} }
inline const char* FileDef::phpprefix() const {
return upb_filedef_phpprefix(this);
}
inline bool FileDef::set_phpprefix(const char* phpprefix, Status* s) {
return upb_filedef_setphpprefix(this, phpprefix, s);
}
inline int FileDef::def_count() const { inline int FileDef::def_count() const {
return upb_filedef_defcount(this); return upb_filedef_defcount(this);
} }
...@@ -4006,6 +4020,7 @@ struct upb_filedef { ...@@ -4006,6 +4020,7 @@ struct upb_filedef {
const char *name; const char *name;
const char *package; const char *package;
const char *phpprefix;
upb_syntax_t syntax; upb_syntax_t syntax;
upb_inttable defs; upb_inttable defs;
...@@ -7212,6 +7227,7 @@ UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_java_string ...@@ -7212,6 +7227,7 @@ UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_java_string
UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_javanano_use_deprecated_package(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 38); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_javanano_use_deprecated_package(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 38); }
UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_objc_class_prefix(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 36); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_objc_class_prefix(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 36); }
UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_optimize_for(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 9); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_optimize_for(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 9); }
UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_php_class_prefix(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 40); }
UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_py_generic_services(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 18); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_py_generic_services(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 18); }
UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_uninterpreted_option(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 999); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_uninterpreted_option(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 999); }
UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MessageOptions_f_deprecated(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MessageOptions_is(m)); return upb_msgdef_itof(m, 3); } UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MessageOptions_f_deprecated(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MessageOptions_is(m)); return upb_msgdef_itof(m, 3); }
......
#!/usr/bin/env bash
# Run this script to regenerate desriptor protos after the protocol compiler
# changes.
if test ! -e src/google/protobuf/stubs/common.h; then
cat >&2 << __EOF__
Could not find source code. Make sure you are running this script from the
root of the distribution tree.
__EOF__
exit 1
fi
pushd src
./protoc --php_out=internal:../php/src google/protobuf/descriptor.proto
popd
...@@ -144,6 +144,7 @@ class Descriptor ...@@ -144,6 +144,7 @@ class Descriptor
->optional('objc_class_prefix', \Google\Protobuf\Internal\GPBType::STRING, 36) ->optional('objc_class_prefix', \Google\Protobuf\Internal\GPBType::STRING, 36)
->optional('csharp_namespace', \Google\Protobuf\Internal\GPBType::STRING, 37) ->optional('csharp_namespace', \Google\Protobuf\Internal\GPBType::STRING, 37)
->optional('swift_prefix', \Google\Protobuf\Internal\GPBType::STRING, 39) ->optional('swift_prefix', \Google\Protobuf\Internal\GPBType::STRING, 39)
->optional('php_class_prefix', \Google\Protobuf\Internal\GPBType::STRING, 40)
->repeated('uninterpreted_option', \Google\Protobuf\Internal\GPBType::MESSAGE, 999, 'google.protobuf.internal.UninterpretedOption') ->repeated('uninterpreted_option', \Google\Protobuf\Internal\GPBType::MESSAGE, 999, 'google.protobuf.internal.UninterpretedOption')
->finalizeToPool(); ->finalizeToPool();
......
...@@ -117,8 +117,8 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message ...@@ -117,8 +117,8 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message
*/ */
public function setField(&$var) public function setField(&$var)
{ {
GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\FieldDescriptorProto::class); $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\FieldDescriptorProto::class);
$this->field = $var; $this->field = $arr;
$this->has_field = true; $this->has_field = true;
} }
...@@ -140,8 +140,8 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message ...@@ -140,8 +140,8 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message
*/ */
public function setExtension(&$var) public function setExtension(&$var)
{ {
GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\FieldDescriptorProto::class); $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\FieldDescriptorProto::class);
$this->extension = $var; $this->extension = $arr;
$this->has_extension = true; $this->has_extension = true;
} }
...@@ -163,8 +163,8 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message ...@@ -163,8 +163,8 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message
*/ */
public function setNestedType(&$var) public function setNestedType(&$var)
{ {
GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\DescriptorProto::class); $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\DescriptorProto::class);
$this->nested_type = $var; $this->nested_type = $arr;
$this->has_nested_type = true; $this->has_nested_type = true;
} }
...@@ -186,8 +186,8 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message ...@@ -186,8 +186,8 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message
*/ */
public function setEnumType(&$var) public function setEnumType(&$var)
{ {
GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\EnumDescriptorProto::class); $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\EnumDescriptorProto::class);
$this->enum_type = $var; $this->enum_type = $arr;
$this->has_enum_type = true; $this->has_enum_type = true;
} }
...@@ -209,8 +209,8 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message ...@@ -209,8 +209,8 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message
*/ */
public function setExtensionRange(&$var) public function setExtensionRange(&$var)
{ {
GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\DescriptorProto_ExtensionRange::class); $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\DescriptorProto_ExtensionRange::class);
$this->extension_range = $var; $this->extension_range = $arr;
$this->has_extension_range = true; $this->has_extension_range = true;
} }
...@@ -232,8 +232,8 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message ...@@ -232,8 +232,8 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message
*/ */
public function setOneofDecl(&$var) public function setOneofDecl(&$var)
{ {
GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\OneofDescriptorProto::class); $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\OneofDescriptorProto::class);
$this->oneof_decl = $var; $this->oneof_decl = $arr;
$this->has_oneof_decl = true; $this->has_oneof_decl = true;
} }
...@@ -278,8 +278,8 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message ...@@ -278,8 +278,8 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message
*/ */
public function setReservedRange(&$var) public function setReservedRange(&$var)
{ {
GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\DescriptorProto_ReservedRange::class); $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\DescriptorProto_ReservedRange::class);
$this->reserved_range = $var; $this->reserved_range = $arr;
$this->has_reserved_range = true; $this->has_reserved_range = true;
} }
...@@ -311,8 +311,8 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message ...@@ -311,8 +311,8 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message
*/ */
public function setReservedName(&$var) public function setReservedName(&$var)
{ {
GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING); $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING);
$this->reserved_name = $var; $this->reserved_name = $arr;
$this->has_reserved_name = true; $this->has_reserved_name = true;
} }
......
...@@ -77,8 +77,8 @@ class EnumDescriptorProto extends \Google\Protobuf\Internal\Message ...@@ -77,8 +77,8 @@ class EnumDescriptorProto extends \Google\Protobuf\Internal\Message
*/ */
public function setValue(&$var) public function setValue(&$var)
{ {
GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\EnumValueDescriptorProto::class); $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\EnumValueDescriptorProto::class);
$this->value = $var; $this->value = $arr;
$this->has_value = true; $this->has_value = true;
} }
......
...@@ -144,8 +144,8 @@ class EnumOptions extends \Google\Protobuf\Internal\Message ...@@ -144,8 +144,8 @@ class EnumOptions extends \Google\Protobuf\Internal\Message
*/ */
public function setUninterpretedOption(&$var) public function setUninterpretedOption(&$var)
{ {
GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class); $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class);
$this->uninterpreted_option = $var; $this->uninterpreted_option = $arr;
$this->has_uninterpreted_option = true; $this->has_uninterpreted_option = true;
} }
......
...@@ -101,8 +101,8 @@ class EnumValueOptions extends \Google\Protobuf\Internal\Message ...@@ -101,8 +101,8 @@ class EnumValueOptions extends \Google\Protobuf\Internal\Message
*/ */
public function setUninterpretedOption(&$var) public function setUninterpretedOption(&$var)
{ {
GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class); $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class);
$this->uninterpreted_option = $var; $this->uninterpreted_option = $arr;
$this->has_uninterpreted_option = true; $this->has_uninterpreted_option = true;
} }
......
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
# Generated by the protocol buffer compiler. DO NOT EDIT! # Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto # source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal;
/** /**
* Protobuf enum <code>google.protobuf.FieldDescriptorProto.Label</code> * Protobuf enum <code>google.protobuf.FieldDescriptorProto.Label</code>
*/ */
namespace Google\Protobuf\Internal;
class FieldDescriptorProto_Label class FieldDescriptorProto_Label
{ {
/** /**
......
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
# Generated by the protocol buffer compiler. DO NOT EDIT! # Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto # source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal;
/** /**
* Protobuf enum <code>google.protobuf.FieldDescriptorProto.Type</code> * Protobuf enum <code>google.protobuf.FieldDescriptorProto.Type</code>
*/ */
namespace Google\Protobuf\Internal;
class FieldDescriptorProto_Type class FieldDescriptorProto_Type
{ {
/** /**
...@@ -63,6 +63,9 @@ class FieldDescriptorProto_Type ...@@ -63,6 +63,9 @@ class FieldDescriptorProto_Type
/** /**
* <pre> * <pre>
* Tag-delimited aggregate. * Tag-delimited aggregate.
* Group type is deprecated and not supported in proto3. However, Proto3
* implementations should still be able to parse the group wire format and
* treat group fields as unknown fields.
* </pre> * </pre>
* *
* <code>TYPE_GROUP = 10;</code> * <code>TYPE_GROUP = 10;</code>
......
...@@ -415,8 +415,8 @@ class FieldOptions extends \Google\Protobuf\Internal\Message ...@@ -415,8 +415,8 @@ class FieldOptions extends \Google\Protobuf\Internal\Message
*/ */
public function setUninterpretedOption(&$var) public function setUninterpretedOption(&$var)
{ {
GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class); $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class);
$this->uninterpreted_option = $var; $this->uninterpreted_option = $arr;
$this->has_uninterpreted_option = true; $this->has_uninterpreted_option = true;
} }
......
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
# Generated by the protocol buffer compiler. DO NOT EDIT! # Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto # source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal;
/** /**
* Protobuf enum <code>google.protobuf.FieldOptions.CType</code> * Protobuf enum <code>google.protobuf.FieldOptions.CType</code>
*/ */
namespace Google\Protobuf\Internal;
class FieldOptions_CType class FieldOptions_CType
{ {
/** /**
......
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
# Generated by the protocol buffer compiler. DO NOT EDIT! # Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto # source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal;
/** /**
* Protobuf enum <code>google.protobuf.FieldOptions.JSType</code> * Protobuf enum <code>google.protobuf.FieldOptions.JSType</code>
*/ */
namespace Google\Protobuf\Internal;
class FieldOptions_JSType class FieldOptions_JSType
{ {
/** /**
......
...@@ -206,8 +206,8 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message ...@@ -206,8 +206,8 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message
*/ */
public function setDependency(&$var) public function setDependency(&$var)
{ {
GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING); $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING);
$this->dependency = $var; $this->dependency = $arr;
$this->has_dependency = true; $this->has_dependency = true;
} }
...@@ -237,8 +237,8 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message ...@@ -237,8 +237,8 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message
*/ */
public function setPublicDependency(&$var) public function setPublicDependency(&$var)
{ {
GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32); $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32);
$this->public_dependency = $var; $this->public_dependency = $arr;
$this->has_public_dependency = true; $this->has_public_dependency = true;
} }
...@@ -270,8 +270,8 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message ...@@ -270,8 +270,8 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message
*/ */
public function setWeakDependency(&$var) public function setWeakDependency(&$var)
{ {
GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32); $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32);
$this->weak_dependency = $var; $this->weak_dependency = $arr;
$this->has_weak_dependency = true; $this->has_weak_dependency = true;
} }
...@@ -301,8 +301,8 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message ...@@ -301,8 +301,8 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message
*/ */
public function setMessageType(&$var) public function setMessageType(&$var)
{ {
GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\DescriptorProto::class); $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\DescriptorProto::class);
$this->message_type = $var; $this->message_type = $arr;
$this->has_message_type = true; $this->has_message_type = true;
} }
...@@ -324,8 +324,8 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message ...@@ -324,8 +324,8 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message
*/ */
public function setEnumType(&$var) public function setEnumType(&$var)
{ {
GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\EnumDescriptorProto::class); $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\EnumDescriptorProto::class);
$this->enum_type = $var; $this->enum_type = $arr;
$this->has_enum_type = true; $this->has_enum_type = true;
} }
...@@ -347,8 +347,8 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message ...@@ -347,8 +347,8 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message
*/ */
public function setService(&$var) public function setService(&$var)
{ {
GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\ServiceDescriptorProto::class); $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\ServiceDescriptorProto::class);
$this->service = $var; $this->service = $arr;
$this->has_service = true; $this->has_service = true;
} }
...@@ -370,8 +370,8 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message ...@@ -370,8 +370,8 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message
*/ */
public function setExtension(&$var) public function setExtension(&$var)
{ {
GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\FieldDescriptorProto::class); $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\FieldDescriptorProto::class);
$this->extension = $var; $this->extension = $arr;
$this->has_extension = true; $this->has_extension = true;
} }
......
...@@ -45,8 +45,8 @@ class FileDescriptorSet extends \Google\Protobuf\Internal\Message ...@@ -45,8 +45,8 @@ class FileDescriptorSet extends \Google\Protobuf\Internal\Message
*/ */
public function setFile(&$var) public function setFile(&$var)
{ {
GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\FileDescriptorProto::class); $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\FileDescriptorProto::class);
$this->file = $var; $this->file = $arr;
$this->has_file = true; $this->has_file = true;
} }
......
...@@ -176,6 +176,16 @@ class FileOptions extends \Google\Protobuf\Internal\Message ...@@ -176,6 +176,16 @@ class FileOptions extends \Google\Protobuf\Internal\Message
*/ */
private $swift_prefix = ''; private $swift_prefix = '';
private $has_swift_prefix = false; private $has_swift_prefix = false;
/**
* <pre>
* Sets the php class prefix which is prepended to all php generated classes
* from this .proto. Default is empty.
* </pre>
*
* <code>optional string php_class_prefix = 40;</code>
*/
private $php_class_prefix = '';
private $has_php_class_prefix = false;
/** /**
* <pre> * <pre>
* The parser stores options it doesn't recognize here. See above. * The parser stores options it doesn't recognize here. See above.
...@@ -706,6 +716,39 @@ class FileOptions extends \Google\Protobuf\Internal\Message ...@@ -706,6 +716,39 @@ class FileOptions extends \Google\Protobuf\Internal\Message
return $this->has_swift_prefix; return $this->has_swift_prefix;
} }
/**
* <pre>
* Sets the php class prefix which is prepended to all php generated classes
* from this .proto. Default is empty.
* </pre>
*
* <code>optional string php_class_prefix = 40;</code>
*/
public function getPhpClassPrefix()
{
return $this->php_class_prefix;
}
/**
* <pre>
* Sets the php class prefix which is prepended to all php generated classes
* from this .proto. Default is empty.
* </pre>
*
* <code>optional string php_class_prefix = 40;</code>
*/
public function setPhpClassPrefix($var)
{
GPBUtil::checkString($var, True);
$this->php_class_prefix = $var;
$this->has_php_class_prefix = true;
}
public function hasPhpClassPrefix()
{
return $this->has_php_class_prefix;
}
/** /**
* <pre> * <pre>
* The parser stores options it doesn't recognize here. See above. * The parser stores options it doesn't recognize here. See above.
...@@ -727,8 +770,8 @@ class FileOptions extends \Google\Protobuf\Internal\Message ...@@ -727,8 +770,8 @@ class FileOptions extends \Google\Protobuf\Internal\Message
*/ */
public function setUninterpretedOption(&$var) public function setUninterpretedOption(&$var)
{ {
GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class); $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class);
$this->uninterpreted_option = $var; $this->uninterpreted_option = $arr;
$this->has_uninterpreted_option = true; $this->has_uninterpreted_option = true;
} }
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
# Generated by the protocol buffer compiler. DO NOT EDIT! # Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto # source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal;
/** /**
* <pre> * <pre>
* Generated classes can be optimized for speed or code size. * Generated classes can be optimized for speed or code size.
...@@ -9,8 +11,6 @@ ...@@ -9,8 +11,6 @@
* *
* Protobuf enum <code>google.protobuf.FileOptions.OptimizeMode</code> * Protobuf enum <code>google.protobuf.FileOptions.OptimizeMode</code>
*/ */
namespace Google\Protobuf\Internal;
class FileOptions_OptimizeMode class FileOptions_OptimizeMode
{ {
/** /**
......
...@@ -61,8 +61,8 @@ class GeneratedCodeInfo extends \Google\Protobuf\Internal\Message ...@@ -61,8 +61,8 @@ class GeneratedCodeInfo extends \Google\Protobuf\Internal\Message
*/ */
public function setAnnotation(&$var) public function setAnnotation(&$var)
{ {
GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\GeneratedCodeInfo_Annotation::class); $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\GeneratedCodeInfo_Annotation::class);
$this->annotation = $var; $this->annotation = $arr;
$this->has_annotation = true; $this->has_annotation = true;
} }
......
...@@ -85,8 +85,8 @@ class GeneratedCodeInfo_Annotation extends \Google\Protobuf\Internal\Message ...@@ -85,8 +85,8 @@ class GeneratedCodeInfo_Annotation extends \Google\Protobuf\Internal\Message
*/ */
public function setPath(&$var) public function setPath(&$var)
{ {
GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32); $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32);
$this->path = $var; $this->path = $arr;
$this->has_path = true; $this->has_path = true;
} }
......
...@@ -320,8 +320,8 @@ class MessageOptions extends \Google\Protobuf\Internal\Message ...@@ -320,8 +320,8 @@ class MessageOptions extends \Google\Protobuf\Internal\Message
*/ */
public function setUninterpretedOption(&$var) public function setUninterpretedOption(&$var)
{ {
GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class); $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class);
$this->uninterpreted_option = $var; $this->uninterpreted_option = $arr;
$this->has_uninterpreted_option = true; $this->has_uninterpreted_option = true;
} }
......
...@@ -129,8 +129,8 @@ class MethodOptions extends \Google\Protobuf\Internal\Message ...@@ -129,8 +129,8 @@ class MethodOptions extends \Google\Protobuf\Internal\Message
*/ */
public function setUninterpretedOption(&$var) public function setUninterpretedOption(&$var)
{ {
GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class); $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class);
$this->uninterpreted_option = $var; $this->uninterpreted_option = $arr;
$this->has_uninterpreted_option = true; $this->has_uninterpreted_option = true;
} }
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
# Generated by the protocol buffer compiler. DO NOT EDIT! # Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto # source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal;
/** /**
* <pre> * <pre>
* Is this method side-effect-free (or safe in HTTP parlance), or idempotent, * Is this method side-effect-free (or safe in HTTP parlance), or idempotent,
...@@ -11,8 +13,6 @@ ...@@ -11,8 +13,6 @@
* *
* Protobuf enum <code>google.protobuf.MethodOptions.IdempotencyLevel</code> * Protobuf enum <code>google.protobuf.MethodOptions.IdempotencyLevel</code>
*/ */
namespace Google\Protobuf\Internal;
class MethodOptions_IdempotencyLevel class MethodOptions_IdempotencyLevel
{ {
/** /**
......
...@@ -52,8 +52,8 @@ class OneofOptions extends \Google\Protobuf\Internal\Message ...@@ -52,8 +52,8 @@ class OneofOptions extends \Google\Protobuf\Internal\Message
*/ */
public function setUninterpretedOption(&$var) public function setUninterpretedOption(&$var)
{ {
GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class); $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class);
$this->uninterpreted_option = $var; $this->uninterpreted_option = $arr;
$this->has_uninterpreted_option = true; $this->has_uninterpreted_option = true;
} }
......
...@@ -77,8 +77,8 @@ class ServiceDescriptorProto extends \Google\Protobuf\Internal\Message ...@@ -77,8 +77,8 @@ class ServiceDescriptorProto extends \Google\Protobuf\Internal\Message
*/ */
public function setMethod(&$var) public function setMethod(&$var)
{ {
GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\MethodDescriptorProto::class); $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\MethodDescriptorProto::class);
$this->method = $var; $this->method = $arr;
$this->has_method = true; $this->has_method = true;
} }
......
...@@ -101,8 +101,8 @@ class ServiceOptions extends \Google\Protobuf\Internal\Message ...@@ -101,8 +101,8 @@ class ServiceOptions extends \Google\Protobuf\Internal\Message
*/ */
public function setUninterpretedOption(&$var) public function setUninterpretedOption(&$var)
{ {
GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class); $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class);
$this->uninterpreted_option = $var; $this->uninterpreted_option = $arr;
$this->has_uninterpreted_option = true; $this->has_uninterpreted_option = true;
} }
......
...@@ -177,8 +177,8 @@ class SourceCodeInfo extends \Google\Protobuf\Internal\Message ...@@ -177,8 +177,8 @@ class SourceCodeInfo extends \Google\Protobuf\Internal\Message
*/ */
public function setLocation(&$var) public function setLocation(&$var)
{ {
GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\SourceCodeInfo_Location::class); $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\SourceCodeInfo_Location::class);
$this->location = $var; $this->location = $arr;
$this->has_location = true; $this->has_location = true;
} }
......
...@@ -179,8 +179,8 @@ class SourceCodeInfo_Location extends \Google\Protobuf\Internal\Message ...@@ -179,8 +179,8 @@ class SourceCodeInfo_Location extends \Google\Protobuf\Internal\Message
*/ */
public function setPath(&$var) public function setPath(&$var)
{ {
GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32); $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32);
$this->path = $var; $this->path = $arr;
$this->has_path = true; $this->has_path = true;
} }
...@@ -218,8 +218,8 @@ class SourceCodeInfo_Location extends \Google\Protobuf\Internal\Message ...@@ -218,8 +218,8 @@ class SourceCodeInfo_Location extends \Google\Protobuf\Internal\Message
*/ */
public function setSpan(&$var) public function setSpan(&$var)
{ {
GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32); $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32);
$this->span = $var; $this->span = $arr;
$this->has_span = true; $this->has_span = true;
} }
...@@ -365,8 +365,8 @@ class SourceCodeInfo_Location extends \Google\Protobuf\Internal\Message ...@@ -365,8 +365,8 @@ class SourceCodeInfo_Location extends \Google\Protobuf\Internal\Message
*/ */
public function setLeadingDetachedComments(&$var) public function setLeadingDetachedComments(&$var)
{ {
GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING); $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING);
$this->leading_detached_comments = $var; $this->leading_detached_comments = $arr;
$this->has_leading_detached_comments = true; $this->has_leading_detached_comments = true;
} }
......
...@@ -84,8 +84,8 @@ class UninterpretedOption extends \Google\Protobuf\Internal\Message ...@@ -84,8 +84,8 @@ class UninterpretedOption extends \Google\Protobuf\Internal\Message
*/ */
public function setName(&$var) public function setName(&$var)
{ {
GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption_NamePart::class); $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption_NamePart::class);
$this->name = $var; $this->name = $arr;
$this->has_name = true; $this->has_name = true;
} }
......
...@@ -78,14 +78,14 @@ class FileDescriptor ...@@ -78,14 +78,14 @@ class FileDescriptor
$file->setPackage($proto->getPackage()); $file->setPackage($proto->getPackage());
foreach ($proto->getMessageType() as $message_proto) { foreach ($proto->getMessageType() as $message_proto) {
$file->addMessageType(Descriptor::buildFromProto( $file->addMessageType(Descriptor::buildFromProto(
$message_proto, $file->getPackage(), "")); $message_proto, $proto, ""));
} }
foreach ($proto->getEnumType() as $enum_proto) { foreach ($proto->getEnumType() as $enum_proto) {
$file->getEnumType()[] = $file->getEnumType()[] =
$file->addEnumType( $file->addEnumType(
EnumDescriptor::buildFromProto( EnumDescriptor::buildFromProto(
$enum_proto, $enum_proto,
$file->getPackage(), $proto,
"")); ""));
} }
return $file; return $file;
...@@ -182,7 +182,7 @@ class Descriptor ...@@ -182,7 +182,7 @@ class Descriptor
return $this->options; return $this->options;
} }
public static function buildFromProto($proto, $package, $containing) public static function buildFromProto($proto, $file_proto, $containing)
{ {
$desc = new Descriptor(); $desc = new Descriptor();
...@@ -192,7 +192,7 @@ class Descriptor ...@@ -192,7 +192,7 @@ class Descriptor
getFullClassName( getFullClassName(
$proto, $proto,
$containing, $containing,
$package, $file_proto,
$message_name_without_package, $message_name_without_package,
$classname, $classname,
$fullname); $fullname);
...@@ -207,7 +207,7 @@ class Descriptor ...@@ -207,7 +207,7 @@ class Descriptor
// Handle nested types. // Handle nested types.
foreach ($proto->getNestedType() as $nested_proto) { foreach ($proto->getNestedType() as $nested_proto) {
$desc->addNestedType(Descriptor::buildFromProto( $desc->addNestedType(Descriptor::buildFromProto(
$nested_proto, $package, $message_name_without_package)); $nested_proto, $file_proto, $message_name_without_package));
} }
// Handle oneof fields. // Handle oneof fields.
...@@ -220,43 +220,46 @@ class Descriptor ...@@ -220,43 +220,46 @@ class Descriptor
} }
} }
function addPrefixIfSpecial( function getClassNameWithoutPackage(
$name, $name,
$package) $file_proto)
{ {
if ($name === "Empty" && $package === "google.protobuf") { if ($name === "Empty" && $file_proto->getPackage() === "google.protobuf") {
return "GPBEmpty"; return "GPBEmpty";
} else { } else {
return $name; $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)));
} }
} }
function getFullClassName( function getFullClassName(
$proto, $proto,
$containing, $containing,
$package, $file_proto,
&$message_name_without_package, &$message_name_without_package,
&$classname, &$classname,
&$fullname) &$fullname)
{ {
// Full name needs to start with '.'. // Full name needs to start with '.'.
$message_name_without_package = $message_name_without_package = $proto->getName();
addPrefixIfSpecial($proto->getName(), $package);
if ($containing !== "") { if ($containing !== "") {
$message_name_without_package = $message_name_without_package =
$containing . "." . $message_name_without_package; $containing . "." . $message_name_without_package;
} }
$package = $file_proto->getPackage();
if ($package === "") { if ($package === "") {
$fullname = "." . $message_name_without_package; $fullname = "." . $message_name_without_package;
} else { } else {
$fullname = "." . $package . "." . $message_name_without_package; $fullname = "." . $package . "." . $message_name_without_package;
} }
// Nested message class names are seperated by '_', and package names are
// seperated by '\'.
$class_name_without_package = $class_name_without_package =
implode('_', array_map('ucwords', getClassNameWithoutPackage($message_name_without_package, $file_proto);
explode('.', $message_name_without_package)));
if ($package === "") { if ($package === "") {
$classname = $class_name_without_package; $classname = $class_name_without_package;
} else { } else {
...@@ -333,7 +336,7 @@ class EnumDescriptor ...@@ -333,7 +336,7 @@ class EnumDescriptor
return $this->klass; return $this->klass;
} }
public static function buildFromProto($proto, $package, $containing) public static function buildFromProto($proto, $file_proto, $containing)
{ {
$desc = new EnumDescriptor(); $desc = new EnumDescriptor();
...@@ -343,7 +346,7 @@ class EnumDescriptor ...@@ -343,7 +346,7 @@ class EnumDescriptor
getFullClassName( getFullClassName(
$proto, $proto,
$containing, $containing,
$package, $file_proto,
$enum_name_without_package, $enum_name_without_package,
$classname, $classname,
$fullname); $fullname);
......
...@@ -194,7 +194,7 @@ class EncodeDecodeTest extends TestBase ...@@ -194,7 +194,7 @@ class EncodeDecodeTest extends TestBase
{ {
$m = new TestMessage(); $m = new TestMessage();
$m->setOptionalInt32(-1); $m->setOptionalInt32(-1);
$data = $m->encode(); $data = $m->serializeToString();
$this->assertSame("08ffffffffffffffffff01", bin2hex($data)); $this->assertSame("08ffffffffffffffffff01", bin2hex($data));
} }
...@@ -202,12 +202,12 @@ class EncodeDecodeTest extends TestBase ...@@ -202,12 +202,12 @@ class EncodeDecodeTest extends TestBase
{ {
$m = new TestMessage(); $m = new TestMessage();
$this->assertEquals(0, $m->getOptionalInt32()); $this->assertEquals(0, $m->getOptionalInt32());
$m->decode(hex2bin("08ffffffffffffffffff01")); $m->mergeFromString(hex2bin("08ffffffffffffffffff01"));
$this->assertEquals(-1, $m->getOptionalInt32()); $this->assertEquals(-1, $m->getOptionalInt32());
$m = new TestMessage(); $m = new TestMessage();
$this->assertEquals(0, $m->getOptionalInt32()); $this->assertEquals(0, $m->getOptionalInt32());
$m->decode(hex2bin("08ffffffff0f")); $m->mergeFromString(hex2bin("08ffffffff0f"));
$this->assertEquals(-1, $m->getOptionalInt32()); $this->assertEquals(-1, $m->getOptionalInt32());
} }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
# gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so `which # gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so `which
# phpunit` --bootstrap autoload.php tmp_test.php # phpunit` --bootstrap autoload.php tmp_test.php
# #
gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so `which phpunit` --bootstrap autoload.php encode_decode_test.php gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so `which phpunit` --bootstrap autoload.php array_test.php
# #
# # gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so # # gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so
# memory_leak_test.php # memory_leak_test.php
......
...@@ -9,6 +9,7 @@ use Google\Protobuf\Internal\RepeatedField; ...@@ -9,6 +9,7 @@ use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\MapField; use Google\Protobuf\Internal\MapField;
use Google\Protobuf\Internal\GPBType; use Google\Protobuf\Internal\GPBType;
use Foo\TestEnum; use Foo\TestEnum;
use Foo\TestIncludePrefixMessage;
use Foo\TestMessage; use Foo\TestMessage;
use Foo\TestMessage_Sub; use Foo\TestMessage_Sub;
...@@ -838,4 +839,17 @@ class GeneratedClassTest extends TestBase ...@@ -838,4 +839,17 @@ class GeneratedClassTest extends TestBase
{ {
$m = new NoNameSpaceEnum(); $m = new NoNameSpaceEnum();
} }
#########################################################
# Test message with given prefix.
#########################################################
public function testPrefixMessage()
{
$m = new TestIncludePrefixMessage();
$n = new PrefixTestPrefix();
$n->setA(1);
$m->setPrefixMessage($n);
$this->assertSame(1, $m->getPrefixMessage()->getA());
}
} }
...@@ -2,8 +2,10 @@ ...@@ -2,8 +2,10 @@
# phpunit has memory leak by itself. Thus, it cannot be used to test memory leak. # phpunit has memory leak by itself. Thus, it cannot be used to test memory leak.
require_once('generated/PrefixTestPrefix.php');
require_once('generated/Bar/TestInclude.php'); require_once('generated/Bar/TestInclude.php');
require_once('generated/Foo/TestEnum.php'); require_once('generated/Foo/TestEnum.php');
require_once('generated/Foo/TestIncludePrefixMessage.php');
require_once('generated/Foo/TestMessage.php'); require_once('generated/Foo/TestMessage.php');
require_once('generated/Foo/TestMessage_Sub.php'); require_once('generated/Foo/TestMessage_Sub.php');
require_once('generated/Foo/TestPackedMessage.php'); require_once('generated/Foo/TestPackedMessage.php');
...@@ -11,6 +13,7 @@ require_once('generated/Foo/TestPhpDoc.php'); ...@@ -11,6 +13,7 @@ require_once('generated/Foo/TestPhpDoc.php');
require_once('generated/Foo/TestUnpackedMessage.php'); require_once('generated/Foo/TestUnpackedMessage.php');
require_once('generated/GPBMetadata/Proto/Test.php'); require_once('generated/GPBMetadata/Proto/Test.php');
require_once('generated/GPBMetadata/Proto/TestInclude.php'); require_once('generated/GPBMetadata/Proto/TestInclude.php');
require_once('generated/GPBMetadata/Proto/TestPrefix.php');
require_once('test_util.php'); require_once('test_util.php');
use Google\Protobuf\Internal\RepeatedField; use Google\Protobuf\Internal\RepeatedField;
......
syntax = "proto3"; syntax = "proto3";
import 'proto/test_include.proto'; import 'proto/test_include.proto';
import 'proto/test_prefix.proto';
package foo; package foo;
...@@ -142,3 +143,7 @@ message TestUnpackedMessage { ...@@ -142,3 +143,7 @@ message TestUnpackedMessage {
message TestPhpDoc { message TestPhpDoc {
int32 a = 1; int32 a = 1;
} }
message TestIncludePrefixMessage {
TestPrefix prefix_message = 1;
}
syntax = "proto3";
option php_class_prefix = "Prefix";
message TestPrefix {
int32 a = 1;
}
...@@ -90,7 +90,7 @@ std::string MessagePrefix(const Descriptor* message) { ...@@ -90,7 +90,7 @@ std::string MessagePrefix(const Descriptor* message) {
message->file()->package() == "google.protobuf") { message->file()->package() == "google.protobuf") {
return "GPB"; return "GPB";
} else { } else {
return ""; return (message->file()->options()).php_class_prefix();
} }
} }
...@@ -103,8 +103,12 @@ std::string MessageName(const Descriptor* message, bool is_descriptor) { ...@@ -103,8 +103,12 @@ std::string MessageName(const Descriptor* message, bool is_descriptor) {
} }
message_name = MessagePrefix(message) + message_name; message_name = MessagePrefix(message) + message_name;
return PhpName(message->file()->package(), is_descriptor) + '\\' + if (message->file()->package() == "") {
message_name; return message_name;
} else {
return PhpName(message->file()->package(), is_descriptor) + '\\' +
message_name;
}
} }
std::string MessageFullName(const Descriptor* message, bool is_descriptor) { std::string MessageFullName(const Descriptor* message, bool is_descriptor) {
......
This diff is collapsed.
This diff is collapsed.
...@@ -376,6 +376,10 @@ message FileOptions { ...@@ -376,6 +376,10 @@ message FileOptions {
// to prefix the types/symbols defined. // to prefix the types/symbols defined.
optional string swift_prefix = 39; optional string swift_prefix = 39;
// Sets the php class prefix which is prepended to all php generated classes
// from this .proto. Default is empty.
optional string php_class_prefix = 40;
// The parser stores options it doesn't recognize here. See above. // The parser stores options it doesn't recognize here. See above.
repeated UninterpretedOption uninterpreted_option = 999; repeated UninterpretedOption uninterpreted_option = 999;
......
...@@ -358,7 +358,7 @@ generate_php_test_proto() { ...@@ -358,7 +358,7 @@ generate_php_test_proto() {
# Generate test file # Generate test file
rm -rf generated rm -rf generated
mkdir generated mkdir generated
../../src/protoc --php_out=generated proto/test.proto proto/test_include.proto proto/test_no_namespace.proto ../../src/protoc --php_out=generated proto/test.proto proto/test_include.proto proto/test_no_namespace.proto proto/test_prefix.proto
pushd ../../src pushd ../../src
./protoc --php_out=../php/tests/generated google/protobuf/empty.proto ./protoc --php_out=../php/tests/generated google/protobuf/empty.proto
popd popd
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment