-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(php): Generate single url environment (#4699)
- Loading branch information
Showing
284 changed files
with
2,702 additions
and
819 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
generators/php/sdk/src/environment/EnvironmentGenerator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { SdkGeneratorContext } from "../SdkGeneratorContext"; | ||
import { SingleUrlEnvironmentGenerator } from "./SingleUrlEnvironmentGenerator"; | ||
import { MultiUrlEnvironmentGenerator } from "./MultiUrlEnvironmentGenerator"; | ||
|
||
export class EnvironmentGenerator { | ||
private context: SdkGeneratorContext; | ||
|
||
public constructor(context: SdkGeneratorContext) { | ||
this.context = context; | ||
} | ||
|
||
public generate(): void { | ||
return this.context.ir.environments?.environments._visit({ | ||
singleBaseUrl: (value) => { | ||
const environments = new SingleUrlEnvironmentGenerator({ | ||
context: this.context, | ||
singleUrlEnvironments: value | ||
}); | ||
this.context.project.addSourceFiles(environments.generate()); | ||
}, | ||
multipleBaseUrls: (value) => { | ||
const environments = new MultiUrlEnvironmentGenerator({ | ||
context: this.context, | ||
multiUrlEnvironments: value | ||
}); | ||
this.context.project.addSourceFiles(environments.generate()); | ||
}, | ||
_other: () => undefined | ||
}); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
generators/php/sdk/src/environment/MultiUrlEnvironmentGenerator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { RelativeFilePath } from "@fern-api/fs-utils"; | ||
import { PhpFile, FileGenerator } from "@fern-api/php-codegen"; | ||
import { MultipleBaseUrlsEnvironments } from "@fern-fern/ir-sdk/api"; | ||
import { SdkCustomConfigSchema } from "../SdkCustomConfig"; | ||
import { SdkGeneratorContext } from "../SdkGeneratorContext"; | ||
|
||
export declare namespace MultiUrlEnvironmentGenerator { | ||
interface Args { | ||
context: SdkGeneratorContext; | ||
multiUrlEnvironments: MultipleBaseUrlsEnvironments; | ||
} | ||
} | ||
|
||
export class MultiUrlEnvironmentGenerator extends FileGenerator<PhpFile, SdkCustomConfigSchema, SdkGeneratorContext> { | ||
private multiUrlEnvironments: MultipleBaseUrlsEnvironments; | ||
|
||
constructor({ context, multiUrlEnvironments }: MultiUrlEnvironmentGenerator.Args) { | ||
super(context); | ||
this.multiUrlEnvironments = multiUrlEnvironments; | ||
} | ||
|
||
public doGenerate(): PhpFile { | ||
throw new Error("Multiple environment URLs are not supported yet"); | ||
} | ||
|
||
protected getFilepath(): RelativeFilePath { | ||
throw new Error("Multiple environment URLs are not supported yet"); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
generators/php/sdk/src/environment/SingleUrlEnvironmentGenerator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { php, PhpFile, FileGenerator } from "@fern-api/php-codegen"; | ||
import { join, RelativeFilePath } from "@fern-api/fs-utils"; | ||
import { SingleBaseUrlEnvironments } from "@fern-fern/ir-sdk/api"; | ||
import { SdkCustomConfigSchema } from "../SdkCustomConfig"; | ||
import { SdkGeneratorContext } from "../SdkGeneratorContext"; | ||
|
||
export declare namespace SingleUrlEnvironmentGenerator { | ||
interface Args { | ||
context: SdkGeneratorContext; | ||
singleUrlEnvironments: SingleBaseUrlEnvironments; | ||
} | ||
} | ||
|
||
export class SingleUrlEnvironmentGenerator extends FileGenerator<PhpFile, SdkCustomConfigSchema, SdkGeneratorContext> { | ||
private singleUrlEnvironments: SingleBaseUrlEnvironments; | ||
|
||
constructor({ context, singleUrlEnvironments }: SingleUrlEnvironmentGenerator.Args) { | ||
super(context); | ||
this.singleUrlEnvironments = singleUrlEnvironments; | ||
} | ||
|
||
public doGenerate(): PhpFile { | ||
const enum_ = php.enum_({ | ||
...this.context.getEnvironmentsClassReference(), | ||
backing: "string" | ||
}); | ||
|
||
for (const environment of this.singleUrlEnvironments.environments) { | ||
enum_.addMember({ | ||
name: this.context.getEnvironmentName(environment.name), | ||
value: environment.url | ||
}); | ||
} | ||
|
||
return new PhpFile({ | ||
clazz: enum_, | ||
directory: RelativeFilePath.of(""), | ||
rootNamespace: this.context.getRootNamespace(), | ||
customConfig: this.context.customConfig | ||
}); | ||
} | ||
|
||
protected getFilepath(): RelativeFilePath { | ||
return join( | ||
this.context.project.filepaths.getSourceDirectory(), | ||
RelativeFilePath.of(`${this.context.getEnvironmentsClassReference().name}.php`) | ||
); | ||
} | ||
} |
Oops, something went wrong.