public PhpFunctionGroup(string @namespace, MethodGroup o) { var functions = o.Methods.Select(m => new PhpOperation(m)); Class = PHP.Class( name: Class.CreateName(@namespace, o.Name), constructor: PHP.Constructor( parameters: GroupConstructorParameters, body: functions.SelectMany(f => f.ConstructorStatements)), functions: functions.Select(f => f.Function), properties: functions.Select(f => f.Property)); Property = PHP.Property(Class.Name, "_" + o.Name + "_group"); Create = PHP .This .Arrow(Property) .Assign(PHP.New(Class.Name, ClientParameterRef)) .Statement(); Function = PHP.Function( name: $"get{o.Name}", @return: Class, body: PHP.Statements(PHP.Return(PHP.This.Arrow(Property)))); }
public override async Task Generate(CodeModel codeModel) { var @namespace = Class.CreateName(codeModel.Namespace); var phpGroups = codeModel.Operations .Where(o => o.Name.RawValue != string.Empty) .Select(o => new PhpFunctionGroup(@namespace, o)); var phpFunctions = codeModel.Operations .Where(o => o.Name.RawValue == string.Empty) .SelectMany(o => o.Methods.Select(m => new PhpOperation(m))); var swaggerObjectData = PHP.Const( SwaggerObjectData, PHP.FromJson(SwaggerObject.Create(codeModel))); var client = PHP.Class( name: Class.CreateName(@namespace, codeModel.Name), constructor: PHP.Constructor( parameters: ClientConstructorParameters, body: PHP .Statements(CreateClient) .Concat(phpGroups.Select(g => g.Create)) .Concat(phpFunctions.SelectMany(f => f.ConstructorStatements))), functions: phpGroups .Select(o => o.Function) .Concat(phpFunctions.Select(f => f.Function)), properties: phpGroups .Select(o => o.Property) .Concat(phpFunctions.Select(f => f.Property)), consts: PHP.Consts(swaggerObjectData)); foreach (var class_ in phpGroups .Select(o => o.Class) .Concat(ImmutableArray.Create(client))) { await Write( string.Join("\n", class_.ToCodeText(Indent)), class_.Name.FileName, false); } }