Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jetted_target_ruby = { path = "../target_ruby" }
jetted_target_ruby_sig = { path = "../target_ruby_sig" }
jetted_target_rust = { path = "../target_rust" }
jetted_target_typescript = { path = "../target_typescript" }
jetted_target_php = { path = "../target_php" }
serde = "1.0"
serde_json = "1.0"
jtd = "0.2.1"
Expand Down
14 changes: 14 additions & 0 deletions crates/cli/src/cli.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,17 @@ args:
long: typescript-out
takes_value: true
value_name: dir

# PHP
- php-out:
help: Output directory for PHP code generation
long: php-out
takes_value: true
value_name: dir
requires:
- php-namespace
- php-namespace:
help: Namespace for PHP generated types
long: php-namespace
takes_value: true
value_name: namespace
14 changes: 14 additions & 0 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,20 @@ fn main() -> Result<()> {
log.finish("TypeScript", &codegen_info);
}

if let Some(out_dir) = matches.value_of("php-out") {
log.start("PHP", out_dir);

let namespace = matches.value_of("php-namespace").unwrap().to_owned();

let target = jetted_target_php::Target::new(Some(namespace));

let codegen_info =
jetted_core::codegen(&target, root_name.clone(), &schema, &Path::new(out_dir))
.with_context(|| "Failed to generate PHP code")?;

log.finish("PHP", &codegen_info);
}

log.flush();
Ok(())
}
Expand Down
16 changes: 8 additions & 8 deletions crates/core/src/target/inflect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub struct CombiningInflector {
}

