Skip to content

Commit fe56ead

Browse files
committed
feat(generator): support anonymous sub list types
1 parent c3fd8ad commit fe56ead

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+837
-18
lines changed

src/Generation/XsdToAbstractEntity.php

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
class 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";

src/Models/Entities/Allergens.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace SoftwarePunt\PSAPI\Models\Entities;
4+
5+
use SoftwarePunt\PSAPI\Models\AbstractEntity;
6+
7+
/**
8+
* Allergens PS-API type
9+
* @generated 2021-08-24
10+
**/
11+
class Allergens extends AbstractEntity
12+
{
13+
/**
14+
* @var Allergeninfo[]
15+
*/
16+
public array $allergeninfo;
17+
}

src/Models/Entities/Allergenset.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66

77
/**
88
* Allergenset PS-API type
9-
* @generated 2021-07-14
9+
* @generated 2021-08-24
1010
**/
1111
class Allergenset extends AbstractEntity
1212
{
1313
public ?string $allergencomment = null;
14+
public Allergens $allergens;
1415
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace SoftwarePunt\PSAPI\Models\Entities;
4+
5+
use SoftwarePunt\PSAPI\Models\AbstractEntity;
6+
7+
/**
8+
* Alternativegtins PS-API type
9+
* @generated 2021-08-24
10+
**/
11+
class Alternativegtins extends AbstractEntity
12+
{
13+
/**
14+
* @var Alternativegtin[]
15+
*/
16+
public array $alternativegtin;
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace SoftwarePunt\PSAPI\Models\Entities;
4+
5+
use SoftwarePunt\PSAPI\Models\AbstractEntity;
6+
7+
/**
8+
* Assetangletypes PS-API type
9+
* @generated 2021-08-24
10+
**/
11+
class Assetangletypes extends AbstractEntity
12+
{
13+
/**
14+
* @var Assetangletype[]
15+
*/
16+
public array $assetangletype;
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace SoftwarePunt\PSAPI\Models\Entities;
4+
5+
use SoftwarePunt\PSAPI\Models\AbstractEntity;
6+
7+
/**
8+
* Assetfacingtypes PS-API type
9+
* @generated 2021-08-24
10+
**/
11+
class Assetfacingtypes extends AbstractEntity
12+
{
13+
/**
14+
* @var Assetfacingtype[]
15+
*/
16+
public array $assetfacingtype;
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace SoftwarePunt\PSAPI\Models\Entities;
4+
5+
use SoftwarePunt\PSAPI\Models\AbstractEntity;
6+
7+
/**
8+
* Assetformattypes PS-API type
9+
* @generated 2021-08-24
10+
**/
11+
class Assetformattypes extends AbstractEntity
12+
{
13+
/**
14+
* @var Assetformattype[]
15+
*/
16+
public array $assetformattype;
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace SoftwarePunt\PSAPI\Models\Entities;
4+
5+
use SoftwarePunt\PSAPI\Models\AbstractEntity;
6+
7+
/**
8+
* Assetlabels PS-API type
9+
* @generated 2021-08-24
10+
**/
11+
class Assetlabels extends AbstractEntity
12+
{
13+
/**
14+
* @var Assetlabel[]
15+
*/
16+
public array $assetlabel;
17+
}

src/Models/Entities/Assettypes.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace SoftwarePunt\PSAPI\Models\Entities;
4+
5+
use SoftwarePunt\PSAPI\Models\AbstractEntity;
6+
7+
/**
8+
* Assettypes PS-API type
9+
* @generated 2021-08-24
10+
**/
11+
class Assettypes extends AbstractEntity
12+
{
13+
/**
14+
* @var Assettype[]
15+
*/
16+
public array $assettype;
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace SoftwarePunt\PSAPI\Models\Entities;
4+
5+
use SoftwarePunt\PSAPI\Models\AbstractEntity;
6+
7+
/**
8+
* Catchzoneinfolist PS-API type
9+
* @generated 2021-08-24
10+
**/
11+
class Catchzoneinfolist extends AbstractEntity
12+
{
13+
/**
14+
* @var Fishcatchzoneinfo[]
15+
*/
16+
public array $catchzoneinfo;
17+
}

0 commit comments

Comments
 (0)