-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from veewee/class-map
Introduce a class-map concept (similar to ext-soap-engine)
- Loading branch information
Showing
6 changed files
with
165 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Soap\Encoding\ClassMap; | ||
|
||
final class ClassMap | ||
{ | ||
/** | ||
* @param non-empty-string $xmlNamespace | ||
* @param non-empty-string $wsdlType | ||
* @param class-string $phpClassName | ||
*/ | ||
public function __construct( | ||
private readonly string $xmlNamespace, | ||
private readonly string $wsdlType, | ||
private readonly string $phpClassName | ||
) { | ||
} | ||
|
||
/** | ||
* @return class-string | ||
*/ | ||
public function getPhpClassName(): string | ||
{ | ||
return $this->phpClassName; | ||
} | ||
|
||
/** | ||
* @return non-empty-string | ||
*/ | ||
public function getXmlType(): string | ||
{ | ||
return $this->wsdlType; | ||
} | ||
|
||
/** | ||
* @return non-empty-string | ||
*/ | ||
public function getXmlNamespace(): string | ||
{ | ||
return $this->xmlNamespace; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Soap\Encoding\ClassMap; | ||
|
||
use ArrayIterator; | ||
use IteratorAggregate; | ||
use Soap\Encoding\Formatter\QNameFormatter; | ||
|
||
/** | ||
* @implements IteratorAggregate<string, ClassMap> | ||
*/ | ||
final class ClassMapCollection implements IteratorAggregate | ||
{ | ||
/** | ||
* @var array<string, ClassMap> | ||
*/ | ||
private array $classMaps = []; | ||
|
||
public function __construct(ClassMap ... $classMaps) | ||
{ | ||
foreach ($classMaps as $classMap) { | ||
$this->set($classMap); | ||
} | ||
} | ||
|
||
public function set(ClassMap $classMap): self | ||
{ | ||
$qname = (new QNameFormatter())($classMap->getXmlNamespace(), $classMap->getXmlType()); | ||
$this->classMaps[$qname] = $classMap; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return ArrayIterator<string, ClassMap> | ||
*/ | ||
public function getIterator(): ArrayIterator | ||
{ | ||
return new ArrayIterator($this->classMaps); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Soap\Encoding\Test\Unit\ClassMap; | ||
|
||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\TestCase; | ||
use Soap\Encoding\ClassMap\ClassMap; | ||
use Soap\Encoding\ClassMap\ClassMapCollection; | ||
|
||
#[CoversClass(ClassMapCollection::class)] | ||
final class ClassMapCollectionTest extends TestCase | ||
{ | ||
public function test_it_tests_class_maps(): void | ||
{ | ||
$classMap = new ClassMapCollection( | ||
$item1 = new ClassMap('uri:xx', 'wsdlType', 'phpType'), | ||
new ClassMap('uri:xx', 'double', 'double'), | ||
$item2 = new ClassMap('uri:xx', 'double', 'double'), | ||
); | ||
|
||
static::assertCount(2, $classMap); | ||
static::assertSame([ | ||
'{uri:xx:wsdltype}' => $item1, | ||
'{uri:xx:double}' => $item2, | ||
], iterator_to_array($classMap)); | ||
} | ||
|
||
public function test_it_can_add_types(): void | ||
{ | ||
$classMap = new ClassMapCollection(); | ||
$classMap->set($item1 = new ClassMap('uri:xx', 'wsdlType', 'phpType')); | ||
$classMap->set($item2 = new ClassMap('uri:xx', 'wsdlType', 'phpType')); | ||
|
||
static::assertSame([ | ||
'{uri:xx:wsdltype}' => $item2, | ||
], iterator_to_array($classMap)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Soap\Encoding\Test\Unit\ClassMap; | ||
|
||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\TestCase; | ||
use Soap\Encoding\ClassMap\ClassMap; | ||
|
||
#[CoversClass(ClassMap::class)] | ||
final class ClassMapTest extends TestCase | ||
{ | ||
public function test_it_tests_class_maps(): void | ||
{ | ||
$classMap = new ClassMap('uri://xx', 'wsdlType', 'phpType'); | ||
|
||
static::assertSame('uri://xx', $classMap->getXmlNamespace()); | ||
static::assertSame('wsdlType', $classMap->getXmlType()); | ||
static::assertSame('phpType', $classMap->getPhpClassName()); | ||
} | ||
} |