Skip to content

Commit 9a7a09e

Browse files
committed
Implement Google\Protobuf\Value:has* methods
1 parent fab79f4 commit 9a7a09e

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

php/ext/google/protobuf/wkt.inc

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,14 @@ static PHP_METHOD(google_protobuf_Value, __construct) {
12131213
zim_Message___construct(INTERNAL_FUNCTION_PARAM_PASSTHRU);
12141214
}
12151215

1216+
static PHP_METHOD(google_protobuf_Value, hasNullValue) {
1217+
Message* intern = (Message*)Z_OBJ_P(getThis());
1218+
const upb_FieldDef *f = upb_MessageDef_FindFieldByName(
1219+
intern->desc->msgdef, "null_value");
1220+
1221+
RETVAL_BOOL(upb_Message_HasFieldByDef(intern->msg, f));
1222+
}
1223+
12161224
static PHP_METHOD(google_protobuf_Value, getNullValue) {
12171225
Message* intern = (Message*)Z_OBJ_P(getThis());
12181226
const upb_FieldDef *f = upb_MessageDef_FindFieldByName(
@@ -1235,6 +1243,14 @@ static PHP_METHOD(google_protobuf_Value, setNullValue) {
12351243
RETURN_COPY(getThis());
12361244
}
12371245

1246+
static PHP_METHOD(google_protobuf_Value, hasNumberValue) {
1247+
Message* intern = (Message*)Z_OBJ_P(getThis());
1248+
const upb_FieldDef *f = upb_MessageDef_FindFieldByName(
1249+
intern->desc->msgdef, "number_value");
1250+
1251+
RETVAL_BOOL(upb_Message_HasFieldByDef(intern->msg, f));
1252+
}
1253+
12381254
static PHP_METHOD(google_protobuf_Value, getNumberValue) {
12391255
Message* intern = (Message*)Z_OBJ_P(getThis());
12401256
const upb_FieldDef *f = upb_MessageDef_FindFieldByName(
@@ -1257,6 +1273,14 @@ static PHP_METHOD(google_protobuf_Value, setNumberValue) {
12571273
RETURN_COPY(getThis());
12581274
}
12591275

1276+
static PHP_METHOD(google_protobuf_Value, hasStringValue) {
1277+
Message* intern = (Message*)Z_OBJ_P(getThis());
1278+
const upb_FieldDef *f = upb_MessageDef_FindFieldByName(
1279+
intern->desc->msgdef, "string_value");
1280+
1281+
RETVAL_BOOL(upb_Message_HasFieldByDef(intern->msg, f));
1282+
}
1283+
12601284
static PHP_METHOD(google_protobuf_Value, getStringValue) {
12611285
Message* intern = (Message*)Z_OBJ_P(getThis());
12621286
const upb_FieldDef *f = upb_MessageDef_FindFieldByName(
@@ -1279,6 +1303,14 @@ static PHP_METHOD(google_protobuf_Value, setStringValue) {
12791303
RETURN_COPY(getThis());
12801304
}
12811305

1306+
static PHP_METHOD(google_protobuf_Value, hasBoolValue) {
1307+
Message* intern = (Message*)Z_OBJ_P(getThis());
1308+
const upb_FieldDef *f = upb_MessageDef_FindFieldByName(
1309+
intern->desc->msgdef, "bool_value");
1310+
1311+
RETVAL_BOOL(upb_Message_HasFieldByDef(intern->msg, f));
1312+
}
1313+
12821314
static PHP_METHOD(google_protobuf_Value, getBoolValue) {
12831315
Message* intern = (Message*)Z_OBJ_P(getThis());
12841316
const upb_FieldDef *f = upb_MessageDef_FindFieldByName(
@@ -1301,6 +1333,14 @@ static PHP_METHOD(google_protobuf_Value, setBoolValue) {
13011333
RETURN_COPY(getThis());
13021334
}
13031335

1336+
static PHP_METHOD(google_protobuf_Value, hasStructValue) {
1337+
Message* intern = (Message*)Z_OBJ_P(getThis());
1338+
const upb_FieldDef *f = upb_MessageDef_FindFieldByName(
1339+
intern->desc->msgdef, "struct_value");
1340+
1341+
RETVAL_BOOL(upb_Message_HasFieldByDef(intern->msg, f));
1342+
}
1343+
13041344
static PHP_METHOD(google_protobuf_Value, getStructValue) {
13051345
Message* intern = (Message*)Z_OBJ_P(getThis());
13061346
const upb_FieldDef *f = upb_MessageDef_FindFieldByName(
@@ -1323,6 +1363,14 @@ static PHP_METHOD(google_protobuf_Value, setStructValue) {
13231363
RETURN_COPY(getThis());
13241364
}
13251365

1366+
static PHP_METHOD(google_protobuf_Value, hasListValue) {
1367+
Message* intern = (Message*)Z_OBJ_P(getThis());
1368+
const upb_FieldDef *f = upb_MessageDef_FindFieldByName(
1369+
intern->desc->msgdef, "list_value");
1370+
1371+
RETVAL_BOOL(upb_Message_HasFieldByDef(intern->msg, f));
1372+
}
1373+
13261374
static PHP_METHOD(google_protobuf_Value, getListValue) {
13271375
Message* intern = (Message*)Z_OBJ_P(getThis());
13281376
const upb_FieldDef *f = upb_MessageDef_FindFieldByName(
@@ -1355,16 +1403,22 @@ static PHP_METHOD(google_protobuf_Value, getKind) {
13551403
}
13561404
static zend_function_entry google_protobuf_Value_phpmethods[] = {
13571405
PHP_ME(google_protobuf_Value, __construct, arginfo_construct, ZEND_ACC_PUBLIC)
1406+
PHP_ME(google_protobuf_Value, hasNullValue, arginfo_void, ZEND_ACC_PUBLIC)
13581407
PHP_ME(google_protobuf_Value, getNullValue, arginfo_void, ZEND_ACC_PUBLIC)
13591408
PHP_ME(google_protobuf_Value, setNullValue, arginfo_setter, ZEND_ACC_PUBLIC)
1409+
PHP_ME(google_protobuf_Value, hasNumberValue, arginfo_void, ZEND_ACC_PUBLIC)
13601410
PHP_ME(google_protobuf_Value, getNumberValue, arginfo_void, ZEND_ACC_PUBLIC)
13611411
PHP_ME(google_protobuf_Value, setNumberValue, arginfo_setter, ZEND_ACC_PUBLIC)
1412+
PHP_ME(google_protobuf_Value, hasStringValue, arginfo_void, ZEND_ACC_PUBLIC)
13621413
PHP_ME(google_protobuf_Value, getStringValue, arginfo_void, ZEND_ACC_PUBLIC)
13631414
PHP_ME(google_protobuf_Value, setStringValue, arginfo_setter, ZEND_ACC_PUBLIC)
1415+
PHP_ME(google_protobuf_Value, hasBoolValue, arginfo_void, ZEND_ACC_PUBLIC)
13641416
PHP_ME(google_protobuf_Value, getBoolValue, arginfo_void, ZEND_ACC_PUBLIC)
13651417
PHP_ME(google_protobuf_Value, setBoolValue, arginfo_setter, ZEND_ACC_PUBLIC)
1418+
PHP_ME(google_protobuf_Value, hasStructValue, arginfo_void, ZEND_ACC_PUBLIC)
13661419
PHP_ME(google_protobuf_Value, getStructValue, arginfo_void, ZEND_ACC_PUBLIC)
13671420
PHP_ME(google_protobuf_Value, setStructValue, arginfo_setter, ZEND_ACC_PUBLIC)
1421+
PHP_ME(google_protobuf_Value, hasListValue, arginfo_void, ZEND_ACC_PUBLIC)
13681422
PHP_ME(google_protobuf_Value, getListValue, arginfo_void, ZEND_ACC_PUBLIC)
13691423
PHP_ME(google_protobuf_Value, setListValue, arginfo_setter, ZEND_ACC_PUBLIC)
13701424
PHP_ME(google_protobuf_Value, getKind, arginfo_void, ZEND_ACC_PUBLIC)

php/tests/has_value_test.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
require_once (dirname(__DIR__) . '/vendor/autoload.php');
4+
5+
use Google\Protobuf\Value;
6+
7+
$v = new Value();
8+
9+
var_dump($v->hasNullValue());
10+
11+
$v->setNullValue(0);
12+
13+
var_dump($v->hasNullValue());

0 commit comments

Comments
 (0)