Skip to content

Commit ae2ac3c

Browse files
author
Caitlin Bales (MSFT)
committed
Add entity inheritance
1 parent 1d10f6a commit ae2ac3c

File tree

2 files changed

+37
-17
lines changed

2 files changed

+37
-17
lines changed

Templates/PHP/Model/ComplexType.php.tt

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ 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-
class <#=complex.Name.ToUpperFirstChar()#>
13+
class <#=complex.Name.ToUpperFirstChar()#> extends Entity
1414
{
1515
/**
1616
* The array of properties available
@@ -31,6 +31,16 @@ class <#=complex.Name.ToUpperFirstChar()#>
3131
{
3232
$this->_propDict = $propDict;
3333
}
34+
35+
/**
36+
* Gets the property dictionary of the <#=complex.Name.ToCheckedCase()#>
37+
*
38+
* @return array The list of properties
39+
*/
40+
public function getProperties()
41+
{
42+
return $this->_propDict;
43+
}
3444
<#
3545
foreach(var property in complex.Properties.Where(prop => prop.Type.GetTypeString() != "bytes")){
3646
var propertyName = property.Name.ToUnderscore();
@@ -44,15 +54,15 @@ foreach(var property in complex.Properties.Where(prop => prop.Type.GetTypeString
4454
*/
4555
public function get<#=property.Name.ToCheckedCase()#>()
4656
{
47-
if (array_key_exists("<#=property.Name.ToCamelize()#>", $this->propDict)) {
57+
if (array_key_exists("<#=property.Name.ToCamelize()#>", $this->_propDict)) {
4858
<#
4959
if (property.Type.GetTypeString() == "datetime") {
5060
#>
5161
return new \DateTime($this->_propDict["<#=property.Name.ToCamelize()#>"]);
5262
<#
5363
} else {
5464
#>
55-
return $this->propDict["<#=property.Name.ToCamelize()#>"];
65+
return $this->_propDict["<#=property.Name.ToCamelize()#>"];
5666
<#
5767
}
5868
#>
@@ -95,12 +105,12 @@ foreach(var property in complex.Properties.Where(prop => prop.Type.GetTypeString
95105
*/
96106
public function get<#=property.Name.ToCheckedCase()#>()
97107
{
98-
if (array_key_exists("<#=property.Name.ToCamelize()#>", $this->propDict)) {
99-
if (is_a($this->propDict["<#=property.Name.ToCamelize()#>"], '<#=property.Type.GetTypeString()#>')) {
100-
return $this->propDict["<#=property.Name.ToCamelize()#>"];
108+
if (array_key_exists("<#=property.Name.ToCamelize()#>", $this->_propDict)) {
109+
if (is_a($this->_propDict["<#=property.Name.ToCamelize()#>"], '<#=property.Type.GetTypeString()#>')) {
110+
return $this->_propDict["<#=property.Name.ToCamelize()#>"];
101111
} else {
102-
$this->propDict["<#=property.Name.ToCamelize()#>"] = new <#=property.Type.GetTypeString()#>($this->propDict["<#=property.Name.ToCamelize()#>"]);
103-
return $this->propDict["<#=property.Name.ToCamelize()#>"];
112+
$this->_propDict["<#=property.Name.ToCamelize()#>"] = new <#=property.Type.GetTypeString()#>($this->_propDict["<#=property.Name.ToCamelize()#>"]);
113+
return $this->_propDict["<#=property.Name.ToCamelize()#>"];
104114
}
105115
}
106116
return null;
@@ -116,11 +126,11 @@ foreach(var property in complex.Properties.Where(prop => prop.Type.GetTypeString
116126
public function set<#=property.Name.ToCheckedCase()#>($val)
117127
{
118128
<# if (property.Type.GetTypeString() == "bool") { #>
119-
$this->propDict["<#=property.Name#>"] = boolval($val);
129+
$this->_propDict["<#=property.Name#>"] = boolval($val);
120130
<# } else if (property.Type.GetTypeString() == "int") { #>
121-
$this->propDict["<#=property.Name#>"] = intval($val);
131+
$this->_propDict["<#=property.Name#>"] = intval($val);
122132
<# } else { #>
123-
$this->propDict["<#=property.Name#>"] = $val;
133+
$this->_propDict["<#=property.Name#>"] = $val;
124134
<# } #>
125135
return $this;
126136
}

Templates/PHP/Model/EntityType.php.tt

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,17 @@ TemplateWriterSettings settings = ConfigurationService.Settings;
1313
namespace Microsoft\Graph\Model;
1414

1515
<#=writer.GetClassBlock(entity.Name.ToCheckedCase().ToString(), "Model")#>
16+
<#
17+
if (entity.Name.ToCheckedCase() == "Entity") {
18+
#>
1619
class <#=entity.Name.ToCheckedCase()#>
20+
<#
21+
} else {
22+
#>
23+
class <#=entity.Name.ToCheckedCase()#> extends Entity
24+
<#
25+
}
26+
#>
1727
{
1828
/**
1929
* The array of properties available
@@ -110,11 +120,11 @@ foreach(var property in entity.Properties.Where(prop => prop.Type.GetTypeString(
110120
public function set<#=property.Name.ToCheckedCase()#>($val)
111121
{
112122
<# if (property.Type.GetTypeString() == "bool") { #>
113-
$this->propDict["<#=property.Name#>"] = boolval($val);
123+
$this->_propDict["<#=property.Name#>"] = boolval($val);
114124
<# } else if (property.Type.GetTypeString() == "int") { #>
115-
$this->propDict["<#=property.Name#>"] = intval($val);
125+
$this->_propDict["<#=property.Name#>"] = intval($val);
116126
<# } else { #>
117-
$this->propDict["<#=property.Name#>"] = $val;
127+
$this->_propDict["<#=property.Name#>"] = $val;
118128
<# } #>
119129
return $this;
120130
}
@@ -165,11 +175,11 @@ foreach(var property in entity.Properties.Where(prop => prop.Type.GetTypeString(
165175
} else {
166176
#>
167177
<# if (property.Type.GetTypeString() == "bool") { #>
168-
$this->propDict["<#=property.Name#>"] = boolval($val);
178+
$this->_propDict["<#=property.Name#>"] = boolval($val);
169179
<# } else if (property.Type.GetTypeString() == "int") { #>
170-
$this->propDict["<#=property.Name#>"] = intval($val);
180+
$this->_propDict["<#=property.Name#>"] = intval($val);
171181
<# } else { #>
172-
$this->propDict["<#=property.Name#>"] = $val;
182+
$this->_propDict["<#=property.Name#>"] = $val;
173183
<# } #>
174184
<#
175185
}

0 commit comments

Comments
 (0)