Make the PHP generator dynamic.
- Modify the PHP generator constructor to fit the new generic interface.
- Register the PHP genrator with the central registry.
- Deprecate the old way of invoking the PHP generator.
- main.cc no longer includes t_php_generator.h.
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@745238 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/generate/t_php_generator.cc b/compiler/cpp/src/generate/t_php_generator.cc
index 0fd0f89..42e15ef 100644
--- a/compiler/cpp/src/generate/t_php_generator.cc
+++ b/compiler/cpp/src/generate/t_php_generator.cc
@@ -2061,3 +2061,11 @@
throw "INVALID TYPE IN type_to_enum: " + type->get_name();
}
+
+THRIFT_REGISTER_GENERATOR(php, "PHP",
+" inlined: Generate PHP inlined files\n"
+" server: Generate PHP server stubs\n"
+" autoload: Generate PHP with autoload\n"
+" oop: Generate PHP with object oriented subclasses\n"
+" rest: Generate PHP REST processors\n"
+);
diff --git a/compiler/cpp/src/generate/t_php_generator.h b/compiler/cpp/src/generate/t_php_generator.h
index be2ca60..cf26737 100644
--- a/compiler/cpp/src/generate/t_php_generator.h
+++ b/compiler/cpp/src/generate/t_php_generator.h
@@ -21,18 +21,33 @@
*/
class t_php_generator : public t_oop_generator {
public:
- t_php_generator(t_program* program,
- bool binary_inline=false,
- bool rest=false,
- bool phps=false,
- bool autoload=false,
- bool oop=false) :
- t_oop_generator(program),
- binary_inline_(binary_inline),
- rest_(rest),
- phps_(phps),
- autoload_(autoload),
- oop_(oop) {
+ t_php_generator(
+ t_program* program,
+ const std::map<std::string, std::string>& parsed_options,
+ const std::string& option_string)
+ : t_oop_generator(program)
+ {
+ std::map<std::string, std::string>::const_iterator iter;
+
+ iter = parsed_options.find("inlined");
+ binary_inline_ = (iter != parsed_options.end());
+
+ iter = parsed_options.find("rest");
+ rest_ = (iter != parsed_options.end());
+
+ iter = parsed_options.find("server");
+ phps_ = (iter != parsed_options.end());
+
+ iter = parsed_options.find("autoload");
+ autoload_ = (iter != parsed_options.end());
+
+ iter = parsed_options.find("oop");
+ oop_ = (iter != parsed_options.end());
+
+ if (oop_ && binary_inline_) {
+ throw "oop and inlined are mutually exclusive.";
+ }
+
out_dir_base_ = (binary_inline_ ? "gen-phpi" : "gen-php");
}
diff --git a/compiler/cpp/src/main.cc b/compiler/cpp/src/main.cc
index 88d9bc4..0e31bd9 100644
--- a/compiler/cpp/src/main.cc
+++ b/compiler/cpp/src/main.cc
@@ -37,7 +37,6 @@
#include "parse/t_program.h"
#include "parse/t_scope.h"
#include "generate/t_generator.h"
-#include "generate/t_php_generator.h"
#include "version.h"
@@ -603,17 +602,10 @@
fprintf(stderr, "Usage: thrift [options] file\n");
fprintf(stderr, "Options:\n");
fprintf(stderr, " -version Print the compiler version\n");
- fprintf(stderr, " -php Generate PHP output files\n");
- fprintf(stderr, " -phpi Generate PHP inlined files\n");
- fprintf(stderr, " -phps Generate PHP server stubs (with -php)\n");
- fprintf(stderr, " -phpl Generate PHP-lite (with -php)\n");
- fprintf(stderr, " -phpa Generate PHP with autoload (with -php)\n");
- fprintf(stderr, " -phpo Generate PHP with object oriented subclasses (with -php)\n");
fprintf(stderr, " -o dir Set the output directory for gen-* packages\n");
fprintf(stderr, " (default: current directory)\n");
fprintf(stderr, " -I dir Add a directory to the list of directories\n");
fprintf(stderr, " searched for include directives\n");
- fprintf(stderr, " -rest Generate PHP REST processors (with -php)\n");
fprintf(stderr, " -nowarn Suppress all compiler warnings (BAD!)\n");
fprintf(stderr, " -strict Strict compiler warnings on\n");
fprintf(stderr, " -v[erbose] Verbose mode\n");
@@ -857,20 +849,6 @@
// Compute fingerprints.
generate_all_fingerprints(program);
- if (gen_php) {
- pverbose("Generating PHP\n");
- t_php_generator* php = new t_php_generator(program, false, gen_rest, gen_phps, gen_phpa, gen_phpo);
- php->generate_program();
- delete php;
- }
-
- if (gen_phpi) {
- pverbose("Generating PHP-inline\n");
- t_php_generator* phpi = new t_php_generator(program, true, gen_rest);
- phpi->generate_program();
- delete phpi;
- }
-
if (dump_docs) {
dump_docstrings(program);
}
@@ -1089,6 +1067,22 @@
pwarning(1, "-perl is deprecated. Use --gen perl");
generator_strings.push_back("perl");
}
+ if (gen_php || gen_phpi) {
+ pwarning(1, "-php is deprecated. Use --gen php");
+ string gen_string = "php:";
+ if (gen_phpi) {
+ gen_string.append("inlined,");
+ } else if(gen_phps) {
+ gen_string.append("server,");
+ } else if(gen_phpa) {
+ gen_string.append("autoload,");
+ } else if(gen_phpo) {
+ gen_string.append("oop,");
+ } else if(gen_rest) {
+ gen_string.append("rest,");
+ }
+ generator_strings.push_back(gen_string);
+ }
if (gen_cocoa) {
pwarning(1, "-cocoa is deprecated. Use --gen cocoa");
generator_strings.push_back("cocoa");
@@ -1115,7 +1109,7 @@
}
// You gotta generate something!
- if (!gen_php && !gen_phpi && generator_strings.empty()) {
+ if (generator_strings.empty()) {
fprintf(stderr, "!!! No output language(s) specified\n\n");
usage();
}
diff --git a/lib/php/src/autoload.php b/lib/php/src/autoload.php
index dc6133c..d0b4c63 100644
--- a/lib/php/src/autoload.php
+++ b/lib/php/src/autoload.php
@@ -20,7 +20,7 @@
* __autoload function to something else and then do:
* $GLOBALS['AUTOLOAD_HOOKS'][] = 'my_autoload_func';
*
- * Generate this code using the -phpa Thrift generator flag.
+ * Generate this code using the --gen php:autoload Thrift generator flag.
*/
$GLOBALS['THRIFT_AUTOLOAD'] = array();