PhpFunc::PhpFunc(const folly::dynamic& d, const fbstring& className) : m_name(d["name"].asString()), m_className(className), m_func(d), m_desc(getFollyDynamicDefaultString(d, "desc", "")), m_returnRef(d.getDefault("ref", "false") == "true"), m_returnKindOf(KindOfNull), m_returnCppType("void"), m_returnPhpType("void"), m_minNumParams(0), m_numTypeChecks(0) { auto returnIt = d.find("return"); if (returnIt != d.items().end()) { auto retNode = returnIt->second; auto typeIt = retNode.find("type"); if (typeIt != retNode.items().end()) { auto type = typeIt->second; if ((type.isString()) && (type != "void") && (type != "null")) { m_returnKindOf = m_returnRef ? KindOfRef : kindOfFromDynamic(type); m_returnCppType = typeString(type, true); m_returnPhpType = phpTypeFromDataType(m_returnKindOf); } } m_returnDesc = getFollyDynamicDefaultString(retNode, "desc", ""); } auto args = d.find("args"); if (args == d.items().end() || !args->second.isArray()) { throw std::logic_error( folly::format("'{0}' must have an array field 'args'", name()).str() ); } auto ret = d.find("return"); if (ret == d.items().end() || !ret->second.isObject() || ret->second.find("type") == ret->second.items().end()) { throw std::logic_error( folly::format("'{0}' must have an array field 'return', which must have " "a string field 'type'", name()).str() ); } bool magic = isMagicMethod(); for (auto &p : args->second) { PhpParam param(p, magic); m_params.push_back(param); if (!param.hasDefault()) { ++m_minNumParams; } if (param.isCheckedType()) { ++m_numTypeChecks; } } m_flags = parseFlags(m_func["flags"]); }
PhpClass::PhpClass(const folly::dynamic &c) : m_class(c), m_idlName(c["name"].asString()), m_phpName(toPhpName(m_idlName)), m_cppName(toCppName(m_idlName)), m_flags(parseFlags(m_class["flags"])), m_desc(getFollyDynamicDefaultString(c, "desc", "")) { auto ifacesIt = m_class.find("ifaces"); if (ifacesIt != m_class.items().end()) { auto ifaces = ifacesIt->second; if (!ifaces.isArray()) { throw std::logic_error( folly::format("Class {0}.ifaces field must be an array", m_idlName).str() ); } for (auto &interface : ifaces) { m_ifaces.push_back(interface.asString()); } } for (auto const& f : c["funcs"]) { PhpFunc func(f, getCppName()); m_methods.push_back(func); } if (c.find("consts") != c.items().end()) { for (auto const& cns : c["consts"]) { PhpConst cons(cns, getCppName()); m_constants.push_back(cons); } } if (c.find("properties") != c.items().end()) { for (auto const& prp : c["properties"]) { PhpProp prop(prp, getCppName()); m_properties.push_back(prop); } } }
PhpParam::PhpParam(const folly::dynamic& param, bool isMagicMethod /*= false */) : m_name(param["name"].asString()), m_param(param), m_desc(getFollyDynamicDefaultString(param, "desc", "")) { if (isMagicMethod) { m_kindOf = KindOfAny; m_cppType = "HPHP::Variant"; return; } if (isRef()) { m_kindOf = KindOfRef; m_cppType = "HPHP::VRefParamValue const&"; } else { m_kindOf = kindOfFromDynamic(param["type"]); m_cppType = typeString(param["type"], false); } m_phpType = phpTypeFromDataType(m_kindOf); }
PhpFunc::PhpFunc(const folly::dynamic& d, const fbstring& className) : m_idlName(d["name"].asString()), m_phpName(toPhpName(m_idlName)), m_cppName(toCppName(m_idlName)), m_className(className), m_func(d), m_desc(getFollyDynamicDefaultString(d, "desc", "")), m_returnRef(d.getDefault("ref", "false") == "true"), m_returnKindOf(KindOfNull), m_returnCppType("void"), m_returnPhpType("void"), m_minNumParams(0), m_numTypeChecks(0) { if (isMethod() && m_idlName.find_last_of(NAMESPACE_STRING) != std::string::npos) { throw std::logic_error( folly::format("'{0}' is a method and cannot have a namespace in its name", m_idlName).str() ); } auto returnIt = d.find("return"); if (returnIt != d.items().end()) { auto retNode = returnIt->second; auto typeIt = retNode.find("type"); if (typeIt != retNode.items().end()) { auto type = typeIt->second; if ((type.isString()) && (type != "void") && (type != "null")) { m_returnKindOf = m_returnRef ? KindOfRef : kindOfFromDynamic(type); m_returnCppType = typeString(type, true); m_returnPhpType = phpTypeFromDataType(m_returnKindOf); } } m_returnDesc = getFollyDynamicDefaultString(retNode, "desc", ""); } auto args = d.find("args"); if (args == d.items().end() || !args->second.isArray()) { throw std::logic_error( folly::format("'{0}' must have an array field 'args'", m_idlName).str() ); } auto ret = d.find("return"); if (ret == d.items().end() || !ret->second.isObject() || ret->second.find("type") == ret->second.items().end()) { throw std::logic_error( folly::format("'{0}' must have an array field 'return', which must have " "a string field 'type'", m_idlName).str() ); } bool magic = isMagicMethod(); m_flags = parseFlags(m_func["flags"]); ParamMode paramMode = ParamMode::CoerceAndCall; if (m_flags & ParamCoerceModeNull) { paramMode = ParamMode::ZendNull; } else if (m_flags & ParamCoerceModeFalse) { paramMode = ParamMode::ZendFalse; } for (auto &p : args->second) { PhpParam param(p, magic, paramMode); m_params.push_back(param); if (!param.hasDefault()) { ++m_minNumParams; } if (param.isCheckedType()) { ++m_numTypeChecks; } } }