You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by dr...@apache.org on 2009/02/17 21:28:24 UTC

svn commit: r745238 - in /incubator/thrift/trunk: compiler/cpp/src/generate/t_php_generator.cc compiler/cpp/src/generate/t_php_generator.h compiler/cpp/src/main.cc lib/php/src/autoload.php

Author: dreiss
Date: Tue Feb 17 20:28:24 2009
New Revision: 745238

URL: http://svn.apache.org/viewvc?rev=745238&view=rev
Log:
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.

Modified:
    incubator/thrift/trunk/compiler/cpp/src/generate/t_php_generator.cc
    incubator/thrift/trunk/compiler/cpp/src/generate/t_php_generator.h
    incubator/thrift/trunk/compiler/cpp/src/main.cc
    incubator/thrift/trunk/lib/php/src/autoload.php

Modified: incubator/thrift/trunk/compiler/cpp/src/generate/t_php_generator.cc
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/compiler/cpp/src/generate/t_php_generator.cc?rev=745238&r1=745237&r2=745238&view=diff
==============================================================================
--- incubator/thrift/trunk/compiler/cpp/src/generate/t_php_generator.cc (original)
+++ incubator/thrift/trunk/compiler/cpp/src/generate/t_php_generator.cc Tue Feb 17 20:28:24 2009
@@ -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"
+);

Modified: incubator/thrift/trunk/compiler/cpp/src/generate/t_php_generator.h
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/compiler/cpp/src/generate/t_php_generator.h?rev=745238&r1=745237&r2=745238&view=diff
==============================================================================
--- incubator/thrift/trunk/compiler/cpp/src/generate/t_php_generator.h (original)
+++ incubator/thrift/trunk/compiler/cpp/src/generate/t_php_generator.h Tue Feb 17 20:28:24 2009
@@ -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");
   }
 

Modified: incubator/thrift/trunk/compiler/cpp/src/main.cc
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/compiler/cpp/src/main.cc?rev=745238&r1=745237&r2=745238&view=diff
==============================================================================
--- incubator/thrift/trunk/compiler/cpp/src/main.cc (original)
+++ incubator/thrift/trunk/compiler/cpp/src/main.cc Tue Feb 17 20:28:24 2009
@@ -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();
   }

Modified: incubator/thrift/trunk/lib/php/src/autoload.php
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/php/src/autoload.php?rev=745238&r1=745237&r2=745238&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/php/src/autoload.php (original)
+++ incubator/thrift/trunk/lib/php/src/autoload.php Tue Feb 17 20:28:24 2009
@@ -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();