Skip to content

Commit

Permalink
WIP. Create basic node class, refactor from array to nodes.
Browse files Browse the repository at this point in the history
  • Loading branch information
rico committed Mar 21, 2023
1 parent e27ea2a commit 6266edf
Show file tree
Hide file tree
Showing 12 changed files with 258 additions and 71 deletions.
2 changes: 1 addition & 1 deletion src/Methods/GetPendingDocumentsStatesList.php
Expand Up @@ -4,5 +4,5 @@

class GetPendingDocumentsStatesList
{

// TODO: implement.
}
2 changes: 1 addition & 1 deletion src/XML/MedidocXMLService.php
Expand Up @@ -22,7 +22,7 @@ public function __construct()
private function initNamespacesMap()
{
foreach (XML_NS::cases() as $namespace) {
$this->namespaceMap[$namespace->value] = $namespace->getName();
$this->namespaceMap[$namespace->value] = $namespace->name;
}
}

Expand Down
19 changes: 12 additions & 7 deletions src/XML/Nodes/Body.php
Expand Up @@ -2,17 +2,22 @@

namespace Smartprax\Medidoc\XML\Nodes;

use Sabre\Xml\Writer;
use Smartprax\Medidoc\XML\XML_NS;

class Body extends NodeBase
class Body extends Node
{
public function namespace(): ?XML_NS
{
return XML_NS::envelope;
}

public function attributes(): array
{
return [];
}

public function xmlSerialize(Writer $writer): void
public function value(): array
{
$writer->write([
'name' => XML_NS::envelope->node('Body'),
'value' => $this->method
]);
return [];
}
}
70 changes: 27 additions & 43 deletions src/XML/Nodes/Envelope.php
Expand Up @@ -3,55 +3,39 @@
namespace Smartprax\Medidoc\XML\Nodes;

use Ramsey\Uuid\Uuid;
use Sabre\Xml\Writer;
use Smartprax\Medidoc\Methods\AbstractMethod;
use Smartprax\Medidoc\XML\Nodes\Envelope\Action;
use Smartprax\Medidoc\XML\Nodes\Envelope\MessageID;
use Smartprax\Medidoc\XML\Nodes\Envelope\ReplyTo;
use Smartprax\Medidoc\XML\Nodes\Envelope\Security;
use Smartprax\Medidoc\XML\Nodes\Envelope\To;
use Smartprax\Medidoc\XML\XML_NS;

