Skip to content

Commit 70b0e93

Browse files
committed
fix: add constructor for php lang
1 parent 0d46a41 commit 70b0e93

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

templates/cli/lib/type-generation/languages/php.js.twig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ class <%- toPascalCase(collection.name) %> {
4444
<% for (const attribute of collection.attributes ){ -%>
4545
public <%- getType(attribute) %> $<%- toCamelCase(attribute.key) %>;
4646
<% } -%>
47+
48+
public function __construct(
49+
<% for (const attribute of collection.attributes ){ -%>
50+
<% if (attribute.required) { -%>
51+
<%- getType(attribute).replace('|null', '') %> $<%- toCamelCase(attribute.key) %><% if (collection.attributes.indexOf(attribute) < collection.attributes.length - 1) { %>,<% } %>
52+
<% } else { -%>
53+
?<%- getType(attribute).replace('|null', '') %> $<%- toCamelCase(attribute.key) %> = null<% if (collection.attributes.indexOf(attribute) < collection.attributes.length - 1) { %>,<% } %>
54+
<% } -%>
55+
<% } -%>
56+
) {
57+
<% for (const attribute of collection.attributes ){ -%>
58+
$this-><%- toCamelCase(attribute.key) %> = $<%- toCamelCase(attribute.key) %>;
59+
<% } -%>
60+
}
4761
}`;
4862
}
4963

0 commit comments

Comments
 (0)