1 // Copyright (c) 2006- Facebook
2 // Distributed under the Thrift Software License
4 // See accompanying file LICENSE or visit the Thrift site at:
5 // http://developers.facebook.com/thrift/
7 #ifndef T_PHP_GENERATOR_H
8 #define T_PHP_GENERATOR_H
15 #include "t_oop_generator.h"
20 * @author Mark Slee <mcslee@facebook.com>
22 class t_php_generator
: public t_oop_generator
{
24 t_php_generator(t_program
* program
,
25 bool binary_inline
=false,
28 bool autoload
=false) :
29 t_oop_generator(program
),
30 binary_inline_(binary_inline
),
34 out_dir_base_
= (binary_inline_
? "gen-phpi" : "gen-php");
38 * Init and close methods
41 void init_generator();
42 void close_generator();
45 * Program-level generation functions
48 void generate_typedef (t_typedef
* ttypedef
);
49 void generate_enum (t_enum
* tenum
);
50 void generate_const (t_const
* tconst
);
51 void generate_struct (t_struct
* tstruct
);
52 void generate_xception (t_struct
* txception
);
53 void generate_service (t_service
* tservice
);
55 std::string
render_const_value(t_type
* type
, t_const_value
* value
);
61 void generate_php_struct(t_struct
* tstruct
, bool is_exception
);
62 void generate_php_struct_definition(std::ofstream
& out
, t_struct
* tstruct
, bool is_xception
=false);
63 void _generate_php_struct_definition(std::ofstream
& out
, t_struct
* tstruct
, bool is_xception
=false);
64 void generate_php_struct_reader(std::ofstream
& out
, t_struct
* tstruct
);
65 void generate_php_struct_writer(std::ofstream
& out
, t_struct
* tstruct
);
66 void generate_php_function_helpers(t_function
* tfunction
);
68 void generate_php_type_spec(std::ofstream
&out
, t_type
* t
);
69 void generate_php_struct_spec(std::ofstream
&out
, t_struct
* tstruct
);
72 * Service-level generation functions
75 void generate_service_helpers (t_service
* tservice
);
76 void generate_service_interface (t_service
* tservice
);
77 void generate_service_rest (t_service
* tservice
);
78 void generate_service_client (t_service
* tservice
);
79 void _generate_service_client (std::ofstream
&out
, t_service
* tservice
);
80 void generate_service_processor (t_service
* tservice
);
81 void generate_process_function (t_service
* tservice
, t_function
* tfunction
);
84 * Serialization constructs
87 void generate_deserialize_field (std::ofstream
&out
,
89 std::string prefix
="",
92 void generate_deserialize_struct (std::ofstream
&out
,
94 std::string prefix
="");
96 void generate_deserialize_container (std::ofstream
&out
,
98 std::string prefix
="");
100 void generate_deserialize_set_element (std::ofstream
&out
,
102 std::string prefix
="");
104 void generate_deserialize_map_element (std::ofstream
&out
,
106 std::string prefix
="");
108 void generate_deserialize_list_element (std::ofstream
&out
,
110 std::string prefix
="");
112 void generate_serialize_field (std::ofstream
&out
,
114 std::string prefix
="");
116 void generate_serialize_struct (std::ofstream
&out
,
118 std::string prefix
="");
120 void generate_serialize_container (std::ofstream
&out
,
122 std::string prefix
="");
124 void generate_serialize_map_element (std::ofstream
&out
,
129 void generate_serialize_set_element (std::ofstream
&out
,
133 void generate_serialize_list_element (std::ofstream
&out
,
138 * Helper rendering functions
141 std::string
php_includes();
142 std::string
declare_field(t_field
* tfield
, bool init
=false, bool obj
=false);
143 std::string
function_signature(t_function
* tfunction
, std::string prefix
="");
144 std::string
argument_list(t_struct
* tstruct
);
145 std::string
type_to_cast(t_type
* ttype
);
146 std::string
type_to_enum(t_type
* ttype
);
148 std::string
php_namespace(t_program
* p
) {
149 std::string ns
= p
->get_php_namespace();
150 return ns
.size() ? (ns
+ "_") : "";
158 std::ofstream f_types_
;
159 std::ofstream f_consts_
;
160 std::ofstream f_helpers_
;
161 std::ofstream f_service_
;
164 * Generate protocol-independent template? Or Binary inline code?
169 * Generate a REST handler class
174 * Generate stubs for a PHP server
179 * Generate PHP code that uses autoload