"class " << php_namespace(tstruct->get_program()) << tstruct->get_name();
if (is_exception) {
out << " extends TException";
- } else {
+ } else if (oop_) {
out << " extends TBase";
}
out <<
" {" << endl;
indent_up();
- indent(out) << "static $_TSPEC;" << endl << endl;
+ if (oop_) {
+ indent(out) << "static $_TSPEC;" << endl << endl;
+ }
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
string dval = "null";
out << endl;
// Generate constructor from array
- string param = (members.size() > 0) ? "$vals=null" : "";
- out <<
- indent() << "public function __construct(" << param << ") {" << endl;
- indent_up();
+ if (oop_ || members.size() > 0) {
+ string param = (members.size() > 0) ? "$vals=null" : "";
+ out <<
+ indent() << "public function __construct(" << param << ") {" << endl;
+ indent_up();
- generate_php_struct_spec(out, tstruct);
+ if (oop_) {
+ generate_php_struct_spec(out, tstruct);
+ }
- if (members.size() > 0) {
- for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
- t_type* t = get_true_type((*m_iter)->get_type());
- if ((*m_iter)->get_value() != NULL && (t->is_struct() || t->is_xception())) {
- indent(out) << "$this->" << (*m_iter)->get_name() << " = " << render_const_value(t, (*m_iter)->get_value()) << ";" << endl;
+ if (members.size() > 0) {
+ for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
+ t_type* t = get_true_type((*m_iter)->get_type());
+ if ((*m_iter)->get_value() != NULL && (t->is_struct() || t->is_xception())) {
+ indent(out) << "$this->" << (*m_iter)->get_name() << " = " << render_const_value(t, (*m_iter)->get_value()) << ";" << endl;
+ }
}
+ out <<
+ indent() << "if (is_array($vals)) {" << endl <<
+ indent() << " parent::__construct(self::$_TSPEC, $vals);" << endl <<
+ indent() << "}" << endl;
}
- out <<
- indent() << "if (is_array($vals)) {" << endl <<
- indent() << " parent::__construct(self::$_TSPEC, $vals);" << endl <<
- indent() << "}" << endl;
+ scope_down(out);
+ out << endl;
}
- scope_down(out);
- out << endl;
out <<
indent() << "public function getName() {" << endl <<
"public function read($input)" << endl;
scope_up(out);
- // TODO(mcslee): Testing this new jonx!
- indent(out) << "return $this->_read('" << tstruct->get_name() << "', self::$_TSPEC, $input);" << endl;
- scope_down(out);
- return;
+ if (oop_) {
+ indent(out) << "return $this->_read('" << tstruct->get_name() << "', self::$_TSPEC, $input);" << endl;
+ scope_down(out);
+ return;
+ }
out <<
indent() << "$xfer = 0;" << endl <<
}
indent_up();
- // TODO(mcslee): Testing this new j0nx
- indent(out) << "return $this->_write('" << tstruct->get_name() << "', self::$_TSPEC, $output);" << endl;
- scope_down(out);
- return;
+ if (oop_) {
+ indent(out) << "return $this->_write('" << tstruct->get_name() << "', self::$_TSPEC, $output);" << endl;
+ scope_down(out);
+ return;
+ }
indent(out) <<
"$xfer = 0;" << endl;
bool gen_phpi = false;
bool gen_phps = true;
bool gen_phpa = false;
+bool gen_phpo = false;
bool gen_rest = false;
bool gen_perl = false;
bool gen_erl = false;
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, " -py Generate Python output files\n");
fprintf(stderr, " -rb Generate Ruby output files\n");
fprintf(stderr, " -xsd Generate XSD output files\n");
if (gen_php) {
pverbose("Generating PHP\n");
- t_php_generator* php = new t_php_generator(program, false, gen_rest, gen_phps, gen_phpa);
+ t_php_generator* php = new t_php_generator(program, false, gen_rest, gen_phps, gen_phpa, gen_phpo);
php->generate_program();
delete php;
}
gen_phps = false;
}
gen_phpa = true;
+ } else if (strcmp(arg, "-phpo") == 0) {
+ if (!gen_php) {
+ gen_php = true;
+ }
+ gen_phpo = true;
} else if (strcmp(arg, "-rest") == 0) {
gen_rest = true;
} else if (strcmp(arg, "-py") == 0) {