Skip to content

Commit

Permalink
Merge pull request #14 from veewee/add-array-info
Browse files Browse the repository at this point in the history
Add soap-enc array information
  • Loading branch information
veewee authored Jun 5, 2024
2 parents 789fb1c + 2fc6b5c commit cbceea3
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 2 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
],
"require": {
"php": "~8.1.0 || ~8.2.0 || ~8.3.0",
"azjezz/psl": "^2.5"
"azjezz/psl": "^2.5",
"php-soap/xml": "^1.6.0"
},
"autoload-dev": {
"psr-4": {
Expand Down
76 changes: 76 additions & 0 deletions src/Metadata/Model/TypeMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ final class TypeMeta
*/
private $isList;

/**
* @var bool|null
*/
private $isRepeatingElement;

/**
* @var bool|null
*/
Expand Down Expand Up @@ -123,6 +128,20 @@ final class TypeMeta
*/
private $isQualified;

/**
* The soap-enc array-type information
*
* @var array{type: non-empty-string, itemType: non-empty-string, namespace: non-empty-string}|null
*/
private $arrayType;

/**
* The name of the internal array nodes for soap-enc arrays
*
* @var string|null
*/
private $arrayNodeName;

/**
* @return Option<bool>
*/
Expand Down Expand Up @@ -295,6 +314,22 @@ public function withIsList(?bool $isList): self
return $new;
}

/**
* @return Option<bool>
*/
public function isRepeatingElement(): Option
{
return from_nullable($this->isRepeatingElement);
}

public function withIsRepeatingElement(?bool $isRepeatingElement): self
{
$new = clone $this;
$new->isRepeatingElement = $isRepeatingElement;

return $new;
}

/**
* @return Option<bool>
*/
Expand Down Expand Up @@ -484,4 +519,45 @@ public function withIsQualified(?bool $qualified): self

return $new;
}

/**
* @return Option<array{type: non-empty-string, itemType: non-empty-string, namespace: non-empty-string}>
*/
public function arrayType(): Option
{
return from_nullable($this->arrayType);
}

/**
* @throws CoercionException
*/
public function withArrayType(?array $arrayType): self
{
$new = clone $this;
$new->arrayType = optional(
shape([
'type' => non_empty_string(),
'itemType' => non_empty_string(),
'namespace' => non_empty_string(),
], true)
)->coerce($arrayType);

return $new;
}

/**
* @return Option<string>
*/
public function arrayNodeName(): Option
{
return from_nullable($this->arrayNodeName);
}

public function withArrayNodeName(?string $arrayNodeName): self
{
$new = clone $this;
$new->arrayNodeName = $arrayNodeName;

return $new;
}
}
16 changes: 16 additions & 0 deletions src/Metadata/Model/XsdType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Soap\Engine\Metadata\Model;

use Soap\Xml\Xmlns;

final class XsdType
{
/**
Expand Down Expand Up @@ -75,6 +77,19 @@ public static function guess(string $name): self
->withBaseType(self::convertBaseType($name, ''));
}

public static function any(): self
{
return self::guess('anyType')
->withXmlTypeName('anyType')
->withXmlNamespace(Xmlns::xsd()->value())
->withMeta(
static fn (TypeMeta $meta): TypeMeta => $meta
->withIsSimple(true)
->withIsNullable(true)
->withIsNil(true)
);
}

/**
* @return array<string, string>
*/
Expand All @@ -86,6 +101,7 @@ public static function fetchAllKnownBaseTypeMappings(): array
'anyuri' => 'string',
'anyxml' => 'string',
'anysimpletype' => 'mixed',
'array' => 'array',
'base64binary' => 'string',
'byte' => 'integer',
'decimal' => 'float',
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Metadata/Model/XsdTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function test_it_can_add_known_base_type_and_move_actual_type_to_member_t
static::assertSame('myType', $new->getName());
static::assertSame($baseType, $new->getBaseType());
static::assertSame($baseType, $new->getBaseTypeOrFallbackToName());
static::assertSame([$typeName], $new->getMemberTypes());
static::assertSame($typeName === $baseType ? [] : [$typeName], $new->getMemberTypes());
}
}

Expand Down

0 comments on commit cbceea3

Please sign in to comment.