Skip to content

Commit

Permalink
Collect target namespace instead of schema - cause there might not be…
Browse files Browse the repository at this point in the history
… a schema linked
  • Loading branch information
veewee committed Jun 3, 2024
1 parent 62d134f commit 63b29d4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
21 changes: 8 additions & 13 deletions src/Schema/MetaInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,49 +13,44 @@ class MetaInformation
{
/**
* Links to the schema in which this information is contained.
* This context schema can be used to resolve e.g. a type.
* This context schema can be used to resolve an un-prefixed qname type.
*
* Example:
* wsdl:arrayType="int"
*
* value = "int"
* contextSchema = xsd : "http://www.w3.org/2001/XMLSchema"
* schema = wsdl : "http://schemas.xmlsoap.org/wsdl/"
*
* The type would be xsd:int
*/
private Schema $contextSchema;

/**
* Links to the schema that holds the declaration of the meta information type.
* The meta information would be located inside the "schema-prefix:name" attribute.
*/
private Schema $schema;
private string $namespaceURI;

private string $name;

private string $value;

public function __construct(
Schema $schema,
Schema $contextSchema,
string $namespaceURI,
string $name,
string $value
) {
$this->schema = $schema;
$this->contextSchema = $contextSchema;
$this->namespaceURI = $namespaceURI;
$this->name = $name;
$this->value = $value;
}

public function getSchema(): Schema
public function getContextSchema(): Schema
{
return $this->schema;
return $this->contextSchema;
}

public function getContextSchema(): Schema
public function getNamespaceURI(): string
{
return $this->contextSchema;
return $this->namespaceURI;
}

public function getName(): string
Expand Down
2 changes: 1 addition & 1 deletion src/SchemaReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ private function loadMetaAttributesForElement(SchemaItem $item, \DOMElement $nod
foreach ($node->attributes as $attr) {
if (null !== $attr->namespaceURI && self::XSD_NS !== $attr->namespaceURI) {
$meta[] = new MetaInformation(
$this->findSchemaForNamespace($item->getSchema(), $attr->namespaceURI),
$this->findSchemaForNamespace($item->getSchema(), $attr->parentNode->namespaceURI),
$attr->namespaceURI,
$attr->name,
$attr->value
);
Expand Down
7 changes: 4 additions & 3 deletions tests/AttributesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ public function testMetaInformation(): void
self::assertCount(1, $meta);
self::assertEquals('meta', $meta[0]->getName());
self::assertEquals('hello', $meta[0]->getValue());
self::assertSame($myAttribute->getSchema(), $meta[0]->getSchema());
self::assertEquals('http://www.example.com', $meta[0]->getNamespaceURI());
self::assertSame(SchemaReader::XSD_NS, $meta[0]->getContextSchema()->getTargetNamespace());
}

public function testExternalSchemaReferencingMetaInformationPrefixed(): void
Expand Down Expand Up @@ -191,7 +192,7 @@ public function testExternalSchemaReferencingMetaInformationPrefixed(): void
self::assertEquals('xs:string', $meta[0]->getValue());

$refAttr = $schema->findAttribute('metaType', 'http://www.ref.com');
self::assertSame($refAttr->getSchema(), $meta[0]->getSchema());
self::assertSame($refAttr->getSchema()->getTargetNamespace(), $meta[0]->getNamespaceURI());
self::assertSame(SchemaReader::XSD_NS, $meta[0]->getContextSchema()->getTargetNamespace());
}

Expand Down Expand Up @@ -222,7 +223,7 @@ public function testExternalSchemaReferencingMetaInformationUnprefixed(): void
self::assertEquals('string', $meta[0]->getValue());

$refAttr = $schema->findAttribute('metaType', 'http://www.ref.com');
self::assertSame($refAttr->getSchema(), $meta[0]->getSchema());
self::assertSame($refAttr->getSchema()->getTargetNamespace(), $meta[0]->getNamespaceURI());
self::assertSame(SchemaReader::XSD_NS, $meta[0]->getContextSchema()->getTargetNamespace());
}
}

0 comments on commit 63b29d4

Please sign in to comment.