88class XsdToAbstractEntity
99{
1010 private \SimpleXMLElement $ xsd ;
11+ private string $ targetDirectory ;
1112
1213 public function __construct (string $ xsdPath )
1314 {
@@ -38,16 +39,18 @@ private function loadXsd(string $xsdPath): void
3839
3940 public function processAll (string $ targetDirectory ): void
4041 {
42+ $ this ->targetDirectory = $ targetDirectory ;
43+
4144 foreach ($ this ->xsd ->children () as $ entry ) {
4245 if ($ entry ->getName () === "complexType " ) {
43- $ this ->processOne ($ targetDirectory , $ entry );
46+ $ this ->processOne ($ entry );
4447 }
4548 }
4649 }
4750
48- public function processOne (string $ targetDirectory , \ SimpleXMLElement $ xsd ): bool
51+ private function processOne (\ SimpleXMLElement $ xsdElement , string $ overrideName = null ): bool
4952 {
50- $ entityName = (string )$ xsd ->attributes ()['name ' ];
53+ $ entityName = $ overrideName ? $ overrideName : (string )$ xsdElement ->attributes ()['name ' ];
5154
5255 if (empty ($ entityName ) || in_array ($ entityName , self ::$ typeBlackList )) {
5356 return false ;
@@ -60,7 +63,7 @@ public function processOne(string $targetDirectory, \SimpleXMLElement $xsd): boo
6063
6164 $ anyEntries = false ;
6265
63- foreach ($ xsd ->children () as $ child ) {
66+ foreach ($ xsdElement ->children () as $ child ) {
6467 foreach ($ child as $ element ) {
6568 if ($ this ->writeElement ($ buffer , $ element )) {
6669 $ anyEntries = true ;
@@ -74,7 +77,7 @@ public function processOne(string $targetDirectory, \SimpleXMLElement $xsd): boo
7477
7578 $ this ->writeFooter ($ buffer );
7679
77- $ targetPath = $ targetDirectory . "/ {$ entityName }.php " ;
80+ $ targetPath = $ this -> targetDirectory . "/ {$ entityName }.php " ;
7881
7982 if ($ this ->checkForChanges ($ buffer , $ targetPath )) {
8083 // Change detected, write file
@@ -153,19 +156,35 @@ private function writeElement(string &$buffer, \SimpleXMLElement $element): bool
153156 $ minOccurs = (int )($ attrs ['minOccurs ' ] ?? 1 );
154157 $ maxOccurs = (int )($ attrs ['maxOccurs ' ] ?? 1 );
155158
156- if (empty ($ name ) || empty ($ type )) {
157- return false ;
159+ $ isArray = $ maxOccurs > 1 || $ attrs ['maxOccurs ' ] == "unbounded " ;
160+ $ isNullable = $ minOccurs === 0 ;
161+
162+ // -------------------------------------------------------------------------------------------------------------
163+ // Nested complex types
164+
165+ // Some nodes, like <allergens> are empty arrays containing an array of a sub element like <allergeninfo>
166+ // These are basically anonymous and useless entities that we'll need create ourselves
167+
168+ foreach ($ element ->children () as $ child ) {
169+ if ($ child ->getName () === "complexType " ) {
170+ $ this ->processOne ($ child , $ name );
171+ $ type = $ name ;
172+ }
158173 }
159174
160- $ phpDocText = null ;
161- $ phpDocVarType = null ;
175+ // -------------------------------------------------------------------------------------------------------------
176+ // Process check
162177
163- $ isArray = $ maxOccurs > 1 || $ attrs ['maxOccurs ' ] == "unbounded " ;
164- $ isNullable = $ minOccurs === 0 ;
178+ if (empty ($ name ) || empty ($ type )) {
179+ return false ;
180+ }
165181
166182 // -------------------------------------------------------------------------------------------------------------
167183 // Determine php type
168184
185+ $ phpDocText = null ;
186+ $ phpDocVarType = null ;
187+
169188 if ($ type === "string " || str_starts_with ($ type , "translationtype_ " )
170189 || str_starts_with ($ type , "string_ " )) {
171190 $ phpTypeText = "string " ;
0 commit comments