impl CombiningInflector {
pub fn new(case: Case) -> Self {
pub const fn new(case: Case) -> Self {
Self { case }
}
}
Expand All @@ -51,7 +51,7 @@ pub struct TailInflector {
}

impl TailInflector {
pub fn new(case: Case) -> Self {
pub const fn new(case: Case) -> Self {
Self { case }
}
}
Expand Down Expand Up @@ -104,7 +104,7 @@ pub struct Case {
}

impl Case {
pub fn new(
pub const fn new(
first_capitalization: CaseCapitalization,
rest_capitalization: CaseCapitalization,
delimiter: Option<char>,
Expand All @@ -118,7 +118,7 @@ impl Case {
}
}

pub fn camel_case() -> Self {
pub const fn camel_case() -> Self {
Self::new(
CaseCapitalization::None,
CaseCapitalization::Initial,
Expand All @@ -127,7 +127,7 @@ impl Case {
)
}

pub fn pascal_case() -> Self {
pub const fn pascal_case() -> Self {
Self::new(
CaseCapitalization::Initial,
CaseCapitalization::Initial,
Expand All @@ -136,7 +136,7 @@ impl Case {
)
}

pub fn pascal_case_with_initialisms(initialisms: BTreeSet<String>) -> Self {
pub const fn pascal_case_with_initialisms(initialisms: BTreeSet<String>) -> Self {
Self::new(
CaseCapitalization::Initial,
CaseCapitalization::Initial,
Expand All @@ -145,7 +145,7 @@ impl Case {
)
}

pub fn snake_case() -> Self {
pub const fn snake_case() -> Self {
Self::new(
CaseCapitalization::None,
CaseCapitalization::None,
Expand All @@ -154,7 +154,7 @@ impl Case {
)
}

pub fn screaming_snake_case() -> Self {
pub const fn screaming_snake_case() -> Self {
Self::new(
CaseCapitalization::All,
CaseCapitalization::All,
Expand Down
15 changes: 15 additions & 0 deletions crates/target_php/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "jetted_target_php"
version = "0.1.0"
authors = [
"Eugenio Tampieri",
]
edition = "2024"

[dependencies]
jetted_core = { path = "../core" }
serde_json = "1.0"
regex = "1"

[dev-dependencies]
jetted_test = { path = "../test" }
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
1 change: 1 addition & 0 deletions crates/target_php/output/basic_enum/BasicEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
36 changes: 36 additions & 0 deletions crates/target_php/output/basic_properties/BasicProperties.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
final class BasicProperties {
private $bar;
private $baz;
private $foo;
private $quux;

/**
* @param bar: string
* @param baz: mixed
* @param foo: boolean
* @param quux: mixed
*/
public function __construct($bar, $baz, $foo, $quux) {
$this->bar = $bar;
$this->baz = $baz;
$this->foo = $foo;
$this->quux = $quux;
}
public function serialize() {
$result = [];
$result["bar"] = $this->bar;
$result["baz"] = $this->baz;
$result["foo"] = $this->foo;
$result["quux"] = $this->quux;
return json_encode($result);
}
public static function deserialize($data) {
return new self(
$result["bar"],
$result["baz"],
$result["foo"],
$result["quux"]
);
}
}
46 changes: 46 additions & 0 deletions crates/target_php/output/custom_overrides/CustomOverrides.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
final class CustomOverrides {
private $override_elements_container;
private $override_type_discriminator;
private $override_type_enum;
private $override_type_expr;
private $override_type_properties;
private $override_values_container;

/**
* @param override_elements_container: mixed
* @param override_type_discriminator: CustomOverridesOverrideTypeDiscriminator
* @param override_type_enum: CustomOverridesOverrideTypeEnum
* @param override_type_expr: string
* @param override_type_properties: CustomOverridesOverrideTypeProperties
* @param override_values_container: mixed
*/
public function __construct($override_elements_container, $override_type_discriminator, $override_type_enum, $override_type_expr, $override_type_properties, $override_values_container) {
$this->override_elements_container = $override_elements_container;
$this->override_type_discriminator = $override_type_discriminator;
$this->override_type_enum = $override_type_enum;
$this->override_type_expr = $override_type_expr;
$this->override_type_properties = $override_type_properties;
$this->override_values_container = $override_values_container;
}
public function serialize() {
$result = [];
$result["override_elements_container"] = $this->override_elements_container;
$result["override_type_discriminator"] = $this->override_type_discriminator;
$result["override_type_enum"] = $this->override_type_enum;
$result["override_type_expr"] = $this->override_type_expr;
$result["override_type_properties"] = $this->override_type_properties;
$result["override_values_container"] = $this->override_values_container;
return json_encode($result);
}
public static function deserialize($data) {
return new self(
$result["override_elements_container"],
$result["override_type_discriminator"],
$result["override_type_enum"],
$result["override_type_expr"],
$result["override_type_properties"],
$result["override_values_container"]
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
final class CustomOverridesOverrideTypeProperties {

/**
*/
public function __construct() {
}
public function serialize() {
$result = [];
return json_encode($result);
}
public static function deserialize($data) {
return new self(
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
1 change: 1 addition & 0 deletions crates/target_php/output/description/Baz.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
46 changes: 46 additions & 0 deletions crates/target_php/output/description/Description.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
final class Description {
private $discriminator_with_description;
private $enum_with_description;
private $long_description;
private $properties_with_description;
private $ref_with_description;
private $string_with_description;

/**
* @param discriminator_with_description: DescriptionDiscriminatorWithDescription
* @param enum_with_description: DescriptionEnumWithDescription
* @param long_description: string
* @param properties_with_description: DescriptionPropertiesWithDescription
* @param ref_with_description: Baz
* @param string_with_description: string
*/
public function __construct($discriminator_with_description, $enum_with_description, $long_description, $properties_with_description, $ref_with_description, $string_with_description) {
$this->discriminator_with_description = $discriminator_with_description;
$this->enum_with_description = $enum_with_description;
$this->long_description = $long_description;
$this->properties_with_description = $properties_with_description;
$this->ref_with_description = $ref_with_description;
$this->string_with_description = $string_with_description;
}
public function serialize() {
$result = [];
$result["discriminator_with_description"] = $this->discriminator_with_description;
$result["enum_with_description"] = $this->enum_with_description;
$result["long_description"] = $this->long_description;
$result["properties_with_description"] = $this->properties_with_description;
$result["ref_with_description"] = $this->ref_with_description;
$result["string_with_description"] = $this->string_with_description;
return json_encode($result);
}
public static function deserialize($data) {
return new self(
$result["discriminator_with_description"],
$result["enum_with_description"],
$result["long_description"],
$result["properties_with_description"],
$result["ref_with_description"],
$result["string_with_description"]
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
final class DescriptionPropertiesWithDescription {

/**
*/
public function __construct() {
}
public function serialize() {
$result = [];
return json_encode($result);
}
public static function deserialize($data) {
return new self(
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
1 change: 1 addition & 0 deletions crates/target_php/output/elements/Elements.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
Loading