diff --git a/src/Methods/GetPendingDocumentsStatesList.php b/src/Methods/GetPendingDocumentsStatesList.php index ddb063d..44745e3 100644 --- a/src/Methods/GetPendingDocumentsStatesList.php +++ b/src/Methods/GetPendingDocumentsStatesList.php @@ -4,5 +4,5 @@ class GetPendingDocumentsStatesList { - + // TODO: implement. } diff --git a/src/XML/MedidocXMLService.php b/src/XML/MedidocXMLService.php index d7ec995..75b2eb2 100644 --- a/src/XML/MedidocXMLService.php +++ b/src/XML/MedidocXMLService.php @@ -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; } } diff --git a/src/XML/Nodes/Body.php b/src/XML/Nodes/Body.php index 1c7a657..2200b78 100644 --- a/src/XML/Nodes/Body.php +++ b/src/XML/Nodes/Body.php @@ -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 []; } } diff --git a/src/XML/Nodes/Envelope.php b/src/XML/Nodes/Envelope.php index 2202260..43f078b 100644 --- a/src/XML/Nodes/Envelope.php +++ b/src/XML/Nodes/Envelope.php @@ -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([ - - // - 'name' => XML_NS::envelope->node('Header'), - 'value' => [ - //http://tempuri.org/IMedidoc/CheckConnection - [ - 'name' => XML_NS::addressing->node('Action'), - 'attributes' => [ - XML_NS::envelope->attribute('mustUnderstand') => '1', - ], - 'value' => 'http://tempuri.org/IMedidoc/' . $this->method->name() - ], - - //urn:uuid:90e8ecbb-fcf2-4fab-bf0d-6f1ed5ad6166 - [ - 'name' => XML_NS::addressing->node('MessageID'), - 'value' => 'urn:uuid:' . Uuid::uuid4(), - ], + public function namespace(): ?XML_NS + { + return XML_NS::envelope; + } - // - // http://www.w3.org/2005/08/addressing/anonymous - // - [ - '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 []; + } - //https://test.medidoc.ch/WebServices/MedidocAccessV3.svc - [ - '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() + ]; } } diff --git a/src/XML/Nodes/Envelope/Action.php b/src/XML/Nodes/Envelope/Action.php new file mode 100644 index 0000000..4bfa8aa --- /dev/null +++ b/src/XML/Nodes/Envelope/Action.php @@ -0,0 +1,30 @@ +attribute('mustUnderstand') => '1', + ]; + } + + public function value(): string|array + { + return 'http://tempuri.org/IMedidoc/' . $this->method->name(); + } +} diff --git a/src/XML/Nodes/Envelope/MessageID.php b/src/XML/Nodes/Envelope/MessageID.php new file mode 100644 index 0000000..88fb216 --- /dev/null +++ b/src/XML/Nodes/Envelope/MessageID.php @@ -0,0 +1,25 @@ + XML_NS::addressing->node('Address'), + 'value' => 'http://www.w3.org/2005/08/addressing/anonymous' + ]; + } +} diff --git a/src/XML/Nodes/Envelope/Security.php b/src/XML/Nodes/Envelope/Security.php new file mode 100644 index 0000000..75599b5 --- /dev/null +++ b/src/XML/Nodes/Envelope/Security.php @@ -0,0 +1,72 @@ +attribute('mustUnderstand') => '1' + ]; + } + + public function value(): array + { + return [ + + // + // 2023-03-21T08:35:52Z + // 2023-03-21T08:40:52Z + // + + [ + '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(), + ] + + ] + ], + + // + // urn:uuid:64ef4932-5c3f-4acd-bf81-183ebab4bef3 + // + + [ + '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(), + ], + + ] + ], + ]; + } +} diff --git a/src/XML/Nodes/Envelope/To.php b/src/XML/Nodes/Envelope/To.php new file mode 100644 index 0000000..6fd0f0d --- /dev/null +++ b/src/XML/Nodes/Envelope/To.php @@ -0,0 +1,27 @@ +attribute('mustUnderstand') => '1' + ]; + } + + public function value(): string + { + return 'https://test.medidoc.ch/WebServices/MedidocAccessV3.svc'; + } +} diff --git a/src/XML/Nodes/Node.php b/src/XML/Nodes/Node.php new file mode 100644 index 0000000..efaf900 --- /dev/null +++ b/src/XML/Nodes/Node.php @@ -0,0 +1,33 @@ +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(), + ]); + } + +} diff --git a/src/XML/Nodes/NodeBase.php b/src/XML/Nodes/NodeBase.php deleted file mode 100644 index e910fc0..0000000 --- a/src/XML/Nodes/NodeBase.php +++ /dev/null @@ -1,13 +0,0 @@ -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; } }