@@ -8,38 +8,33 @@ CodeWriterPHP writer = (CodeWriterPHP) host.CodeWriter;
8
8
OdcmClass entity = host.CurrentType.AsOdcmClass();
9
9
TemplateWriterSettings settings = ConfigurationService.Settings;
10
10
String entityName = entity.Name.SanitizeEntityName();
11
- string targetNamespace = @"Microsoft\Graph\Model";
12
- String entityBaseName = "";
13
-
14
- if (entity.Base != null)
15
- entityBaseName = entity.Base.Name.SanitizeEntityName();
16
-
17
- // TemplateWriterSettings.Properties are set at the Typewriter command line. Check the command line
18
- // documentation for more information on how the TemplateWriterSettings.Properties is used.
19
- if (settings.Properties.ContainsKey("php.namespace"))
11
+ String entityCheckedCase = entity.Name.ToCheckedCase();
12
+ String targetNamespace = TypeHelperPHP.GetPHPNamespace(entity, settings);
13
+ String entityBaseName = TypeHelperPHP.GetBaseTypeFullName(entity.Base, targetNamespace, settings);
14
+ if (entityBaseName.Contains("\\"))
20
15
{
21
- targetNamespace = settings.Properties["php.namespace"] ;
22
- }
16
+ entityBaseName = "\\" + entityBaseName ;
17
+ }
23
18
24
19
#>
25
20
<#=writer.WriteHeader(writer.GetDocBlock(entityName.ToCheckedCase()))#>
26
21
namespace <#=targetNamespace#>;
27
22
28
23
<#=writer.GetClassBlock(entityName.ToCheckedCase().ToString(), "Model")#>
29
24
<#
30
- if (entity.Name.ToCheckedCase() == "Entity") {
25
+ if (entityCheckedCase == "Entity") {
31
26
#>
32
- class <#=entity.Name.ToCheckedCase() #> implements \JsonSerializable
27
+ class <#=entityCheckedCase #> implements \JsonSerializable
33
28
<#
34
29
} else {
35
30
#>
36
- class <#=entityName.ToCheckedCase()#> extends <#=entityBaseName.ToCheckedCase() #>
31
+ class <#=entityName.ToCheckedCase()#> extends <#=entityBaseName#>
37
32
<#
38
33
}
39
34
#>
40
35
{
41
36
<#
42
- if (entity.Name.ToCheckedCase() == "Entity") {
37
+ if (entityCheckedCase == "Entity") {
43
38
#>
44
39
/**
45
40
* The array of properties available
@@ -50,7 +45,7 @@ if (entity.Name.ToCheckedCase() == "Entity") {
50
45
protected $_propDict;
51
46
52
47
/**
53
- * Construct a new <#=entity.Name.ToCheckedCase() #>
48
+ * Construct a new <#=entityCheckedCase #>
54
49
*
55
50
* @param array $propDict A list of properties to set
56
51
*/
@@ -72,7 +67,19 @@ if (entity.Name.ToCheckedCase() == "Entity") {
72
67
<#
73
68
}
74
69
foreach(var property in entity.Properties.Where(prop => prop.Type.GetTypeString() != "bytes")){
75
- String propertyName = property.Name.SanitizePropertyName(entityName).ToCamelize();
70
+ String propertyName = property.Name.SanitizePropertyName(entityName).ToCamelize();
71
+ var camelCasePropertyName = property.Name.ToCamelize();
72
+ var propertyTypeString = property.Type.GetTypeString();
73
+ var propertyNamespace = TypeHelperPHP.GetPHPNamespace(property.Type, settings);
74
+
75
+ // Check whether this type is a generated model type or a PHP type
76
+ var fullPropertyTypeName = propertyTypeString[0] == '\\' || propertyTypeString.IsPHPPrimitiveType()
77
+ ? propertyTypeString
78
+ : string.Join("\\", propertyNamespace, propertyTypeString.SanitizeEntityName().ToCheckedCase());
79
+
80
+ var propertyTypeReference = propertyNamespace == targetNamespace && !propertyTypeString.IsPHPPrimitiveType()
81
+ ? propertyTypeString.SanitizeEntityName().ToCheckedCase()
82
+ : fullPropertyTypeName;
76
83
if (property.Type.IsComplex()) {
77
84
if (property.IsCollection()) {
78
85
#>
@@ -88,8 +95,8 @@ foreach(var property in entity.Properties.Where(prop => prop.Type.GetTypeString(
88
95
*/
89
96
public function get<#=propertyName.ToCheckedCase()#>()
90
97
{
91
- if (array_key_exists("<#=property.Name.ToCamelize() #>", $this->_propDict)) {
92
- return $this->_propDict["<#=property.Name.ToCamelize() #>"];
98
+ if (array_key_exists("<#=camelCasePropertyName #>", $this->_propDict)) {
99
+ return $this->_propDict["<#=camelCasePropertyName #>"];
93
100
} else {
94
101
return null;
95
102
}
@@ -102,13 +109,13 @@ foreach(var property in entity.Properties.Where(prop => prop.Type.GetTypeString(
102
109
* <#=property.GetSanitizedLongDescription()#>
103
110
<# } #>
104
111
*
105
- * @param <#=property.Type.GetTypeString().SanitizeEntityName().ToCheckedCase() #> $val The <#=propertyName#>
112
+ * @param <#=propertyTypeReference #> $val The <#=propertyName#>
106
113
*
107
- * @return <#=entity.Name.ToCheckedCase() #>
114
+ * @return <#=entityCheckedCase #>
108
115
*/
109
116
public function set<#=propertyName.ToCheckedCase()#>($val)
110
117
{
111
- $this->_propDict["<#=property.Name.ToCamelize() #>"] = $val;
118
+ $this->_propDict["<#=camelCasePropertyName #>"] = $val;
112
119
return $this;
113
120
}
114
121
@@ -122,26 +129,20 @@ foreach(var property in entity.Properties.Where(prop => prop.Type.GetTypeString(
122
129
* <#=property.GetSanitizedLongDescription()#>
123
130
<# } #>
124
131
*
125
- * @return <#=property.Type.GetTypeString().SanitizeEntityName().ToCheckedCase() #> The <#=propertyName#>
132
+ * @return <#=propertyTypeReference #> The <#=propertyName#>
126
133
*/
127
134
public function get<#=propertyName.ToCheckedCase()#>()
128
135
{
129
- if (array_key_exists("<#=property.Name.ToCamelize()#>", $this->_propDict)) {
130
- <#
131
- // Check whether this type is a generated model type or a PHP type
132
- if (property.Type.GetTypeString()[0] == '\\') { #>
133
- if (is_a($this->_propDict["<#=property.Name.ToCamelize()#>"], "<#=property.Type.GetTypeString()#>")) {
134
- <# } else { #>
135
- if (is_a($this->_propDict["<#=property.Name.ToCamelize()#>"], "<#=targetNamespace#>\<#=property.Type.GetTypeString()#>")) {
136
- <# } #>
137
- return $this->_propDict["<#=property.Name.ToCamelize()#>"];
136
+ if (array_key_exists("<#=camelCasePropertyName#>", $this->_propDict)) {
137
+ if (is_a($this->_propDict["<#=camelCasePropertyName#>"], "<#=fullPropertyTypeName#>")) {
138
+ return $this->_propDict["<#=camelCasePropertyName#>"];
138
139
} else {
139
- <# if (property.Type.GetTypeString() == "\\GuzzleHttp\\Psr7\\Stream") { #>
140
- $this->_propDict["<#=property.Name.ToCamelize() #>"] = \GuzzleHttp\Psr7\stream_for($this->_propDict["<#=property.Name.ToCamelize() #>"]);
141
- return $this->_propDict["<#=property.Name.ToCamelize() #>"];
140
+ <# if (propertyTypeString == "\\GuzzleHttp\\Psr7\\Stream") { #>
141
+ $this->_propDict["<#=camelCasePropertyName #>"] = \GuzzleHttp\Psr7\stream_for($this->_propDict["<#=camelCasePropertyName #>"]);
142
+ return $this->_propDict["<#=camelCasePropertyName #>"];
142
143
<# } else { #>
143
- $this->_propDict["<#=property.Name.ToCamelize() #>"] = new <#=property.Type.GetTypeString().SanitizeEntityName().ToCheckedCase() #>($this->_propDict["<#=property.Name.ToCamelize() #>"]);
144
- return $this->_propDict["<#=property.Name.ToCamelize() #>"];
144
+ $this->_propDict["<#=camelCasePropertyName #>"] = new <#=propertyTypeReference #>($this->_propDict["<#=camelCasePropertyName #>"]);
145
+ return $this->_propDict["<#=camelCasePropertyName #>"];
145
146
<# } #>
146
147
}
147
148
}
@@ -155,18 +156,18 @@ if (property.Type.GetTypeString()[0] == '\\') { #>
155
156
* <#=property.GetSanitizedLongDescription()#>
156
157
<# } #>
157
158
*
158
- * @param <#=property.Type.GetTypeString().SanitizeEntityName().ToCheckedCase() #> $val The <#=propertyName#>
159
+ * @param <#=propertyTypeReference #> $val The <#=propertyName#>
159
160
*
160
- * @return <#=entity.Name.ToCheckedCase() #>
161
+ * @return <#=entityCheckedCase #>
161
162
*/
162
163
public function set<#=propertyName.ToCheckedCase()#>($val)
163
164
{
164
- <# if (property.Type.GetTypeString() == "bool") { #>
165
- $this->_propDict["<#=property.Name.ToCamelize() #>"] = boolval($val);
166
- <# } else if (property.Type.GetTypeString() == "int") { #>
167
- $this->_propDict["<#=property.Name.ToCamelize() #>"] = intval($val);
165
+ <# if (propertyTypeString == "bool") { #>
166
+ $this->_propDict["<#=camelCasePropertyName #>"] = boolval($val);
167
+ <# } else if (propertyTypeString == "int") { #>
168
+ $this->_propDict["<#=camelCasePropertyName #>"] = intval($val);
168
169
<# } else { #>
169
- $this->_propDict["<#=property.Name.ToCamelize() #>"] = $val;
170
+ $this->_propDict["<#=camelCasePropertyName #>"] = $val;
170
171
<# } #>
171
172
return $this;
172
173
}
@@ -182,19 +183,19 @@ if (property.Type.GetTypeString()[0] == '\\') { #>
182
183
* <#=property.GetSanitizedLongDescription()#>
183
184
<# } #>
184
185
*
185
- * @return <#=property.Type.GetTypeString() #> The <#=propertyName#>
186
+ * @return <#=propertyTypeReference #> The <#=propertyName#>
186
187
*/
187
188
public function get<#=propertyName.ToCheckedCase()#>()
188
189
{
189
- if (array_key_exists("<#=property.Name.ToCamelize() #>", $this->_propDict)) {
190
+ if (array_key_exists("<#=camelCasePropertyName #>", $this->_propDict)) {
190
191
<#
191
- if (property.Type.GetTypeString() == "\\DateTime") {
192
+ if (propertyTypeString == "\\DateTime") {
192
193
#>
193
- return new \DateTime($this->_propDict["<#=property.Name.ToCamelize() #>"]);
194
+ return new \DateTime($this->_propDict["<#=camelCasePropertyName #>"]);
194
195
<#
195
196
} else {
196
197
#>
197
- return $this->_propDict["<#=property.Name.ToCamelize() #>"];
198
+ return $this->_propDict["<#=camelCasePropertyName #>"];
198
199
<#
199
200
}
200
201
#>
@@ -210,23 +211,23 @@ if (property.Type.GetTypeString()[0] == '\\') { #>
210
211
* <#=property.GetSanitizedLongDescription()#>
211
212
<# } #>
212
213
*
213
- * @param <#=property.Type.GetTypeString() #> $val The <#=propertyName#>
214
+ * @param <#=propertyTypeReference #> $val The <#=propertyName#>
214
215
*
215
- * @return <#=entity.Name.ToCheckedCase() #>
216
+ * @return <#=entityCheckedCase #>
216
217
*/
217
218
public function set<#=propertyName.ToCheckedCase()#>($val)
218
219
{
219
220
<#
220
- if (property.Type.GetTypeString() == "\\DateTime") {
221
+ if (propertyTypeString == "\\DateTime") {
221
222
#>
222
- $this->_propDict["<#=property.Name.ToCamelize() #>"]
223
+ $this->_propDict["<#=camelCasePropertyName #>"]
223
224
= $val->format(\DateTime::ISO8601) . "Z";
224
225
<#
225
226
} else {
226
227
#>
227
- <# if (property.Type.GetTypeString() == "bool") { #>
228
+ <# if (propertyTypeString == "bool") { #>
228
229
$this->_propDict["<#=property.Name#>"] = boolval($val);
229
- <# } else if (property.Type.GetTypeString() == "int") { #>
230
+ <# } else if (propertyTypeString == "int") { #>
230
231
$this->_propDict["<#=property.Name#>"] = intval($val);
231
232
<# } else { #>
232
233
$this->_propDict["<#=property.Name#>"] = $val;
@@ -240,7 +241,7 @@ if (property.Type.GetTypeString()[0] == '\\') { #>
240
241
<#
241
242
}
242
243
}
243
- if (entity.Name.ToCheckedCase() == "Entity") {
244
+ if (entityCheckedCase == "Entity") {
244
245
#>
245
246
/**
246
247
* Gets the ODataType
0 commit comments