@@ -11,6 +11,7 @@ class Entry
1111 const INDEX_ENTRYCLASS = 0 ;
1212 const INDEX_MULTIPLICITY = 1 ;
1313 const INDEX_EMBEDDING = 2 ;
14+ const INDEX_NULLABLE = 3 ;
1415
1516 /**
1617 * @var array
@@ -64,18 +65,19 @@ private static function parseAssociations($class)
6465
6566 foreach (static ::$ associations as $ association => $ entryClass ) {
6667 $ matches = [];
67- $ result = preg_match ('#^([^.[\]]+)(\.[^.[\]]*)?(\[\])?$# ' , $ association , $ matches );
68+ $ result = preg_match ('#^(\?)?( [^.[\]]+)(\.[^.[\]]*)?(\[\])?$# ' , $ association , $ matches );
6869
69- if ($ result === 0 || (!empty ($ matches [2 ]) && !empty ($ matches [3 ]))) {
70+ if ($ result === 0 || (!empty ($ matches [3 ]) && !empty ($ matches [4 ]))) {
7071 throw new InvalidArgumentException ('Invalid association definition given: ' . $ association );
7172 }
7273
73- self ::$ parsedAssociations [$ class ][$ matches [1 ]] = [
74+ self ::$ parsedAssociations [$ class ][$ matches [2 ]] = [
7475 self ::INDEX_ENTRYCLASS => $ entryClass ,
75- self ::INDEX_MULTIPLICITY => !empty ($ matches [3 ]),
76- self ::INDEX_EMBEDDING => !empty ($ matches [2 ]) ?
77- ($ matches [2 ] === '. ' ? $ matches [1 ] . '_ ' : substr ($ matches [2 ], 1 )) :
76+ self ::INDEX_MULTIPLICITY => !empty ($ matches [4 ]),
77+ self ::INDEX_EMBEDDING => !empty ($ matches [3 ]) ?
78+ ($ matches [3 ] === '. ' ? $ matches [2 ] . '_ ' : substr ($ matches [3 ], 1 )) :
7879 FALSE ,
80+ self ::INDEX_NULLABLE => !empty ($ matches [1 ]),
7981 ];
8082 }
8183 }
@@ -101,7 +103,7 @@ public function __get($name)
101103 $ this ->readEmbeddedEntry ($ association [self ::INDEX_EMBEDDING ]) :
102104 $ this ->readData ($ name );
103105
104- if ($ data === NULL ) {
106+ if ($ data === NULL || ( $ association [ self :: INDEX_NULLABLE ] && empty ( $ data )) ) {
105107 return $ this ->data [$ name ] = NULL ;
106108 }
107109
0 commit comments