From 2a816c28ae166f267e3a681ba335b298d542b1f1 Mon Sep 17 00:00:00 2001 From: Roger Meier Date: Fri, 7 Feb 2014 01:15:23 +0100 Subject: [PATCH] THRIFT-2348 PHP Generator: add array typehint to functions Patch: Maurus Cuelenaere --- compiler/cpp/src/generate/t_php_generator.cc | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/compiler/cpp/src/generate/t_php_generator.cc b/compiler/cpp/src/generate/t_php_generator.cc index 0f487583..124039b3 100644 --- a/compiler/cpp/src/generate/t_php_generator.cc +++ b/compiler/cpp/src/generate/t_php_generator.cc @@ -205,7 +205,7 @@ class t_php_generator : public t_oop_generator { std::string php_includes(); std::string declare_field(t_field* tfield, bool init=false, bool obj=false); std::string function_signature(t_function* tfunction, std::string prefix=""); - std::string argument_list(t_struct* tstruct, bool addStructSignature = true); + std::string argument_list(t_struct* tstruct, bool addTypeHints = true); std::string type_to_cast(t_type* ttype); std::string type_to_enum(t_type* ttype); std::string type_to_phpdoc(t_type* ttype); @@ -2374,7 +2374,7 @@ string t_php_generator::function_signature(t_function* tfunction, /** * Renders a field list */ -string t_php_generator::argument_list(t_struct* tstruct, bool addStructSignature) { +string t_php_generator::argument_list(t_struct* tstruct, bool addTypeHints) { string result = ""; const vector& fields = tstruct->get_members(); @@ -2390,11 +2390,18 @@ string t_php_generator::argument_list(t_struct* tstruct, bool addStructSignature t_type* type = (*f_iter)->get_type(); //Set type name - if(addStructSignature && type->is_struct()) + if (addTypeHints) { - string className = php_namespace(type->get_program()) + php_namespace_directory("Definition", false) + classify(type->get_name()); + if (type->is_struct()) + { + string className = php_namespace(type->get_program()) + php_namespace_directory("Definition", false) + classify(type->get_name()); - result += className + " "; + result += className + " "; + } + else if (type->is_container()) + { + result += "array "; + } } result += "$" + (*f_iter)->get_name(); -- 2.17.1