Skip to content

Commit cbceea3

Browse files
authored
Merge pull request #14 from veewee/add-array-info
Add soap-enc array information
2 parents 789fb1c + 2fc6b5c commit cbceea3

File tree

4 files changed

+95
-2
lines changed

4 files changed

+95
-2
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
],
1717
"require": {
1818
"php": "~8.1.0 || ~8.2.0 || ~8.3.0",
19-
"azjezz/psl": "^2.5"
19+
"azjezz/psl": "^2.5",
20+
"php-soap/xml": "^1.6.0"
2021
},
2122
"autoload-dev": {
2223
"psr-4": {

src/Metadata/Model/TypeMeta.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ final class TypeMeta
6868
*/
6969
private $isList;
7070

71+
/**
72+
* @var bool|null
73+
*/
74+
private $isRepeatingElement;
75+
7176
/**
7277
* @var bool|null
7378
*/
@@ -123,6 +128,20 @@ final class TypeMeta
123128
*/
124129
private $isQualified;
125130

131+
/**
132+
* The soap-enc array-type information
133+
*
134+
* @var array{type: non-empty-string, itemType: non-empty-string, namespace: non-empty-string}|null
135+
*/
136+
private $arrayType;
137+
138+
/**
139+
* The name of the internal array nodes for soap-enc arrays
140+
*
141+
* @var string|null
142+
*/
143+
private $arrayNodeName;
144+
126145
/**
127146
* @return Option<bool>
128147
*/
@@ -295,6 +314,22 @@ public function withIsList(?bool $isList): self
295314
return $new;
296315
}
297316

317+
/**
318+
* @return Option<bool>
319+
*/
320+
public function isRepeatingElement(): Option
321+
{
322+
return from_nullable($this->isRepeatingElement);
323+
}
324+
325+
public function withIsRepeatingElement(?bool $isRepeatingElement): self
326+
{
327+
$new = clone $this;
328+
$new->isRepeatingElement = $isRepeatingElement;
329+
330+
return $new;
331+
}
332+
298333
/**
299334
* @return Option<bool>
300335
*/
@@ -484,4 +519,45 @@ public function withIsQualified(?bool $qualified): self
484519

485520
return $new;
486521
}
522+
523+
/**
524+
* @return Option<array{type: non-empty-string, itemType: non-empty-string, namespace: non-empty-string}>
525+
*/
526+
public function arrayType(): Option
527+
{
528+
return from_nullable($this->arrayType);
529+
}
530+
531+
/**
532+
* @throws CoercionException
533+
*/
534+
public function withArrayType(?array $arrayType): self
535+
{
536+
$new = clone $this;
537+
$new->arrayType = optional(
538+
shape([
539+
'type' => non_empty_string(),
540+
'itemType' => non_empty_string(),
541+
'namespace' => non_empty_string(),
542+
], true)
543+
)->coerce($arrayType);
544+
545+
return $new;
546+
}
547+
548+
/**
549+
* @return Option<string>
550+
*/
551+
public function arrayNodeName(): Option
552+
{
553+
return from_nullable($this->arrayNodeName);
554+
}
555+
556+
public function withArrayNodeName(?string $arrayNodeName): self
557+
{
558+
$new = clone $this;
559+
$new->arrayNodeName = $arrayNodeName;
560+
561+
return $new;
562+
}
487563
}

src/Metadata/Model/XsdType.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Soap\Engine\Metadata\Model;
66

7+
use Soap\Xml\Xmlns;
8+
79
final class XsdType
810
{
911
/**
@@ -75,6 +77,19 @@ public static function guess(string $name): self
7577
->withBaseType(self::convertBaseType($name, ''));
7678
}
7779

80+
public static function any(): self
81+
{
82+
return self::guess('anyType')
83+
->withXmlTypeName('anyType')
84+
->withXmlNamespace(Xmlns::xsd()->value())
85+
->withMeta(
86+
static fn (TypeMeta $meta): TypeMeta => $meta
87+
->withIsSimple(true)
88+
->withIsNullable(true)
89+
->withIsNil(true)
90+
);
91+
}
92+
7893
/**
7994
* @return array<string, string>
8095
*/
@@ -86,6 +101,7 @@ public static function fetchAllKnownBaseTypeMappings(): array
86101
'anyuri' => 'string',
87102
'anyxml' => 'string',
88103
'anysimpletype' => 'mixed',
104+
'array' => 'array',
89105
'base64binary' => 'string',
90106
'byte' => 'integer',
91107
'decimal' => 'float',

tests/Unit/Metadata/Model/XsdTypeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function test_it_can_add_known_base_type_and_move_actual_type_to_member_t
5959
static::assertSame('myType', $new->getName());
6060
static::assertSame($baseType, $new->getBaseType());
6161
static::assertSame($baseType, $new->getBaseTypeOrFallbackToName());
62-
static::assertSame([$typeName], $new->getMemberTypes());
62+
static::assertSame($typeName === $baseType ? [] : [$typeName], $new->getMemberTypes());
6363
}
6464
}
6565

0 commit comments

Comments
 (0)