mirror of
https://github.com/valitydev/thrift.git
synced 2024-11-07 02:45:22 +00:00
All thrift PHP class constructors can take an array as the constructor argument
Summary: It will init any field with the value in the array. Hot for converting DB rows into thrift objs. git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664871 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
52cb2234de
commit
19e71c34b1
@ -158,6 +158,27 @@ void t_php_generator::generate_php_struct_definition(ofstream& out,
|
||||
|
||||
out << endl;
|
||||
|
||||
out <<
|
||||
indent() << "public function __construct($vals=null) {" << endl;
|
||||
indent_up();
|
||||
out <<
|
||||
indent() << "if (is_array($vals)) {" << endl;
|
||||
indent_up();
|
||||
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
|
||||
out <<
|
||||
indent() << "if (isset($vals['" << (*m_iter)->get_name() << "'])) {" << endl <<
|
||||
indent() << " $this->" << (*m_iter)->get_name() << " = $vals['" << (*m_iter)->get_name() << "'];" << endl <<
|
||||
indent() << "}" << endl;
|
||||
}
|
||||
indent_down();
|
||||
out <<
|
||||
indent() << "}" << endl;
|
||||
|
||||
indent_down();
|
||||
out <<
|
||||
indent() << "}" << endl <<
|
||||
endl;
|
||||
|
||||
generate_php_struct_reader(out, tstruct);
|
||||
generate_php_struct_writer(out, tstruct);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user