Skip to content

Commit b1a242f

Browse files
author
Caitlin Bales (MSFT)
committed
Update models to support JSON data types
1 parent bced3e8 commit b1a242f

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

Templates/PHP/Model/ComplexType.php.tt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class <#=complex.Name.ToUpperFirstChar()#>
4141
<#
4242
if (property.Type.GetTypeString() == "datetime") {
4343
#>
44-
return datetime.strptime($this->_propDict["<#=property.Name.ToCamelize()#>"].replace("Z", ""), "%Y-%m-%dT%H:%M:%S.%f");
44+
return new \DateTime($this->_propDict["<#=property.Name.ToCamelize()#>"]);
4545
<#
4646
} else {
4747
#>
@@ -66,7 +66,7 @@ class <#=complex.Name.ToUpperFirstChar()#>
6666
<#
6767
if (property.Type.GetTypeString() == "datetime") {
6868
#>
69-
$this->_propDict["<#=propertyName#>"] = $val->isoformat()+"Z";
69+
$this->_propDict["<#=propertyName#>"] = $val->format(\DateTime::ISO8601) . "Z";
7070
<#
7171
} else {
7272
#>
@@ -106,7 +106,13 @@ class <#=complex.Name.ToUpperFirstChar()#>
106106
*/
107107
public function set<#=property.Name.ToCheckedCase()#>($val)
108108
{
109+
<# if (property.Type.GetTypeString() == "bool") { #>
110+
$this->propDict["<#=property.Name#>"] = boolval($val);
111+
<# } else if (property.Type.GetTypeString() == "int") { #>
112+
$this->propDict["<#=property.Name#>"] = intval($val);
113+
<# } else { #>
109114
$this->propDict["<#=property.Name#>"] = $val;
115+
<# } #>
110116
}
111117
<#
112118
}

Templates/PHP/Model/EntityType.php.tt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class <#=entity.Name.ToCheckedCase()#>
3939
/**
4040
* Gets the item ID
4141
*
42-
* @return array The item ID
42+
* @return int The item ID
4343
*/
4444
public function getId()
4545
{
@@ -116,7 +116,7 @@ class <#=entity.Name.ToCheckedCase()#>
116116
<#
117117
if (property.Type.GetTypeString() == "datetime") {
118118
#>
119-
return datetime.strptime($this->_propDict["<#=property.Name.ToCamelize()#>"].replace("Z", ""), "%Y-%m-%dT%H:%M:%S.%f");
119+
return new \DateTime($this->_propDict["<#=property.Name.ToCamelize()#>"]);
120120
<#
121121
} else {
122122
#>
@@ -132,7 +132,7 @@ class <#=entity.Name.ToCheckedCase()#>
132132
/**
133133
* Sets the <#=property.Name#>
134134
*
135-
* @param string $val The <#=propertyName#>
135+
* @param <#=property.Type.GetTypeString()#> $val The <#=propertyName#>
136136
*
137137
* @return null
138138
*/
@@ -141,7 +141,7 @@ class <#=entity.Name.ToCheckedCase()#>
141141
<#
142142
if (property.Type.GetTypeString() == "datetime") {
143143
#>
144-
$this->_propDict["<#=property.Name.ToCamelize()#>"] = $val->isoformat()+"Z";
144+
$this->_propDict["<#=property.Name.ToCamelize()#>"] = $val->format(\DateTime::ISO8601) . "Z";
145145
<#
146146
} else {
147147
#>

0 commit comments

Comments
 (0)