diff options
author | Khanh Nguyen <44149581+Kn99HN@users.noreply.github.com> | 2023-01-25 09:05:48 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-25 09:05:48 -0800 |
commit | 34c821f4adbc97723f27998b20e1c86fbf4f5937 (patch) | |
tree | d0a46df3127f053101486183f208cb3fbd75fa2f /src/idl_gen_php.cpp | |
parent | 802a3a056a66f6d744d03739341918486e1de612 (diff) | |
download | flatbuffers-34c821f4adbc97723f27998b20e1c86fbf4f5937.tar.gz flatbuffers-34c821f4adbc97723f27998b20e1c86fbf4f5937.tar.bz2 flatbuffers-34c821f4adbc97723f27998b20e1c86fbf4f5937.zip |
Refactor languages to use CodeGenerator interface. (#7797)
* Refactor to use CodeGenerator interface.
- Move code to its own header file to be included in flatc_main.cpp
- Refactor code to use CodeGenerator interface for all languages
* Format all files
* remove lua code generator since it doesn't support bfbs generator
* Update CMakeLists file with new idl_gen_*.cpp and idl_gen_*.h files
* Add idl_gen_swift header file
* Add idl_gen_swift header file and update bazel file
* Remove CodeGenerator interface for idl_gen_text.*. Remove comments and extern declaration
* Reorder header and implementation files in CMakeLists.txt
* Add idl_gen_* header files to implementation files
* Update CMakeLists and remove unused import
Co-authored-by: Derek Bailey <derekbailey@google.com>
Diffstat (limited to 'src/idl_gen_php.cpp')
-rw-r--r-- | src/idl_gen_php.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/idl_gen_php.cpp b/src/idl_gen_php.cpp index 5896935e..ba8c1633 100644 --- a/src/idl_gen_php.cpp +++ b/src/idl_gen_php.cpp @@ -16,6 +16,8 @@ // independent from idl_parser, since this code is not needed for most clients +#include "idl_gen_php.h" + #include <string> #include "flatbuffers/code_generators.h" @@ -942,4 +944,53 @@ bool GeneratePhp(const Parser &parser, const std::string &path, php::PhpGenerator generator(parser, path, file_name); return generator.generate(); } + +namespace { + +class PhpCodeGenerator : public CodeGenerator { + public: + Status GenerateCode(const Parser &parser, const std::string &path, + const std::string &filename) override { + if (!GeneratePhp(parser, path, filename)) { return Status::ERROR; } + return Status::OK; + } + + Status GenerateCode(const uint8_t *buffer, int64_t length) override { + (void)buffer; + (void)length; + return Status::NOT_IMPLEMENTED; + } + + Status GenerateMakeRule(const Parser &parser, const std::string &path, + const std::string &filename, + std::string &output) override { + (void)parser; + (void)path; + (void)filename; + (void)output; + return Status::NOT_IMPLEMENTED; + } + + Status GenerateGrpcCode(const Parser &parser, const std::string &path, + const std::string &filename) override { + (void)parser; + (void)path; + (void)filename; + return Status::NOT_IMPLEMENTED; + } + + bool IsSchemaOnly() const override { return true; } + + bool SupportsBfbsGeneration() const override { return false; } + + IDLOptions::Language Language() const override { return IDLOptions::kPhp; } + + std::string LanguageName() const override { return "Php"; } +}; +} // namespace + +std::unique_ptr<CodeGenerator> NewPhpCodeGenerator() { + return std::unique_ptr<PhpCodeGenerator>(new PhpCodeGenerator()); +} + } // namespace flatbuffers |