mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-05 21:17:25 +00:00
sharing the Flatbuffers warning
This commit is contained in:
@@ -54,24 +54,6 @@ namespace php {
|
||||
// Hardcode spaces per indentation.
|
||||
const std::string Indent = " ";
|
||||
|
||||
// Begin by declaring namespace and imports.
|
||||
static 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 += "// automatically generated, do not modify\n\n";
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
||||
// Begin a class declaration.
|
||||
static void BeginClass(const StructDef &struct_def, std::string *code_ptr) {
|
||||
std::string &code = *code_ptr;
|
||||
@@ -867,35 +849,6 @@ namespace php {
|
||||
: (IsStruct(field.value.type) ? "Struct" : "Offset");
|
||||
}
|
||||
|
||||
|
||||
// Save out the generated code for a Php Table type.
|
||||
static bool SaveType(const Parser &parser, const Definition &def,
|
||||
const std::string &classcode, const std::string &path,
|
||||
bool needs_imports) {
|
||||
if (!classcode.length()) return true;
|
||||
|
||||
std::string namespace_name;
|
||||
std::string namespace_dir = path;
|
||||
|
||||
auto &namespaces = parser.namespaces_.back()->components;
|
||||
for (auto it = namespaces.begin(); it != namespaces.end(); ++it) {
|
||||
if (namespace_name.length()) {
|
||||
namespace_name += "\\";
|
||||
namespace_dir += kPathSeparator;
|
||||
}
|
||||
namespace_name += *it;
|
||||
namespace_dir += *it;
|
||||
EnsureDirExists(namespace_dir.c_str());
|
||||
}
|
||||
|
||||
std::string code = "";
|
||||
BeginFile(namespace_name, needs_imports, &code);
|
||||
code += classcode;
|
||||
|
||||
std::string filename = namespace_dir + kPathSeparator + def.name + ".php";
|
||||
return SaveFile(filename.c_str(), code, false);
|
||||
}
|
||||
|
||||
static std::string GenTypeBasic(const Type &type) {
|
||||
static const char *ctypename[] = {
|
||||
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE, PTYPE) \
|
||||
@@ -993,8 +946,7 @@ namespace php {
|
||||
auto &enum_def = **it;
|
||||
std::string enumcode;
|
||||
GenEnum(enum_def, &enumcode);
|
||||
if (!SaveType(parser_, enum_def, enumcode, path_, false))
|
||||
return false;
|
||||
if (!SaveType(enum_def, enumcode, false)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1005,11 +957,55 @@ namespace php {
|
||||
auto &struct_def = **it;
|
||||
std::string declcode;
|
||||
GenStruct(parser_, struct_def, &declcode);
|
||||
if (!SaveType(parser_, struct_def, declcode, path_, true))
|
||||
return false;
|
||||
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 namespace_name;
|
||||
std::string namespace_dir = path_;
|
||||
|
||||
auto &namespaces = parser_.namespaces_.back()->components;
|
||||
for (auto it = namespaces.begin(); it != namespaces.end(); ++it) {
|
||||
if (namespace_name.length()) {
|
||||
namespace_name += "\\";
|
||||
namespace_dir += kPathSeparator;
|
||||
}
|
||||
namespace_name += *it;
|
||||
namespace_dir += *it;
|
||||
EnsureDirExists(namespace_dir.c_str());
|
||||
}
|
||||
|
||||
std::string code = "";
|
||||
BeginFile(namespace_name, needs_imports, &code);
|
||||
code += classcode;
|
||||
|
||||
std::string filename =
|
||||
namespace_dir + kPathSeparator + def.name + ".php";
|
||||
return SaveFile(filename.c_str(), code, false);
|
||||
}
|
||||
};
|
||||
} // namespace php
|
||||
|
||||
|
||||
Reference in New Issue
Block a user