class Envelope extends NodeBase
class Envelope extends Node
{
public function __construct(
protected AbstractMethod $method
) {}

public function xmlSerialize(Writer $writer): void
{
$writer->write([

// <envelope:Header>
'name' => XML_NS::envelope->node('Header'),
'value' => [

//<addressing:Action envelope:mustUnderstand="1">http://tempuri.org/IMedidoc/CheckConnection</addressing:Action>
[
'name' => XML_NS::addressing->node('Action'),
'attributes' => [
XML_NS::envelope->attribute('mustUnderstand') => '1',
],
'value' => 'http://tempuri.org/IMedidoc/' . $this->method->name()
],

//<addressing:MessageID>urn:uuid:90e8ecbb-fcf2-4fab-bf0d-6f1ed5ad6166</addressing:MessageID>
[
'name' => XML_NS::addressing->node('MessageID'),
'value' => 'urn:uuid:' . Uuid::uuid4(),
],
public function namespace(): ?XML_NS
{
return XML_NS::envelope;
}

// <adressing:ReplyTo>
// <addressing:Address>http://www.w3.org/2005/08/addressing/anonymous</addressing:Address>
// </adressing:ReplyTo>
[
'name' => XML_NS::addressing->node('ReplyTo'),
'value' => [
'name' => XML_NS::addressing->node('Address'),
'value' => 'http://www.w3.org/2005/08/addressing/anonymous'
],
],
public function attributes(): array
{
return [];
}

//<addressing:To envelope:mustUnderstand="1">https://test.medidoc.ch/WebServices/MedidocAccessV3.svc</addressing:To>
[
'name' => XML_NS::addressing->node('To'),
'attributes' => [
XML_NS::envelope->attribute('mustUnderstand') => '1',
],
'value' => 'https://test.medidoc.ch/WebServices/MedidocAccessV3.svc',
],
]
]);
public function value(): array
{
return [
new Action($this->method),
new MessageID(),
new ReplyTo(),
new To(),
new Security()
];
}
}
30 changes: 30 additions & 0 deletions src/XML/Nodes/Envelope/Action.php
@@ -0,0 +1,30 @@
<?php

namespace Smartprax\Medidoc\XML\Nodes\Envelope;

use Smartprax\Medidoc\Methods\AbstractMethod;
use Smartprax\Medidoc\XML\XML_NS;

class Action extends \Smartprax\Medidoc\XML\Nodes\Node
{

public function __construct(private AbstractMethod $method)
{}

public function namespace(): ?XML_NS
{
return XML_NS::addressing;
}

public function attributes(): array
{
return [
XML_NS::envelope->attribute('mustUnderstand') => '1',
];
}

public function value(): string|array
{
return 'http://tempuri.org/IMedidoc/' . $this->method->name();
}
}
25 changes: 25 additions & 0 deletions src/XML/Nodes/Envelope/MessageID.php
@@ -0,0 +1,25 @@
<?php

namespace Smartprax\Medidoc\XML\Nodes\Envelope;

use Ramsey\Uuid\Uuid;
use Smartprax\Medidoc\XML\XML_NS;

class MessageID extends \Smartprax\Medidoc\XML\Nodes\Node
{

public function namespace(): ?XML_NS
{
return XML_NS::addressing;
}

public function attributes(): array
{
return [];
}

public function value(): string|array
{
return 'urn:uuid:' . Uuid::uuid4();
}
}
28 changes: 28 additions & 0 deletions src/XML/Nodes/Envelope/ReplyTo.php
@@ -0,0 +1,28 @@
<?php

namespace Smartprax\Medidoc\XML\Nodes\Envelope;

use Smartprax\Medidoc\XML\Nodes\Node;
use Smartprax\Medidoc\XML\XML_NS;

class ReplyTo extends Node
{

public function namespace(): ?XML_NS
{
return XML_NS::addressing;
}

public function attributes(): array
{
return [];
}

public function value(): string|array
{
return [
'name' => XML_NS::addressing->node('Address'),
'value' => 'http://www.w3.org/2005/08/addressing/anonymous'
];
}
}
72 changes: 72 additions & 0 deletions src/XML/Nodes/Envelope/Security.php
@@ -0,0 +1,72 @@
<?php

namespace Smartprax\Medidoc\XML\Nodes\Envelope;

use Ramsey\Uuid\Uuid;
use Smartprax\Medidoc\XML\Nodes\Node;
use Smartprax\Medidoc\XML\XML_NS;

class Security extends Node
{

public function namespace(): ?XML_NS
{
return XML_NS::wss_secext;
}

public function attributes(): array
{
return [
XML_NS::envelope->attribute('mustUnderstand') => '1'
];
}

public function value(): array
{
return [

// <u:Timestamp u:Id="_0">
// <u:Created>2023-03-21T08:35:52Z</u:Created>
// <u:Expires>2023-03-21T08:40:52Z</u:Expires>
// </u:Timestamp>

[
'name' => XML_NS::wss_utility->node('Timestamp'),
'attributes' => [
XML_NS::wss_utility->attribute('Id') => '_0',
],
'value' => [
[
'name' => XML_NS::wss_utility->node('Created'),
'value' => \now()->subSeconds(50)->toIso8601String(),
],

[
'name' => XML_NS::wss_utility->node('Expires'),
'value' => \now()->addSeconds(50)->toIso8601String(),
]

]
],

// <c:SecurityContextToken xmlns:c="http://schemas.xmlsoap.org/ws/2005/02/sc"
// u:Id="uuid-126619d5-b159-4b44-bbdf-ed5e8a618d57-1491">
// <c:Identifier>urn:uuid:64ef4932-5c3f-4acd-bf81-183ebab4bef3</c:Identifier>
// </c:SecurityContextToken>

[
'name' => XML_NS::sc->node('SecurityContextToken'),
'attributes' => [
XML_NS::wss_utility->attribute('Id') => 'uuid' . Uuid::uuid4(),
],
'value' => [
[
'name' => XML_NS::sc->node('Identifier'),
'value' => 'urn:uuid:' . Uuid::uuid4(),
],

]
],
];
}
}
27 changes: 27 additions & 0 deletions src/XML/Nodes/Envelope/To.php
@@ -0,0 +1,27 @@
<?php

namespace Smartprax\Medidoc\XML\Nodes\Envelope;

use Smartprax\Medidoc\XML\Nodes\Node;
use Smartprax\Medidoc\XML\XML_NS;

class To extends Node
{

public function namespace(): ?XML_NS
{
return XML_NS::addressing;
}

public function attributes(): array
{
return [
XML_NS::envelope->attribute('mustUnderstand') => '1'
];
}

public function value(): string
{
return 'https://test.medidoc.ch/WebServices/MedidocAccessV3.svc';
}
}
33 changes: 33 additions & 0 deletions src/XML/Nodes/Node.php
@@ -0,0 +1,33 @@
<?php

namespace Smartprax\Medidoc\XML\Nodes;

use Illuminate\Support\Str;
use Sabre\Xml\Writer;
use Sabre\Xml\XmlSerializable;
use Smartprax\Medidoc\Methods\AbstractMethod;
use Smartprax\Medidoc\XML\XML_NS;

abstract class Node implements XmlSerializable
{
abstract public function namespace() : ?XML_NS;
abstract public function attributes() : array;
abstract public function value() : string|array;

public function name() : string
{
return Str::of(get_class($this))
->replace('\\', '/')
->basename();
}

public function xmlSerialize(Writer $writer): void
{
$writer->write([
'name' => $this->namespace() ? $this->namespace()->node($this->name()) : $this->name(),
'attributes' => $this->attributes(),
'value' => $this->value(),
]);
}

}
13 changes: 0 additions & 13 deletions src/XML/Nodes/NodeBase.php

This file was deleted.

8 changes: 2 additions & 6 deletions src/XML/XML_NS.php
Expand Up @@ -8,21 +8,17 @@ enum XML_NS : string
case addressing = 'http://www.w3.org/2005/08/addressing';
case wss_utility = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd';
case wss_secext = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
case sc = 'http://schemas.xmlsoap.org/ws/2005/02/sc';


public function node(string $name): string
{
return '{' . $this->value . '}' . $name;
}

public function getName(): string
{
return \str_replace('_', '-', $this->name);
}

public function attribute(string $name): string
{
return $this->getName() . ':' . $name;
return $this->name . ':' . $name;
}

}

0 comments on commit 6266edf

Please sign in to comment.