Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
25672c17
Commit
25672c17
authored
Aug 03, 2017
by
Paul Yang
Committed by
GitHub
Aug 03, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add getClass for php Descriptor in c extension (#3443)
parent
9df89cca
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
1 deletion
+16
-1
def.c
php/ext/google/protobuf/def.c
+11
-0
protobuf.h
php/ext/google/protobuf/protobuf.h
+1
-0
descriptors_test.php
php/tests/descriptors_test.php
+4
-1
No files found.
php/ext/google/protobuf/def.c
View file @
25672c17
...
...
@@ -184,6 +184,7 @@ void gpb_type_init(TSRMLS_D) {
// -----------------------------------------------------------------------------
static
zend_function_entry
descriptor_methods
[]
=
{
PHP_ME
(
Descriptor
,
getClass
,
NULL
,
ZEND_ACC_PUBLIC
)
PHP_ME
(
Descriptor
,
getFullName
,
NULL
,
ZEND_ACC_PUBLIC
)
PHP_ME
(
Descriptor
,
getField
,
NULL
,
ZEND_ACC_PUBLIC
)
PHP_ME
(
Descriptor
,
getFieldCount
,
NULL
,
ZEND_ACC_PUBLIC
)
...
...
@@ -234,6 +235,16 @@ static void descriptor_init_c_instance(Descriptor *desc TSRMLS_DC) {
desc
->
json_serialize_handlers_preserve
=
NULL
;
}
PHP_METHOD
(
Descriptor
,
getClass
)
{
Descriptor
*
intern
=
UNBOX
(
Descriptor
,
getThis
());
#if PHP_MAJOR_VERSION < 7
const
char
*
classname
=
intern
->
klass
->
name
;
#else
const
char
*
classname
=
ZSTR_VAL
(
intern
->
klass
->
name
);
#endif
PHP_PROTO_RETVAL_STRINGL
(
classname
,
strlen
(
classname
),
1
);
}
PHP_METHOD
(
Descriptor
,
getFullName
)
{
Descriptor
*
intern
=
UNBOX
(
Descriptor
,
getThis
());
const
char
*
fullname
=
upb_msgdef_fullname
(
intern
->
msgdef
);
...
...
php/ext/google/protobuf/protobuf.h
View file @
25672c17
...
...
@@ -508,6 +508,7 @@ PHP_PROTO_WRAP_OBJECT_START(Descriptor)
const
upb_handlers
*
json_serialize_handlers_preserve
;
PHP_PROTO_WRAP_OBJECT_END
PHP_METHOD
(
Descriptor
,
getClass
);
PHP_METHOD
(
Descriptor
,
getFullName
);
PHP_METHOD
(
Descriptor
,
getField
);
PHP_METHOD
(
Descriptor
,
getFieldCount
);
...
...
php/tests/descriptors_test.php
View file @
25672c17
...
...
@@ -75,9 +75,12 @@ class DescriptorsTest extends TestBase
public
function
testDescriptor
()
{
$pool
=
DescriptorPool
::
getGeneratedPool
();
$desc
=
$pool
->
getDescriptorByClassName
(
get_class
(
new
TestDescriptorsMessage
()));
$class
=
get_class
(
new
TestDescriptorsMessage
());
$this
->
assertSame
(
'Descriptors\TestDescriptorsMessage'
,
$class
);
$desc
=
$pool
->
getDescriptorByClassName
(
$class
);
$this
->
assertSame
(
'descriptors.TestDescriptorsMessage'
,
$desc
->
getFullName
());
$this
->
assertSame
(
$class
,
$desc
->
getClass
());
$this
->
assertInstanceOf
(
'\Google\Protobuf\FieldDescriptor'
,
$desc
->
getField
(
0
));
$this
->
assertSame
(
7
,
$desc
->
getFieldCount
());
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment