Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
F
flatbuffers
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
flatbuffers
Commits
66f2aac2
Commit
66f2aac2
authored
Jun 14, 2016
by
lakedaemon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
php:pulled methods inside the generator
parent
4a249752
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
67 additions
and
75 deletions
+67
-75
idl_gen_php.cpp
src/idl_gen_php.cpp
+67
-75
No files found.
src/idl_gen_php.cpp
View file @
66f2aac2
...
...
@@ -25,14 +25,74 @@
namespace
flatbuffers
{
namespace
php
{
// Hardcode spaces per indentation.
const
std
::
string
Indent
=
" "
;
class
PhpGenerator
:
public
BaseGenerator
{
public
:
PhpGenerator
(
const
Parser
&
parser
,
const
std
::
string
&
path
,
const
std
::
string
&
file_name
)
:
BaseGenerator
(
parser
,
path
,
file_name
){};
bool
generate
()
{
if
(
!
generateEnums
())
return
false
;
if
(
!
generateStructs
())
return
false
;
return
true
;
}
private
:
bool
generateEnums
()
{
for
(
auto
it
=
parser_
.
enums_
.
vec
.
begin
();
it
!=
parser_
.
enums_
.
vec
.
end
();
++
it
)
{
auto
&
enum_def
=
**
it
;
std
::
string
enumcode
;
GenEnum
(
enum_def
,
&
enumcode
);
if
(
!
SaveType
(
enum_def
,
enumcode
,
false
))
return
false
;
}
return
true
;
}
bool
generateStructs
()
{
for
(
auto
it
=
parser_
.
structs_
.
vec
.
begin
();
it
!=
parser_
.
structs_
.
vec
.
end
();
++
it
)
{
auto
&
struct_def
=
**
it
;
std
::
string
declcode
;
GenStruct
(
parser_
,
struct_def
,
&
declcode
);
if
(
!
SaveType
(
struct_def
,
declcode
,
true
))
return
false
;
}
return
true
;
}
// Begin by declaring namespace and imports.
void
BeginFile
(
const
std
::
string
name_space_name
,
const
bool
needs_imports
,
std
::
string
*
code_ptr
)
{
std
::
string
&
code
=
*
code_ptr
;
code
+=
"<?php
\n
"
;
code
=
code
+
"// "
+
FlatBuffersGeneratedWarning
();
code
+=
"namespace "
+
name_space_name
+
";
\n\n
"
;
if
(
needs_imports
)
{
code
+=
"use
\\
Google
\\
FlatBuffers
\\
Struct;
\n
"
;
code
+=
"use
\\
Google
\\
FlatBuffers
\\
Table;
\n
"
;
code
+=
"use
\\
Google
\\
FlatBuffers
\\
ByteBuffer;
\n
"
;
code
+=
"use
\\
Google
\\
FlatBuffers
\\
FlatBufferBuilder;
\n
"
;
code
+=
"
\n
"
;
}
}
// Save out the generated code for a Php Table type.
bool
SaveType
(
const
Definition
&
def
,
const
std
::
string
&
classcode
,
bool
needs_imports
)
{
if
(
!
classcode
.
length
())
return
true
;
std
::
string
code
=
""
;
BeginFile
(
FullNamespace
(
"
\\
"
,
*
def
.
defined_namespace
),
needs_imports
,
&
code
);
code
+=
classcode
;
std
::
string
filename
=
NamespaceDir
(
*
def
.
defined_namespace
)
+
kPathSeparator
+
def
.
name
+
".php"
;
return
SaveFile
(
filename
.
c_str
(),
code
,
false
);
}
static
std
::
string
GenGetter
(
const
Type
&
type
);
static
std
::
string
GenDefaultValue
(
const
Value
&
value
);
static
std
::
string
GenMethod
(
const
FieldDef
&
field
);
static
void
GenStructBuilder
(
const
StructDef
&
struct_def
,
std
::
string
*
code_ptr
);
static
std
::
string
GenTypeBasic
(
const
Type
&
type
);
static
std
::
string
GenTypeGet
(
const
Type
&
type
);
// Ensure that a type is prefixed with its namespace whenever it is used
// outside of its namespace.
...
...
@@ -51,9 +111,6 @@ namespace php {
}
// Hardcode spaces per indentation.
const
std
::
string
Indent
=
" "
;
// Begin a class declaration.
static
void
BeginClass
(
const
StructDef
&
struct_def
,
std
::
string
*
code_ptr
)
{
std
::
string
&
code
=
*
code_ptr
;
...
...
@@ -928,71 +985,6 @@ namespace php {
code
+=
Indent
+
"}
\n
"
;
}
class
PhpGenerator
:
public
BaseGenerator
{
public
:
PhpGenerator
(
const
Parser
&
parser
,
const
std
::
string
&
path
,
const
std
::
string
&
file_name
)
:
BaseGenerator
(
parser
,
path
,
file_name
){};
bool
generate
()
{
if
(
!
generateEnums
())
return
false
;
if
(
!
generateStructs
())
return
false
;
return
true
;
}
private
:
bool
generateEnums
()
{
for
(
auto
it
=
parser_
.
enums_
.
vec
.
begin
();
it
!=
parser_
.
enums_
.
vec
.
end
();
++
it
)
{
auto
&
enum_def
=
**
it
;
std
::
string
enumcode
;
GenEnum
(
enum_def
,
&
enumcode
);
if
(
!
SaveType
(
enum_def
,
enumcode
,
false
))
return
false
;
}
return
true
;
}
bool
generateStructs
()
{
for
(
auto
it
=
parser_
.
structs_
.
vec
.
begin
();
it
!=
parser_
.
structs_
.
vec
.
end
();
++
it
)
{
auto
&
struct_def
=
**
it
;
std
::
string
declcode
;
GenStruct
(
parser_
,
struct_def
,
&
declcode
);
if
(
!
SaveType
(
struct_def
,
declcode
,
true
))
return
false
;
}
return
true
;
}
// Begin by declaring namespace and imports.
void
BeginFile
(
const
std
::
string
name_space_name
,
const
bool
needs_imports
,
std
::
string
*
code_ptr
)
{
std
::
string
&
code
=
*
code_ptr
;
code
+=
"<?php
\n
"
;
code
=
code
+
"// "
+
FlatBuffersGeneratedWarning
();
code
+=
"namespace "
+
name_space_name
+
";
\n\n
"
;
if
(
needs_imports
)
{
code
+=
"use
\\
Google
\\
FlatBuffers
\\
Struct;
\n
"
;
code
+=
"use
\\
Google
\\
FlatBuffers
\\
Table;
\n
"
;
code
+=
"use
\\
Google
\\
FlatBuffers
\\
ByteBuffer;
\n
"
;
code
+=
"use
\\
Google
\\
FlatBuffers
\\
FlatBufferBuilder;
\n
"
;
code
+=
"
\n
"
;
}
}
// Save out the generated code for a Php Table type.
bool
SaveType
(
const
Definition
&
def
,
const
std
::
string
&
classcode
,
bool
needs_imports
)
{
if
(
!
classcode
.
length
())
return
true
;
std
::
string
code
=
""
;
BeginFile
(
FullNamespace
(
"
\\
"
,
*
def
.
defined_namespace
),
needs_imports
,
&
code
);
code
+=
classcode
;
std
::
string
filename
=
NamespaceDir
(
*
def
.
defined_namespace
)
+
kPathSeparator
+
def
.
name
+
".php"
;
return
SaveFile
(
filename
.
c_str
(),
code
,
false
);
}
};
}
// namespace php
...
...
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