mirror of
https://github.com/protocolbuffers/protobuf
synced 2026-08-26 02:23:14 -04:00
This is a reopening of https://github.com/protocolbuffers/protobuf/issues/6035, where it was requested that someone contribute a PR. I chose the option name `EMIT_DEFAULTS` to match the ruby client and existing upd option. I tried to be relatively comprehensive with the tests, but let me know if there's anything stylistically or logically you want changed.
Locally the tests run happily:
```
php % git rev-parse HEAD
7cb3b2d9f60bdffce69c01143ca15c46d2eaa900
php % php -dextension=ext/google/protobuf/modules/protobuf.so -d error_reporting="E_ALL & ~E_DEPRECATED" vendor/bin/phpunit --bootstrap tests/force_c_ext.php tests/EncodeDecodeTest.php
PHPUnit 8.5.26 #StandWithUkraine
............................................................... 63 / 147 ( 42%)
............................................................... 126 / 147 ( 85%)
..................... 147 / 147 (100%)
Time: 49 ms, Memory: 6.00 MB
OK (147 tests, 1150 assertions)
```
Closes #23985
COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/23985 from SpencerMalone:php-default-value-option 6d8bc74056
PiperOrigin-RevId: 821657589
29 lines
1.1 KiB
C
29 lines
1.1 KiB
C
// Protocol Buffers - Google's data interchange format
|
|
// Copyright 2008 Google Inc. All rights reserved.
|
|
//
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file or at
|
|
// https://developers.google.com/open-source/licenses/bsd
|
|
|
|
#include "print_options.h"
|
|
|
|
#include "php.h"
|
|
|
|
zend_class_entry* options_ce;
|
|
|
|
void PrintOptions_ModuleInit() {
|
|
zend_class_entry tmp_ce;
|
|
|
|
INIT_CLASS_ENTRY(tmp_ce, "Google\\Protobuf\\PrintOptions", NULL);
|
|
options_ce = zend_register_internal_class(&tmp_ce);
|
|
|
|
// Define constants
|
|
zend_declare_class_constant_long(options_ce, "PRESERVE_PROTO_FIELD_NAMES",
|
|
sizeof("PRESERVE_PROTO_FIELD_NAMES") - 1,
|
|
PRESERVE_PROTO_FIELD_NAMES);
|
|
zend_declare_class_constant_long(options_ce, "ALWAYS_PRINT_ENUMS_AS_INTS",
|
|
sizeof("ALWAYS_PRINT_ENUMS_AS_INTS") - 1,
|
|
ALWAYS_PRINT_ENUMS_AS_INTS);
|
|
zend_declare_class_constant_long(options_ce, "EMIT_DEFAULTS",
|
|
sizeof("EMIT_DEFAULTS") - 1, EMIT_DEFAULTS);
|
|
}
|