Skip to content

Commit 7a04515

Browse files
committed
Added PhpDateTime to avoid a (probably) common conflict.
1 parent 7e86407 commit 7a04515

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@
44
- Added public interface IPhpObject
55
- Added public class PhpObjectDictionary (implementing IPhpObject).
66
- Added public class PhpDynamicObject (implementing IPhpObject)
7+
- Added PhpDateTime to avoid conflicts with System.DateTime.
78

89
With IPhpObjects, you can get the class name specified in the serialized data via `GetClassName()`.
910

11+
**Known issues:**
12+
- Can not deserialize dynamic objects.
13+
1014
# 0.5.1
1115

1216
- Fixed misleading exception message on malformed objects.
1317
- Fixed valid classnames being rejected as malformed.
1418
- Fixed type-lookup logic trying to deserialize with `null` Type information.
1519

1620
Known issues:
17-
- Objects with classname `DateTime` will fail to deserialize, unless the option `EnableTypeLookup` is set to `false`.
21+
- ~~Objects with classname `DateTime` will fail to deserialize, unless the option `EnableTypeLookup` is set to `false`.~~ (fixed since)
1822

1923
# 0.5.0
2024

PhpSerializerNET/PhpDeserializer.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ namespace PhpSerializerNET {
1515
internal class PhpDeserializer {
1616
private PhpDeserializationOptions _options;
1717
private List<PhpSerializeToken> _tokens;
18-
private static Dictionary<string, Type> TypeLookupCache = new();
18+
private static Dictionary<string, Type> TypeLookupCache = new(){
19+
{ "DateTime", typeof(PhpDateTime) }
20+
};
1921

2022
public PhpDeserializer(string input, PhpDeserializationOptions options) {
2123
this._options = options;

PhpSerializerNET/Types/PhpDateTime.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
This Source Code Form is subject to the terms of the Mozilla Public
3+
License, v. 2.0. If a copy of the MPL was not distributed with this
4+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
5+
**/
6+
7+
namespace PhpSerializerNET {
8+
9+
[PhpClass("DateTime")]
10+
public class PhpDateTime : IPhpObject {
11+
[PhpProperty("date")]
12+
public string Date { get; set; }
13+
14+
[PhpProperty("timezone_type")]
15+
public int TimezoneType { get; set; }
16+
17+
[PhpProperty("timezone")]
18+
public string Timezone { get; set; }
19+
20+
public string GetClassName() {
21+
return "DateTime";
22+
}
23+
24+
public void SetClassName(string className) {
25+
// Nothing to do.
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)