File tree Expand file tree Collapse file tree 2 files changed +14
-23
lines changed Expand file tree Collapse file tree 2 files changed +14
-23
lines changed Original file line number Diff line number Diff line change @@ -16,9 +16,19 @@ internal class PhpDeserializer {
1616 private PhpDeserializationOptions _options ;
1717 private List < PhpSerializeToken > _tokens ;
1818
19- public PhpDeserializer ( PhpDeserializationOptions options , List < PhpSerializeToken > tokens ) {
19+ public PhpDeserializer ( string input , PhpDeserializationOptions options ) {
2020 this . _options = options ;
21- this . _tokens = tokens ;
21+ if ( this . _options == null ) {
22+ this . _options = PhpDeserializationOptions . DefaultOptions ;
23+ }
24+ this . _tokens = new PhpTokenizer ( input , _options ) . Tokenize ( ) ;
25+
26+ if ( _tokens . Count > 1 ) {
27+ throw new DeserializationException ( "Can not deserialize loose collection of values into object" ) ;
28+ }
29+ if ( _tokens . Count == 0 ) {
30+ throw new DeserializationException ( "No PHP serialization data found." ) ;
31+ }
2232 }
2333
2434 public object Deserialize ( ) {
Original file line number Diff line number Diff line change @@ -33,16 +33,7 @@ public static class PhpSerializer {
3333 /// <see cref="Dictionary{object,object}"/>
3434 /// </returns>
3535 public static object Deserialize ( string input , PhpDeserializationOptions options = null ) {
36- if ( options == null ) {
37- options = PhpDeserializationOptions . DefaultOptions ;
38- }
39- var tokens = new PhpTokenizer ( input , options ) . Tokenize ( ) ;
40- if ( tokens . Count > 1 ) // TODO: maybe have an option to return a List<> in this case.
41- {
42- throw new DeserializationException ( "Can not deserialize loose collection of values into object" ) ;
43- }
44-
45- return new PhpDeserializer ( options , tokens ) . Deserialize ( ) ;
36+ return new PhpDeserializer ( input , options ) . Deserialize ( ) ;
4637 }
4738
4839 /// <summary>
@@ -62,17 +53,7 @@ public static T Deserialize<T>(
6253 string input ,
6354 PhpDeserializationOptions options = null
6455 ) {
65- if ( options == null ) {
66- options = PhpDeserializationOptions . DefaultOptions ;
67- }
68- var tokens = new PhpTokenizer ( input , options ) . Tokenize ( ) ;
69-
70- if ( tokens . Count > 1 ) // TODO: maybe have an option to return a List<> in this case.
71- {
72- throw new DeserializationException ( "Can not deserialize loose collection of values into object" ) ;
73- }
74-
75- return new PhpDeserializer ( options , tokens ) . Deserialize < T > ( ) ;
56+ return new PhpDeserializer ( input , options ) . Deserialize < T > ( ) ;
7657 }
7758
7859 /// <summary>
You can’t perform that action at this time.
0 commit comments