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,
30 t_oop_generator(program
),
31 binary_inline_(binary_inline
),
36 out_dir_base_
= (binary_inline_
? "gen-phpi" : "gen-php");
40 * Init and close methods
43 void init_generator();
44 void close_generator();
47 * Program-level generation functions
50 void generate_typedef (t_typedef
* ttypedef
);
51 void generate_enum (t_enum
* tenum
);
52 void generate_const (t_const
* tconst
);
53 void generate_struct (t_struct
* tstruct
);
54 void generate_xception (t_struct
* txception
);
55 void generate_service (t_service
* tservice
);
57 std::string
render_const_value(t_type
* type
, t_const_value
* value
);
63 void generate_php_struct(t_struct
* tstruct
, bool is_exception
);
64 void generate_php_struct_definition(std::ofstream
& out
, t_struct
* tstruct
, bool is_xception
=false);
65 void _generate_php_struct_definition(std::ofstream
& out
, t_struct
* tstruct
, bool is_xception
=false);
66 void generate_php_struct_reader(std::ofstream
& out
, t_struct
* tstruct
);
67 void generate_php_struct_writer(std::ofstream
& out
, t_struct
* tstruct
);
68 void generate_php_function_helpers(t_function
* tfunction
);
70 void generate_php_type_spec(std::ofstream
&out
, t_type
* t
);
71 void generate_php_struct_spec(std::ofstream
&out
, t_struct
* tstruct
);
74 * Service-level generation functions
77 void generate_service_helpers (t_service
* tservice
);
78 void generate_service_interface (t_service
* tservice
);
79 void generate_service_rest (t_service
* tservice
);
80 void generate_service_client (t_service
* tservice
);
81 void _generate_service_client (std::ofstream
&out
, t_service
* tservice
);
82 void generate_service_processor (t_service
* tservice
);
83 void generate_process_function (t_service
* tservice
, t_function
* tfunction
);
86 * Serialization constructs
89 void generate_deserialize_field (std::ofstream
&out
,
91 std::string prefix
="",
94 void generate_deserialize_struct (std::ofstream
&out
,
96 std::string prefix
="");
98 void generate_deserialize_container (std::ofstream
&out
,
100 std::string prefix
="");
102 void generate_deserialize_set_element (std::ofstream
&out
,
104 std::string prefix
="");
106 void generate_deserialize_map_element (std::ofstream
&out
,
108 std::string prefix
="");
110 void generate_deserialize_list_element (std::ofstream
&out
,
112 std::string prefix
="");
114 void generate_serialize_field (std::ofstream
&out
,
116 std::string prefix
="");
118 void generate_serialize_struct (std::ofstream
&out
,
120 std::string prefix
="");
122 void generate_serialize_container (std::ofstream
&out
,
124 std::string prefix
="");
126 void generate_serialize_map_element (std::ofstream
&out
,
131 void generate_serialize_set_element (std::ofstream
&out
,
135 void generate_serialize_list_element (std::ofstream
&out
,
140 * Helper rendering functions
143 std::string
php_includes();
144 std::string
declare_field(t_field
* tfield
, bool init
=false, bool obj
=false);
145 std::string
function_signature(t_function
* tfunction
, std::string prefix
="");
146 std::string
argument_list(t_struct
* tstruct
);
147 std::string
type_to_cast(t_type
* ttype
);
148 std::string
type_to_enum(t_type
* ttype
);
150 std::string
php_namespace(t_program
* p
) {
151 std::string ns
= p
->get_php_namespace();
152 return ns
.size() ? (ns
+ "_") : "";
160 std::ofstream f_types_
;
161 std::ofstream f_consts_
;
162 std::ofstream f_helpers_
;
163 std::ofstream f_service_
;
166 * Generate protocol-independent template? Or Binary inline code?
171 * Generate a REST handler class
176 * Generate stubs for a PHP server
181 * Generate PHP code that uses autoload
186 * Whether to use OOP base class TBase