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
662e8b20
Unverified
Commit
662e8b20
authored
Nov 08, 2017
by
Paul Yang
Committed by
GitHub
Nov 08, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Provide util funtions to figure out correct php class names. (#3850)
parent
1144768d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
9 deletions
+36
-9
php_generator.cc
src/google/protobuf/compiler/php/php_generator.cc
+27
-9
php_generator.h
src/google/protobuf/compiler/php/php_generator.h
+9
-0
No files found.
src/google/protobuf/compiler/php/php_generator.cc
View file @
662e8b20
...
@@ -215,19 +215,12 @@ std::string NamespacedName(const string& classname,
...
@@ -215,19 +215,12 @@ std::string NamespacedName(const string& classname,
template
<
typename
DescriptorType
>
template
<
typename
DescriptorType
>
std
::
string
FullClassName
(
const
DescriptorType
*
desc
,
bool
is_descriptor
)
{
std
::
string
FullClassName
(
const
DescriptorType
*
desc
,
bool
is_descriptor
)
{
string
classname
=
desc
->
name
();
string
classname
=
GeneratedClassName
(
desc
);
const
Descriptor
*
containing
=
desc
->
containing_type
();
while
(
containing
!=
NULL
)
{
classname
=
containing
->
name
()
+
'_'
+
classname
;
containing
=
containing
->
containing_type
();
}
classname
=
ClassNamePrefix
(
classname
,
desc
)
+
classname
;
return
NamespacedName
(
classname
,
desc
,
is_descriptor
);
return
NamespacedName
(
classname
,
desc
,
is_descriptor
);
}
}
std
::
string
FullClassName
(
const
ServiceDescriptor
*
desc
,
bool
is_descriptor
)
{
std
::
string
FullClassName
(
const
ServiceDescriptor
*
desc
,
bool
is_descriptor
)
{
string
classname
=
desc
->
name
();
string
classname
=
GeneratedClassName
(
desc
);
classname
=
ClassNamePrefix
(
classname
,
desc
)
+
classname
;
return
NamespacedName
(
classname
,
desc
,
is_descriptor
);
return
NamespacedName
(
classname
,
desc
,
is_descriptor
);
}
}
...
@@ -1419,6 +1412,31 @@ bool Generator::Generate(const FileDescriptor* file, const string& parameter,
...
@@ -1419,6 +1412,31 @@ bool Generator::Generate(const FileDescriptor* file, const string& parameter,
return
true
;
return
true
;
}
}
std
::
string
GeneratedClassName
(
const
Descriptor
*
desc
)
{
std
::
string
classname
=
desc
->
name
();
const
Descriptor
*
containing
=
desc
->
containing_type
();
while
(
containing
!=
NULL
)
{
classname
=
containing
->
name
()
+
'_'
+
classname
;
containing
=
containing
->
containing_type
();
}
return
ClassNamePrefix
(
classname
,
desc
)
+
classname
;
}
std
::
string
GeneratedClassName
(
const
EnumDescriptor
*
desc
)
{
std
::
string
classname
=
desc
->
name
();
const
Descriptor
*
containing
=
desc
->
containing_type
();
while
(
containing
!=
NULL
)
{
classname
=
containing
->
name
()
+
'_'
+
classname
;
containing
=
containing
->
containing_type
();
}
return
ClassNamePrefix
(
classname
,
desc
)
+
classname
;
}
std
::
string
GeneratedClassName
(
const
ServiceDescriptor
*
desc
)
{
std
::
string
classname
=
desc
->
name
();
return
ClassNamePrefix
(
classname
,
desc
)
+
classname
;
}
}
// namespace php
}
// namespace php
}
// namespace compiler
}
// namespace compiler
}
// namespace protobuf
}
// namespace protobuf
...
...
src/google/protobuf/compiler/php/php_generator.h
View file @
662e8b20
...
@@ -32,6 +32,7 @@
...
@@ -32,6 +32,7 @@
#define GOOGLE_PROTOBUF_COMPILER_PHP_GENERATOR_H__
#define GOOGLE_PROTOBUF_COMPILER_PHP_GENERATOR_H__
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/descriptor.h>
#include <string>
#include <string>
...
@@ -47,8 +48,16 @@ class LIBPROTOC_EXPORT Generator
...
@@ -47,8 +48,16 @@ class LIBPROTOC_EXPORT Generator
const
string
&
parameter
,
const
string
&
parameter
,
GeneratorContext
*
generator_context
,
GeneratorContext
*
generator_context
,
string
*
error
)
const
;
string
*
error
)
const
;
};
};
// To skip reserved keywords in php, some generated classname are prefixed.
// Other code generators may need following API to figure out the actual
// classname.
std
::
string
GeneratedClassName
(
const
google
::
protobuf
::
Descriptor
*
desc
);
std
::
string
GeneratedClassName
(
const
google
::
protobuf
::
EnumDescriptor
*
desc
);
std
::
string
GeneratedClassName
(
const
google
::
protobuf
::
ServiceDescriptor
*
desc
);
}
// namespace php
}
// namespace php
}
// namespace compiler
}
// namespace compiler
}
// namespace protobuf
}
// namespace protobuf
...
...
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