Skip to content

Commit 9537e7e

Browse files
author
Caitlin Bales (MSFT)
authored
Merge pull request #81 from microsoftgraph/caitbal/working
Update PHP templates
2 parents 7042720 + 6e58b8e commit 9537e7e

File tree

2 files changed

+72
-28
lines changed

2 files changed

+72
-28
lines changed

Templates/PHP/Model/ComplexType.php.tt

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ OdcmClass complex = (OdcmClass)host.CurrentType;
1010
<#=writer.WriteHeader(writer.GetDocBlock(complex.Name.ToCheckedCase()))#>
1111
namespace Microsoft\Graph\Model;
1212
<#=writer.GetClassBlock(complex.Name.ToCheckedCase().ToString(), "Model")#>
13+
<#
14+
if (complex.Base != null) {
15+
#>
16+
class <#=complex.Name.ToCheckedCase()#> extends <#=complex.Base.Name.ToCheckedCase()#>
17+
<#
18+
} else {
19+
#>
1320
class <#=complex.Name.ToCheckedCase()#> extends Entity
21+
<#
22+
}
23+
#>
1424
{
15-
/**
16-
* Gets the property dictionary of the <#=complex.Name.ToCheckedCase()#>
17-
*
18-
* @return array The list of properties
19-
*/
20-
public function getProperties()
21-
{
22-
return $this->_propDict;
23-
}
2425
<#
2526
foreach(var property in complex.Properties.Where(prop => prop.Type.GetTypeString() != "bytes")){
2627
var propertyName = property.Name.ToUnderscore();
2728
if (!property.Type.IsComplex()) {
2829
#>
29-
3030
/**
3131
* Gets the <#=property.Name#>
3232
*
@@ -89,8 +89,13 @@ foreach(var property in complex.Properties.Where(prop => prop.Type.GetTypeString
8989
if (is_a($this->_propDict["<#=property.Name.ToCamelize()#>"], "<#=property.Type.GetTypeString()#>")) {
9090
return $this->_propDict["<#=property.Name.ToCamelize()#>"];
9191
} else {
92+
<# if (property.Type.GetTypeString() == "\\GuzzleHttp\\Psr7\\Stream") { #>
93+
$this->_propDict["<#=property.Name.ToCamelize()#>"] = \GuzzleHttp\Psr7\stream_for($this->_propDict["<#=property.Name.ToCamelize()#>"]);
94+
return $this->_propDict["<#=property.Name.ToCamelize()#>"];
95+
<# } else { #>
9296
$this->_propDict["<#=property.Name.ToCamelize()#>"] = new <#=property.Type.GetTypeString()#>($this->_propDict["<#=property.Name.ToCamelize()#>"]);
9397
return $this->_propDict["<#=property.Name.ToCamelize()#>"];
98+
<# } #>
9499
}
95100
}
96101
return null;

Templates/PHP/Model/EntityType.php.tt

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ namespace Microsoft\Graph\Model;
1616
<#
1717
if (entity.Name.ToCheckedCase() == "Entity") {
1818
#>
19-
class <#=entity.Name.ToCheckedCase()#>
19+
class <#=entity.Name.ToCheckedCase()#> implements \JsonSerializable
2020
<#
2121
} else {
2222
#>
23-
class <#=entity.Name.ToCheckedCase()#> extends Entity
23+
class <#=entity.Name.ToCheckedCase()#> extends <#=entity.Base.Name.ToCheckedCase() #>
2424
<#
2525
}
2626
#>
@@ -45,9 +45,7 @@ if (entity.Name.ToCheckedCase() == "Entity") {
4545
{
4646
$this->_propDict = $propDict;
4747
}
48-
<#
49-
}
50-
#>
48+
5149
/**
5250
* Gets the property dictionary of the <#=entity.Name.ToUpperFirstChar()#>
5351
*
@@ -57,19 +55,20 @@ if (entity.Name.ToCheckedCase() == "Entity") {
5755
{
5856
return $this->_propDict;
5957
}
60-
<#
58+
59+
<#
60+
}
6161
foreach(var property in entity.Properties.Where(prop => prop.Type.GetTypeString() != "bytes")){
6262
var propertyName = property.Name.ToUnderscore();
6363
var propertyNameCap = property.Name.ToUpperFirstChar();
6464
if (property.Type.IsComplex()) {
6565
if (property.IsCollection()) {
6666
#>
67-
68-
/**
69-
* Gets the <#=property.Name#>
70-
*
71-
* @return array The <#=property.Name#>
72-
*/
67+
/**
68+
* Gets the <#=property.Name#>
69+
*
70+
* @return array The <#=property.Name#>
71+
*/
7372
public function get<#=property.Name.ToCheckedCase()#>()
7473
{
7574
if (array_key_exists("<#=property.Name.ToCamelize()#>", $this->_propDict)) {
@@ -78,7 +77,7 @@ foreach(var property in entity.Properties.Where(prop => prop.Type.GetTypeString(
7877
return null;
7978
}
8079
}
81-
80+
8281
/**
8382
* Sets the <#=property.Name#>
8483
*
@@ -91,11 +90,10 @@ foreach(var property in entity.Properties.Where(prop => prop.Type.GetTypeString(
9190
$this->_propDict["<#=property.Name.ToCamelize()#>"] = $val;
9291
return $this;
9392
}
94-
93+
9594
<#
9695
} else {
9796
#>
98-
9997
/**
10098
* Gets the <#=property.Name#>
10199
*
@@ -107,13 +105,18 @@ foreach(var property in entity.Properties.Where(prop => prop.Type.GetTypeString(
107105
if (is_a($this->_propDict["<#=property.Name.ToCamelize()#>"], "<#=property.Type.GetTypeString()#>")) {
108106
return $this->_propDict["<#=property.Name.ToCamelize()#>"];
109107
} else {
108+
<# if (property.Type.GetTypeString() == "\\GuzzleHttp\\Psr7\\Stream") { #>
109+
$this->_propDict["<#=property.Name.ToCamelize()#>"] = \GuzzleHttp\Psr7\stream_for($this->_propDict["<#=property.Name.ToCamelize()#>"]);
110+
return $this->_propDict["<#=property.Name.ToCamelize()#>"];
111+
<# } else { #>
110112
$this->_propDict["<#=property.Name.ToCamelize()#>"] = new <#=property.Type.GetTypeString()#>($this->_propDict["<#=property.Name.ToCamelize()#>"]);
111113
return $this->_propDict["<#=property.Name.ToCamelize()#>"];
114+
<# } #>
112115
}
113116
}
114117
return null;
115118
}
116-
119+
117120
/**
118121
* Sets the <#=property.Name#>
119122
*
@@ -132,11 +135,11 @@ foreach(var property in entity.Properties.Where(prop => prop.Type.GetTypeString(
132135
<# } #>
133136
return $this;
134137
}
138+
135139
<#
136140
}
137141
} else {
138142
#>
139-
140143
/**
141144
* Gets the <#=property.Name#>
142145
*
@@ -160,7 +163,7 @@ foreach(var property in entity.Properties.Where(prop => prop.Type.GetTypeString(
160163
return null;
161164
}
162165
}
163-
166+
164167
/**
165168
* Sets the <#=property.Name#>
166169
*
@@ -190,8 +193,44 @@ foreach(var property in entity.Properties.Where(prop => prop.Type.GetTypeString(
190193
#>
191194
return $this;
192195
}
196+
193197
<#
194198
}
195199
}
200+
if (entity.Name.ToCheckedCase() == "Entity") {
201+
#>
202+
/**
203+
* Gets the ODataType
204+
*
205+
* @return string The ODataType
206+
*/
207+
public function getODataType()
208+
{
209+
return $this->_propDict["@odata.type"];
210+
}
211+
212+
/**
213+
* Sets the ODataType
214+
*
215+
* @param string The ODataType
216+
*
217+
* @return Entity
218+
*/
219+
public function setODataType($val)
220+
{
221+
$this->_propDict["@odata.type"] = $val;
222+
}
223+
224+
/**
225+
* Serializes the object by property array
226+
*
227+
* @return array The list of properties
228+
*/
229+
public function jsonSerialize()
230+
{
231+
return $this->getProperties();
232+
}
233+
<#
234+
}
196235
#>
197236
}

0 commit comments

Comments
 (0)