From 4d39ec598ddfaff63a55a6e36512e34da716a9bb Mon Sep 17 00:00:00 2001 From: Giovanni Piemontese <22853912+ynnoig@users.noreply.github.com> Date: Thu, 9 Nov 2023 21:57:56 +0100 Subject: [PATCH] chore(style): adjusted php-cs-fixer indent --- .php-cs-fixer.php | 51 +- .../Authentication/AuthenticatorInterface.php | 8 +- .../SimpleSharedSecretAuthenticator.php | 22 +- src/CXml/Builder.php | 288 +++++----- src/CXml/Builder/OrderRequestBuilder.php | 520 +++++++++--------- .../Builder/ProductActivityMessageBuilder.php | 78 +-- .../Builder/PunchOutOrderMessageBuilder.php | 346 ++++++------ src/CXml/Context.php | 142 ++--- .../CredentialRepositoryInterface.php | 8 +- src/CXml/Credential/Registry.php | 82 +-- .../Document/DocumentRegistryInterface.php | 4 +- src/CXml/Endpoint.php | 90 +-- .../CXmlAuthenticationInvalidException.php | 8 +- .../CXmlCredentialInvalidException.php | 20 +- src/CXml/Exception/CXmlException.php | 8 +- .../CXmlHandlerNotFoundException.php | 8 +- src/CXml/Handler/HandlerInterface.php | 10 +- src/CXml/Handler/HandlerRegistry.php | 64 +-- src/CXml/Handler/HandlerRegistryInterface.php | 2 +- .../SelfAwareProfileRequestHandler.php | 66 +-- ...icStartPagePunchOutSetupRequestHandler.php | 34 +- .../CXmlWrappingNodeJmsEventSubscriber.php | 238 ++++---- src/CXml/Jms/JmsDateTimeHandler.php | 88 +-- src/CXml/Model/Address.php | 196 +++---- src/CXml/Model/BillTo.php | 26 +- src/CXml/Model/CXml.php | 262 ++++----- src/CXml/Model/CarrierIdentifier.php | 70 +-- src/CXml/Model/Classification.php | 26 +- src/CXml/Model/Comment.php | 94 ++-- src/CXml/Model/Contact.php | 104 ++-- src/CXml/Model/Country.php | 44 +- src/CXml/Model/Credential.php | 108 ++-- src/CXml/Model/Date.php | 68 +-- src/CXml/Model/Description.php | 38 +- src/CXml/Model/DocumentReference.php | 26 +- src/CXml/Model/Extrinsic.php | 42 +- src/CXml/Model/ExtrinsicsTrait.php | 92 ++-- src/CXml/Model/Header.php | 72 +-- src/CXml/Model/IdReference.php | 42 +- src/CXml/Model/IdReferencesTrait.php | 60 +- src/CXml/Model/Inventory.php | 76 +-- src/CXml/Model/InventoryQuantity.php | 42 +- src/CXml/Model/ItemDetail.php | 294 +++++----- src/CXml/Model/ItemId.php | 82 +-- src/CXml/Model/ItemIn.php | 102 ++-- src/CXml/Model/ItemOut.php | 210 +++---- src/CXml/Model/Message/Message.php | 114 ++-- .../Model/Message/ProductActivityDetail.php | 92 ++-- .../Model/Message/ProductActivityHeader.php | 80 +-- .../Model/Message/ProductActivityMessage.php | 82 +-- .../Model/Message/PunchOutOrderMessage.php | 102 ++-- .../Message/PunchOutOrderMessageHeader.php | 174 +++--- src/CXml/Model/Money.php | 72 +-- src/CXml/Model/MoneyWrapper.php | 24 +- src/CXml/Model/MultilanguageString.php | 72 +-- src/CXml/Model/Option.php | 26 +- src/CXml/Model/OrderReference.php | 88 +-- src/CXml/Model/Party.php | 44 +- src/CXml/Model/PayloadIdentity.php | 30 +- src/CXml/Model/PostalAddress.php | 236 ++++---- src/CXml/Model/Request/ConfirmationHeader.php | 98 ++-- .../Model/Request/ConfirmationRequest.php | 60 +- src/CXml/Model/Request/OrderRequest.php | 100 ++-- src/CXml/Model/Request/OrderRequestHeader.php | 384 ++++++------- .../Model/Request/PunchOutSetupRequest.php | 216 ++++---- src/CXml/Model/Request/Request.php | 102 ++-- src/CXml/Model/Request/ShipNoticeHeader.php | 182 +++--- src/CXml/Model/Request/ShipNoticeRequest.php | 144 ++--- .../Model/Request/StatusUpdateRequest.php | 70 +-- src/CXml/Model/Response/ProfileResponse.php | 82 +-- .../Model/Response/PunchOutSetupResponse.php | 16 +- src/CXml/Model/Response/Response.php | 82 +-- src/CXml/Model/SelectedItem.php | 24 +- src/CXml/Model/ShipControl.php | 108 ++-- src/CXml/Model/ShipNoticePortion.php | 36 +- src/CXml/Model/ShipTo.php | 74 +-- src/CXml/Model/ShipmentIdentifier.php | 94 ++-- src/CXml/Model/Shipping.php | 44 +- src/CXml/Model/ShippingContractNumber.php | 16 +- src/CXml/Model/Status.php | 84 +-- src/CXml/Model/SupplierOrderInfo.php | 44 +- src/CXml/Model/Tax.php | 44 +- src/CXml/Model/Transaction.php | 50 +- src/CXml/Model/TransportInformation.php | 24 +- src/CXml/Model/UnitOfMeasure.php | 24 +- src/CXml/Model/Url.php | 26 +- .../Payload/DefaultPayloadIdentityFactory.php | 64 +-- .../PayloadIdentityFactoryInterface.php | 2 +- .../Exception/CXmlProcessException.php | 8 +- src/CXml/Processor/HeaderProcessor.php | 86 +-- src/CXml/Processor/Processor.php | 422 +++++++------- src/CXml/Serializer.php | 102 ++-- src/CXml/Validation/DtdValidator.php | 152 ++--- .../Exception/CXmlInvalidException.php | 56 +- .../Builder/OrderRequestBuilderTest.php | 66 +-- tests/CXmlTest/Model/OrderRequestTest.php | 236 ++++---- .../Model/ProductActivityMessageTest.php | 90 +-- .../Model/PunchOutSetupRequestTest.php | 200 +++---- .../Model/PunchoutOrderMessageTest.php | 136 ++--- tests/CXmlTest/Model/SerializerTest.php | 374 ++++++------- .../CXmlTest/Model/ShipNoticeRequestTest.php | 100 ++-- .../Model/StatusUpdateRequestTest.php | 84 +-- .../DefaultPayloadIdentityFactoryTest.php | 18 +- .../Validation/MessageValidatorTest.php | 46 +- 104 files changed, 5033 insertions(+), 5034 deletions(-) diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index b7f817d..cb04617 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -1,35 +1,34 @@ in(__DIR__.'/src') - ->in(__DIR__.'/tests') + ->in(__DIR__.'/src') + ->in(__DIR__.'/tests') ; $config = new PhpCsFixer\Config(); return $config - ->setRiskyAllowed(true) - ->setRules([ - '@PSR2' => true, - '@PSR1' => true, - '@PhpCsFixer' => true, - '@Symfony' => true, - '@Symfony:risky' => false, - 'native_function_invocation' => [ - 'include' => [\PhpCsFixer\Fixer\FunctionNotation\NativeFunctionInvocationFixer::SET_INTERNAL], - 'scope' => 'namespaced', - 'strict' => false, - ], - 'void_return' => true, - 'random_api_migration' => true, - 'pow_to_exponentiation' => true, - 'combine_nested_dirname' => true, - 'phpdoc_separation' => false, - '@PHP74Migration' => true, - 'global_namespace_import' => [ - 'import_classes' => false, - ], - ]) - ->setIndent("\t") - ->setFinder($finder) + ->setRiskyAllowed(true) + ->setRules([ + '@PSR2' => true, + '@PSR1' => true, + '@PhpCsFixer' => true, + '@Symfony' => true, + '@Symfony:risky' => false, + 'native_function_invocation' => [ + 'include' => [\PhpCsFixer\Fixer\FunctionNotation\NativeFunctionInvocationFixer::SET_INTERNAL], + 'scope' => 'namespaced', + 'strict' => false, + ], + 'void_return' => true, + 'random_api_migration' => true, + 'pow_to_exponentiation' => true, + 'combine_nested_dirname' => true, + 'phpdoc_separation' => false, + '@PHP74Migration' => true, + 'global_namespace_import' => [ + 'import_classes' => false, + ], + ]) + ->setFinder($finder) ; diff --git a/src/CXml/Authentication/AuthenticatorInterface.php b/src/CXml/Authentication/AuthenticatorInterface.php index 4bbb714..52e2759 100644 --- a/src/CXml/Authentication/AuthenticatorInterface.php +++ b/src/CXml/Authentication/AuthenticatorInterface.php @@ -8,8 +8,8 @@ interface AuthenticatorInterface { - /** - * @throws CXmlAuthenticationInvalidException - */ - public function authenticate(Header $header, Context $context): void; + /** + * @throws CXmlAuthenticationInvalidException + */ + public function authenticate(Header $header, Context $context): void; } diff --git a/src/CXml/Authentication/SimpleSharedSecretAuthenticator.php b/src/CXml/Authentication/SimpleSharedSecretAuthenticator.php index eed7f05..b042528 100644 --- a/src/CXml/Authentication/SimpleSharedSecretAuthenticator.php +++ b/src/CXml/Authentication/SimpleSharedSecretAuthenticator.php @@ -8,17 +8,17 @@ class SimpleSharedSecretAuthenticator implements AuthenticatorInterface { - private string $sharedSecret; + private string $sharedSecret; - public function __construct(string $sharedSecret) - { - $this->sharedSecret = $sharedSecret; - } + public function __construct(string $sharedSecret) + { + $this->sharedSecret = $sharedSecret; + } - public function authenticate(Header $header, Context $context): void - { - if ($this->sharedSecret !== $header->getSender()->getCredential()->getSharedSecret()) { - throw new CXmlAuthenticationInvalidException($header->getSender()->getCredential()); - } - } + public function authenticate(Header $header, Context $context): void + { + if ($this->sharedSecret !== $header->getSender()->getCredential()->getSharedSecret()) { + throw new CXmlAuthenticationInvalidException($header->getSender()->getCredential()); + } + } } diff --git a/src/CXml/Builder.php b/src/CXml/Builder.php index 6af6fa5..279f28d 100644 --- a/src/CXml/Builder.php +++ b/src/CXml/Builder.php @@ -20,148 +20,148 @@ class Builder { - private PayloadIdentityFactoryInterface $payloadIdentityFactory; - - private ?PayloadInterface $payload = null; - private Credential $from; - private Credential $to; - private Credential $sender; - private ?string $senderUserAgent; - private ?Status $status = null; - private ?string $locale; - - private function __construct(string $senderUserAgent, string $locale = null, PayloadIdentityFactoryInterface $payloadIdentityFactory = null) - { - $this->locale = $locale; - $this->payloadIdentityFactory = $payloadIdentityFactory ?? new DefaultPayloadIdentityFactory(); - $this->senderUserAgent = $senderUserAgent; - } - - public static function create(string $senderUserAgent = 'cxml-php UserAgent', string $locale = null, PayloadIdentityFactoryInterface $payloadIdentityFactory = null): self - { - return new self($senderUserAgent, $locale, $payloadIdentityFactory); - } - - public function payload(PayloadInterface $payload = null): self - { - $this->payload = $payload; - - return $this; - } - - public function status(Status $status): self - { - $this->status = $status; - - return $this; - } - - public function sender(Credential $sender): self - { - $this->sender = $sender; - - return $this; - } - - public function setSenderUserAgent(?string $senderUserAgent): self - { - $this->senderUserAgent = $senderUserAgent; - - return $this; - } - - public function from(Credential $from): self - { - $this->from = $from; - - return $this; - } - - public function to(Credential $to): self - { - $this->to = $to; - - return $this; - } - - private function buildHeader(): Header - { - if (!isset($this->from)) { - throw new \LogicException("No 'from' has been set. Necessary for building a header."); - } - if (!isset($this->to)) { - throw new \LogicException("No 'to' has been set. Necessary for building a header."); - } - if (!isset($this->sender)) { - throw new \LogicException("No 'sender' has been set. Necessary for building a header."); - } - - return new Header( - new Party($this->from), - new Party($this->to), - new Party($this->sender, $this->senderUserAgent) - ); - } - - /** - * @throws CXmlException - */ - public function build(string $deploymentMode = null): CXml - { - switch (true) { - case $this->payload instanceof RequestPayloadInterface: - /** @noinspection PhpParamsInspection */ - $cXml = CXml::forRequest( - $this->payloadIdentityFactory->newPayloadIdentity(), - new Request($this->payload, $this->status, null, $deploymentMode), - $this->buildHeader(), - $this->locale - ); - break; - - case $this->payload instanceof MessagePayloadInterface: - /** @noinspection PhpParamsInspection */ - $cXml = CXml::forMessage( - $this->payloadIdentityFactory->newPayloadIdentity(), - new Message($this->payload, $this->status), - $this->buildHeader(), - $this->locale - ); - break; - - case $this->payload instanceof ResponsePayloadInterface: - $status = $this->status; - - // response requires a status - if (null === $status) { - $status = new Status(); // 200 OK - } - - /** @noinspection PhpParamsInspection */ - $cXml = CXml::forResponse( - $this->payloadIdentityFactory->newPayloadIdentity(), - new Response($status, $this->payload), - $this->locale - ); - break; - - default: - // simple status ping-pong response - if ($this->status) { - $cXml = CXml::forResponse( - $this->payloadIdentityFactory->newPayloadIdentity(), - new Response($this->status), - $this->locale - ); - - break; - } - } - - if (!isset($cXml)) { - throw new CXmlException('Neither payload (Request, Message, Response) was set.'); - } - - return $cXml; - } + private PayloadIdentityFactoryInterface $payloadIdentityFactory; + + private ?PayloadInterface $payload = null; + private Credential $from; + private Credential $to; + private Credential $sender; + private ?string $senderUserAgent; + private ?Status $status = null; + private ?string $locale; + + private function __construct(string $senderUserAgent, string $locale = null, PayloadIdentityFactoryInterface $payloadIdentityFactory = null) + { + $this->locale = $locale; + $this->payloadIdentityFactory = $payloadIdentityFactory ?? new DefaultPayloadIdentityFactory(); + $this->senderUserAgent = $senderUserAgent; + } + + public static function create(string $senderUserAgent = 'cxml-php UserAgent', string $locale = null, PayloadIdentityFactoryInterface $payloadIdentityFactory = null): self + { + return new self($senderUserAgent, $locale, $payloadIdentityFactory); + } + + public function payload(PayloadInterface $payload = null): self + { + $this->payload = $payload; + + return $this; + } + + public function status(Status $status): self + { + $this->status = $status; + + return $this; + } + + public function sender(Credential $sender): self + { + $this->sender = $sender; + + return $this; + } + + public function setSenderUserAgent(?string $senderUserAgent): self + { + $this->senderUserAgent = $senderUserAgent; + + return $this; + } + + public function from(Credential $from): self + { + $this->from = $from; + + return $this; + } + + public function to(Credential $to): self + { + $this->to = $to; + + return $this; + } + + private function buildHeader(): Header + { + if (!isset($this->from)) { + throw new \LogicException("No 'from' has been set. Necessary for building a header."); + } + if (!isset($this->to)) { + throw new \LogicException("No 'to' has been set. Necessary for building a header."); + } + if (!isset($this->sender)) { + throw new \LogicException("No 'sender' has been set. Necessary for building a header."); + } + + return new Header( + new Party($this->from), + new Party($this->to), + new Party($this->sender, $this->senderUserAgent) + ); + } + + /** + * @throws CXmlException + */ + public function build(string $deploymentMode = null): CXml + { + switch (true) { + case $this->payload instanceof RequestPayloadInterface: + /** @noinspection PhpParamsInspection */ + $cXml = CXml::forRequest( + $this->payloadIdentityFactory->newPayloadIdentity(), + new Request($this->payload, $this->status, null, $deploymentMode), + $this->buildHeader(), + $this->locale + ); + break; + + case $this->payload instanceof MessagePayloadInterface: + /** @noinspection PhpParamsInspection */ + $cXml = CXml::forMessage( + $this->payloadIdentityFactory->newPayloadIdentity(), + new Message($this->payload, $this->status), + $this->buildHeader(), + $this->locale + ); + break; + + case $this->payload instanceof ResponsePayloadInterface: + $status = $this->status; + + // response requires a status + if (null === $status) { + $status = new Status(); // 200 OK + } + + /** @noinspection PhpParamsInspection */ + $cXml = CXml::forResponse( + $this->payloadIdentityFactory->newPayloadIdentity(), + new Response($status, $this->payload), + $this->locale + ); + break; + + default: + // simple status ping-pong response + if ($this->status) { + $cXml = CXml::forResponse( + $this->payloadIdentityFactory->newPayloadIdentity(), + new Response($this->status), + $this->locale + ); + + break; + } + } + + if (!isset($cXml)) { + throw new CXmlException('Neither payload (Request, Message, Response) was set.'); + } + + return $cXml; + } } diff --git a/src/CXml/Builder/OrderRequestBuilder.php b/src/CXml/Builder/OrderRequestBuilder.php index 6efa5c0..b91d4e2 100644 --- a/src/CXml/Builder/OrderRequestBuilder.php +++ b/src/CXml/Builder/OrderRequestBuilder.php @@ -25,264 +25,264 @@ class OrderRequestBuilder { - private array $items = []; - private string $orderId; - private \DateTimeInterface $orderDate; - private int $total = 0; - private string $currency; - private array $comments = []; - private array $contacts = []; - private ?ShipTo $shipTo = null; - private BillTo $billTo; - private string $language; - private ?Shipping $shipping = null; - private ?Tax $tax = null; - private array $extrinsics = []; - - private function __construct(string $orderId, \DateTimeInterface $orderDate, string $currency, string $language = 'en') - { - $this->orderId = $orderId; - $this->orderDate = $orderDate; - $this->currency = $currency; - $this->language = $language; - } - - public static function create(string $orderId, \DateTimeInterface $orderDate, string $currency, string $language = 'en'): self - { - return new self($orderId, $orderDate, $currency, $language); - } - - public static function fromPunchOutOrderMessage( - PunchOutOrderMessage $punchOutOrderMessage, - string $currency = null, - string $orderId = null, - \DateTimeInterface $orderDate = null, - string $language = 'en' - ): self { - if ($supplierOrderInfo = $punchOutOrderMessage->getPunchOutOrderMessageHeader()->getSupplierOrderInfo()) { - $orderId ??= $supplierOrderInfo->getOrderId(); - $orderDate ??= $supplierOrderInfo->getOrderDate(); - } - $currency ??= $punchOutOrderMessage->getPunchOutOrderMessageHeader()->getTotal()->getMoney()->getCurrency(); - - if (null === $orderId) { - throw new \LogicException('orderId should either be given or present in the PunchOutOrderMessage'); - } - if (null === $orderDate) { - throw new \LogicException('orderDate should either be given or present in the PunchOutOrderMessage'); - } - - $orb = new self( - $orderId, - $orderDate, - $currency, - $language - ); - - $orb->setShipTo($punchOutOrderMessage->getPunchOutOrderMessageHeader()->getShipTo()); - - foreach ($punchOutOrderMessage->getPunchoutOrderMessageItems() as $item) { - $orb->addItem( - $item->getQuantity(), - $item->getItemId(), - $item->getItemDetail()->getDescription()->getValue(), - $item->getItemDetail()->getUnitOfMeasure(), - $item->getItemDetail()->getUnitPrice()->getMoney()->getValueCent(), - [ - new Classification('custom', '0'), // TODO make this configurable - ] - ); - } - - return $orb; - } - - public function billTo( - string $name, - PostalAddress $postalAddress = null, - string $addressId = null, - string $addressIdDomain = null, - string $email = null, - string $phone = null, - string $fax = null, - string $url = null - ): self { - $this->billTo = new BillTo( - new Address( - new MultilanguageString($name, null, $this->language), - $postalAddress, - $addressId, - $addressIdDomain, - $email, - $phone, - $fax, - $url - ) - ); - - return $this; - } - - public function shipTo( - string $name, - PostalAddress $postalAddress, - array $carrierIdentifiers = [], - string $carrierAccountNo = null - ): self { - $this->shipTo = new ShipTo( - new Address( - new MultilanguageString($name, null, $this->language), - $postalAddress - ), - $carrierAccountNo ? TransportInformation::fromContractAccountNumber($carrierAccountNo) : null - ); - - foreach ($carrierIdentifiers as $domain => $identifier) { - $this->shipTo->addCarrierIdentifier($domain, $identifier); - } - - return $this; - } - - public function setShipTo(?ShipTo $shipTo): self - { - $this->shipTo = $shipTo; - - return $this; - } - - public function shipping(int $costs, string $description): self - { - $this->shipping = new Shipping( - $this->currency, - $costs, - new Description($description, null, $this->language), - ); - - return $this; - } - - public function tax(int $costs, string $description): self - { - $this->tax = new Tax( - $this->currency, - $costs, - new MultilanguageString($description, null, $this->language), - ); - - return $this; - } - - public function addItem( - int $quantity, - ItemId $itemId, - string $description, - string $unitOfMeasure, - int $unitPrice, - array $classifications, - \DateTimeInterface $requestDeliveryDate = null, - ItemOut $parent = null - ): self { - $lineNumber = \count($this->items) + 1; - - $item = ItemOut::create( - $lineNumber, - $quantity, - $itemId, - ItemDetail::create( - new Description( - $description, - null, - $this->language - ), - $unitOfMeasure, - new MoneyWrapper( - $this->currency, - $unitPrice - ), - $classifications - ), - $requestDeliveryDate, - $parent ? $parent->getLineNumber() : null - ); - - $this->items[] = $item; - $this->total += ($quantity * $unitPrice); - - return $this; - } - - public function addComment(string $value = null, string $type = null, string $lang = null, string $attachmentUrl = null): self - { - $this->comments[] = new Comment( - $value, - $type, - $lang, - $attachmentUrl - ); - - return $this; - } - - public function addContact(string $name, string $email, string $role = Contact::ROLE_BUYER): self - { - $contact = new Contact( - new MultilanguageString($name, null, $this->language), - $role - ); - $contact->addEmail($email); - - $this->contacts[] = $contact; - - return $this; - } - - public function addExtrinsic(Extrinsic $extrinsic): self - { - $this->extrinsics[] = $extrinsic; - - return $this; - } - - private function buildOrderRequestHeader(): OrderRequestHeader - { - $orh = OrderRequestHeader::create( - $this->orderId, - $this->orderDate, - $this->shipTo, - $this->billTo, - new MoneyWrapper($this->currency, $this->total), - $this->comments, - OrderRequestHeader::TYPE_NEW, - $this->contacts - ) - ->setShipping($this->shipping) - ->setTax($this->tax) - ; - - foreach ($this->extrinsics as $extrinsic) { - $orh->addExtrinsic($extrinsic); - } - - return $orh; - } - - public function build(): OrderRequest - { - if (!isset($this->billTo)) { - throw new \LogicException('BillTo is required'); - } - - return OrderRequest::create( - $this->buildOrderRequestHeader() - )->addItems($this->items); - } - - /** - * @return ItemOut[] - */ - public function getItems(): array - { - return $this->items; - } + private array $items = []; + private string $orderId; + private \DateTimeInterface $orderDate; + private int $total = 0; + private string $currency; + private array $comments = []; + private array $contacts = []; + private ?ShipTo $shipTo = null; + private BillTo $billTo; + private string $language; + private ?Shipping $shipping = null; + private ?Tax $tax = null; + private array $extrinsics = []; + + private function __construct(string $orderId, \DateTimeInterface $orderDate, string $currency, string $language = 'en') + { + $this->orderId = $orderId; + $this->orderDate = $orderDate; + $this->currency = $currency; + $this->language = $language; + } + + public static function create(string $orderId, \DateTimeInterface $orderDate, string $currency, string $language = 'en'): self + { + return new self($orderId, $orderDate, $currency, $language); + } + + public static function fromPunchOutOrderMessage( + PunchOutOrderMessage $punchOutOrderMessage, + string $currency = null, + string $orderId = null, + \DateTimeInterface $orderDate = null, + string $language = 'en' + ): self { + if ($supplierOrderInfo = $punchOutOrderMessage->getPunchOutOrderMessageHeader()->getSupplierOrderInfo()) { + $orderId ??= $supplierOrderInfo->getOrderId(); + $orderDate ??= $supplierOrderInfo->getOrderDate(); + } + $currency ??= $punchOutOrderMessage->getPunchOutOrderMessageHeader()->getTotal()->getMoney()->getCurrency(); + + if (null === $orderId) { + throw new \LogicException('orderId should either be given or present in the PunchOutOrderMessage'); + } + if (null === $orderDate) { + throw new \LogicException('orderDate should either be given or present in the PunchOutOrderMessage'); + } + + $orb = new self( + $orderId, + $orderDate, + $currency, + $language + ); + + $orb->setShipTo($punchOutOrderMessage->getPunchOutOrderMessageHeader()->getShipTo()); + + foreach ($punchOutOrderMessage->getPunchoutOrderMessageItems() as $item) { + $orb->addItem( + $item->getQuantity(), + $item->getItemId(), + $item->getItemDetail()->getDescription()->getValue(), + $item->getItemDetail()->getUnitOfMeasure(), + $item->getItemDetail()->getUnitPrice()->getMoney()->getValueCent(), + [ + new Classification('custom', '0'), // TODO make this configurable + ] + ); + } + + return $orb; + } + + public function billTo( + string $name, + PostalAddress $postalAddress = null, + string $addressId = null, + string $addressIdDomain = null, + string $email = null, + string $phone = null, + string $fax = null, + string $url = null + ): self { + $this->billTo = new BillTo( + new Address( + new MultilanguageString($name, null, $this->language), + $postalAddress, + $addressId, + $addressIdDomain, + $email, + $phone, + $fax, + $url + ) + ); + + return $this; + } + + public function shipTo( + string $name, + PostalAddress $postalAddress, + array $carrierIdentifiers = [], + string $carrierAccountNo = null + ): self { + $this->shipTo = new ShipTo( + new Address( + new MultilanguageString($name, null, $this->language), + $postalAddress + ), + $carrierAccountNo ? TransportInformation::fromContractAccountNumber($carrierAccountNo) : null + ); + + foreach ($carrierIdentifiers as $domain => $identifier) { + $this->shipTo->addCarrierIdentifier($domain, $identifier); + } + + return $this; + } + + public function setShipTo(?ShipTo $shipTo): self + { + $this->shipTo = $shipTo; + + return $this; + } + + public function shipping(int $costs, string $description): self + { + $this->shipping = new Shipping( + $this->currency, + $costs, + new Description($description, null, $this->language), + ); + + return $this; + } + + public function tax(int $costs, string $description): self + { + $this->tax = new Tax( + $this->currency, + $costs, + new MultilanguageString($description, null, $this->language), + ); + + return $this; + } + + public function addItem( + int $quantity, + ItemId $itemId, + string $description, + string $unitOfMeasure, + int $unitPrice, + array $classifications, + \DateTimeInterface $requestDeliveryDate = null, + ItemOut $parent = null + ): self { + $lineNumber = \count($this->items) + 1; + + $item = ItemOut::create( + $lineNumber, + $quantity, + $itemId, + ItemDetail::create( + new Description( + $description, + null, + $this->language + ), + $unitOfMeasure, + new MoneyWrapper( + $this->currency, + $unitPrice + ), + $classifications + ), + $requestDeliveryDate, + $parent ? $parent->getLineNumber() : null + ); + + $this->items[] = $item; + $this->total += ($quantity * $unitPrice); + + return $this; + } + + public function addComment(string $value = null, string $type = null, string $lang = null, string $attachmentUrl = null): self + { + $this->comments[] = new Comment( + $value, + $type, + $lang, + $attachmentUrl + ); + + return $this; + } + + public function addContact(string $name, string $email, string $role = Contact::ROLE_BUYER): self + { + $contact = new Contact( + new MultilanguageString($name, null, $this->language), + $role + ); + $contact->addEmail($email); + + $this->contacts[] = $contact; + + return $this; + } + + public function addExtrinsic(Extrinsic $extrinsic): self + { + $this->extrinsics[] = $extrinsic; + + return $this; + } + + private function buildOrderRequestHeader(): OrderRequestHeader + { + $orh = OrderRequestHeader::create( + $this->orderId, + $this->orderDate, + $this->shipTo, + $this->billTo, + new MoneyWrapper($this->currency, $this->total), + $this->comments, + OrderRequestHeader::TYPE_NEW, + $this->contacts + ) + ->setShipping($this->shipping) + ->setTax($this->tax) + ; + + foreach ($this->extrinsics as $extrinsic) { + $orh->addExtrinsic($extrinsic); + } + + return $orh; + } + + public function build(): OrderRequest + { + if (!isset($this->billTo)) { + throw new \LogicException('BillTo is required'); + } + + return OrderRequest::create( + $this->buildOrderRequestHeader() + )->addItems($this->items); + } + + /** + * @return ItemOut[] + */ + public function getItems(): array + { + return $this->items; + } } diff --git a/src/CXml/Builder/ProductActivityMessageBuilder.php b/src/CXml/Builder/ProductActivityMessageBuilder.php index 68fdb4f..fe56acd 100644 --- a/src/CXml/Builder/ProductActivityMessageBuilder.php +++ b/src/CXml/Builder/ProductActivityMessageBuilder.php @@ -12,53 +12,53 @@ class ProductActivityMessageBuilder { - private ProductActivityMessage $productActivityMessage; - private string $warehouseCodeDomain; + private ProductActivityMessage $productActivityMessage; + private string $warehouseCodeDomain; - private function __construct(string $messageId, string $warehouseCodeDomain) - { - $this->productActivityMessage = ProductActivityMessage::create( - $messageId, - ); + private function __construct(string $messageId, string $warehouseCodeDomain) + { + $this->productActivityMessage = ProductActivityMessage::create( + $messageId, + ); - $this->warehouseCodeDomain = $warehouseCodeDomain; - } + $this->warehouseCodeDomain = $warehouseCodeDomain; + } - public static function create(string $messageId, string $warehouseCodeDomain): self - { - return new self($messageId, $warehouseCodeDomain); - } + public static function create(string $messageId, string $warehouseCodeDomain): self + { + return new self($messageId, $warehouseCodeDomain); + } - public function addProductActivityDetail(string $sku, string $warehouseCode, int $stockLevel, array $extrinsics = null): self - { - $inventory = Inventory::create() - ->setStockOnHandQuantity(new InventoryQuantity($stockLevel, 'EA')) - ; + public function addProductActivityDetail(string $sku, string $warehouseCode, int $stockLevel, array $extrinsics = null): self + { + $inventory = Inventory::create() + ->setStockOnHandQuantity(new InventoryQuantity($stockLevel, 'EA')) + ; - $activityDetail = ProductActivityDetail::create( - new ItemId($sku, null, $sku), - $inventory, - Contact::create(new MultilanguageString($warehouseCode, null, 'en'), 'locationFrom') - ->addIdReference($this->warehouseCodeDomain, $warehouseCode) - ); + $activityDetail = ProductActivityDetail::create( + new ItemId($sku, null, $sku), + $inventory, + Contact::create(new MultilanguageString($warehouseCode, null, 'en'), 'locationFrom') + ->addIdReference($this->warehouseCodeDomain, $warehouseCode) + ); - if ($extrinsics) { - foreach ($extrinsics as $k => $v) { - $activityDetail->addExtrinsicAsKeyValue($k, $v); - } - } + if ($extrinsics) { + foreach ($extrinsics as $k => $v) { + $activityDetail->addExtrinsicAsKeyValue($k, $v); + } + } - $this->productActivityMessage->addProductActivityDetail($activityDetail); + $this->productActivityMessage->addProductActivityDetail($activityDetail); - return $this; - } + return $this; + } - public function build(): ProductActivityMessage - { - if (empty($this->productActivityMessage->getProductActivityDetails())) { - throw new \RuntimeException('Cannot build ProductActivityMessage without any ProductActivityDetail'); - } + public function build(): ProductActivityMessage + { + if (empty($this->productActivityMessage->getProductActivityDetails())) { + throw new \RuntimeException('Cannot build ProductActivityMessage without any ProductActivityDetail'); + } - return $this->productActivityMessage; - } + return $this->productActivityMessage; + } } diff --git a/src/CXml/Builder/PunchOutOrderMessageBuilder.php b/src/CXml/Builder/PunchOutOrderMessageBuilder.php index b287c86..93fd93f 100644 --- a/src/CXml/Builder/PunchOutOrderMessageBuilder.php +++ b/src/CXml/Builder/PunchOutOrderMessageBuilder.php @@ -19,177 +19,177 @@ class PunchOutOrderMessageBuilder { - private string $buyerCookie; - private string $currency; - private ?string $operationAllowed; - private string $language; - - /** - * @var ItemIn[] - */ - private array $punchoutOrderMessageItems = []; - private int $total = 0; - private ?Shipping $shipping = null; - private ?Tax $tax = null; - private string $orderId; - private ?\DateTimeInterface $orderDate; - private ?ShipTo $shipTo = null; - - private function __construct(string $language, string $buyerCookie, string $currency, string $operationAllowed = null) - { - $this->buyerCookie = $buyerCookie; - $this->currency = $currency; - $this->operationAllowed = $operationAllowed; - $this->language = $language; - } - - public static function create(string $language, string $buyerCookie, string $currency, string $operationAllowed = null): self - { - return new self($language, $buyerCookie, $currency, $operationAllowed); - } - - public function orderReference(string $orderId, \DateTimeInterface $orderDate = null): self - { - $this->orderId = $orderId; - $this->orderDate = $orderDate; - - return $this; - } - - public function shipTo( - string $name, - PostalAddress $postalAddress, - array $carrierIdentifiers = [], - string $carrierAccountNo = null - ): self { - $this->shipTo = new ShipTo( - new Address( - new MultilanguageString($name, null, $this->language), - $postalAddress - ), - $carrierAccountNo ? TransportInformation::fromContractAccountNumber($carrierAccountNo) : null - ); - - foreach ($carrierIdentifiers as $domain => $identifier) { - $this->shipTo->addCarrierIdentifier($domain, $identifier); - } - - return $this; - } - - public function shipping(int $shipping, string $taxDescription): self - { - $this->shipping = new Shipping( - $this->currency, - $shipping, - new Description( - $taxDescription, - null, - $this->language - ) - ); - - return $this; - } - - public function tax(int $tax, string $taxDescription): self - { - $this->tax = new Tax( - $this->currency, - $tax, - new Description( - $taxDescription, - null, - $this->language - ) - ); - - return $this; - } - - public function addPunchoutOrderMessageItem( - ItemId $itemId, - int $quantity, - string $description, - string $unitOfMeasure, - int $unitPrice, - array $classifications, - string $manufacturerPartId = null, - string $manufacturerName = null, - int $leadTime = null, - array $extrinsics = null - ): self { - $itemDetail = ItemDetail::create( - new Description( - $description, - null, - $this->language - ), - $unitOfMeasure, - new MoneyWrapper( - $this->currency, - $unitPrice - ), - $classifications - ) - ->setManufacturerPartId($manufacturerPartId) - ->setManufacturerName($manufacturerName) - ->setLeadtime($leadTime) - ; - - if ($extrinsics) { - foreach ($extrinsics as $k => $v) { - $itemDetail->addExtrinsicAsKeyValue($k, $v); - } - } - - $punchoutOrderMessageItem = ItemIn::create( - $quantity, - $itemId, - $itemDetail - ); - - return $this->addItem($punchoutOrderMessageItem); - } - - public function addItem(ItemIn $itemIn): self - { - $this->punchoutOrderMessageItems[] = $itemIn; - $this->total += ($itemIn->getItemDetail()->getUnitPrice()->getMoney()->getValueCent() * $itemIn->getQuantity()); - - return $this; - } - - public function build(): PunchOutOrderMessage - { - if (empty($this->punchoutOrderMessageItems)) { - throw new \RuntimeException('Cannot build PunchOutOrderMessage without any PunchoutOrderMessageItem'); - } - - $punchoutOrderMessageHeader = new PunchOutOrderMessageHeader( - new MoneyWrapper($this->currency, $this->total), - $this->shipping, - $this->tax, - $this->operationAllowed - ); - - if (isset($this->shipTo)) { - $punchoutOrderMessageHeader->setShipTo($this->shipTo); - } - - if (isset($this->orderId)) { - $punchoutOrderMessageHeader->setSupplierOrderInfo($this->orderId, $this->orderDate); - } - - $punchOutOrderMessage = PunchOutOrderMessage::create( - $this->buyerCookie, - $punchoutOrderMessageHeader - ); - - foreach ($this->punchoutOrderMessageItems as $punchoutOrderMessageItem) { - $punchOutOrderMessage->addPunchoutOrderMessageItem($punchoutOrderMessageItem); - } - - return $punchOutOrderMessage; - } + private string $buyerCookie; + private string $currency; + private ?string $operationAllowed; + private string $language; + + /** + * @var ItemIn[] + */ + private array $punchoutOrderMessageItems = []; + private int $total = 0; + private ?Shipping $shipping = null; + private ?Tax $tax = null; + private string $orderId; + private ?\DateTimeInterface $orderDate; + private ?ShipTo $shipTo = null; + + private function __construct(string $language, string $buyerCookie, string $currency, string $operationAllowed = null) + { + $this->buyerCookie = $buyerCookie; + $this->currency = $currency; + $this->operationAllowed = $operationAllowed; + $this->language = $language; + } + + public static function create(string $language, string $buyerCookie, string $currency, string $operationAllowed = null): self + { + return new self($language, $buyerCookie, $currency, $operationAllowed); + } + + public function orderReference(string $orderId, \DateTimeInterface $orderDate = null): self + { + $this->orderId = $orderId; + $this->orderDate = $orderDate; + + return $this; + } + + public function shipTo( + string $name, + PostalAddress $postalAddress, + array $carrierIdentifiers = [], + string $carrierAccountNo = null + ): self { + $this->shipTo = new ShipTo( + new Address( + new MultilanguageString($name, null, $this->language), + $postalAddress + ), + $carrierAccountNo ? TransportInformation::fromContractAccountNumber($carrierAccountNo) : null + ); + + foreach ($carrierIdentifiers as $domain => $identifier) { + $this->shipTo->addCarrierIdentifier($domain, $identifier); + } + + return $this; + } + + public function shipping(int $shipping, string $taxDescription): self + { + $this->shipping = new Shipping( + $this->currency, + $shipping, + new Description( + $taxDescription, + null, + $this->language + ) + ); + + return $this; + } + + public function tax(int $tax, string $taxDescription): self + { + $this->tax = new Tax( + $this->currency, + $tax, + new Description( + $taxDescription, + null, + $this->language + ) + ); + + return $this; + } + + public function addPunchoutOrderMessageItem( + ItemId $itemId, + int $quantity, + string $description, + string $unitOfMeasure, + int $unitPrice, + array $classifications, + string $manufacturerPartId = null, + string $manufacturerName = null, + int $leadTime = null, + array $extrinsics = null + ): self { + $itemDetail = ItemDetail::create( + new Description( + $description, + null, + $this->language + ), + $unitOfMeasure, + new MoneyWrapper( + $this->currency, + $unitPrice + ), + $classifications + ) + ->setManufacturerPartId($manufacturerPartId) + ->setManufacturerName($manufacturerName) + ->setLeadtime($leadTime) + ; + + if ($extrinsics) { + foreach ($extrinsics as $k => $v) { + $itemDetail->addExtrinsicAsKeyValue($k, $v); + } + } + + $punchoutOrderMessageItem = ItemIn::create( + $quantity, + $itemId, + $itemDetail + ); + + return $this->addItem($punchoutOrderMessageItem); + } + + public function addItem(ItemIn $itemIn): self + { + $this->punchoutOrderMessageItems[] = $itemIn; + $this->total += ($itemIn->getItemDetail()->getUnitPrice()->getMoney()->getValueCent() * $itemIn->getQuantity()); + + return $this; + } + + public function build(): PunchOutOrderMessage + { + if (empty($this->punchoutOrderMessageItems)) { + throw new \RuntimeException('Cannot build PunchOutOrderMessage without any PunchoutOrderMessageItem'); + } + + $punchoutOrderMessageHeader = new PunchOutOrderMessageHeader( + new MoneyWrapper($this->currency, $this->total), + $this->shipping, + $this->tax, + $this->operationAllowed + ); + + if (isset($this->shipTo)) { + $punchoutOrderMessageHeader->setShipTo($this->shipTo); + } + + if (isset($this->orderId)) { + $punchoutOrderMessageHeader->setSupplierOrderInfo($this->orderId, $this->orderDate); + } + + $punchOutOrderMessage = PunchOutOrderMessage::create( + $this->buyerCookie, + $punchoutOrderMessageHeader + ); + + foreach ($this->punchoutOrderMessageItems as $punchoutOrderMessageItem) { + $punchOutOrderMessage->addPunchoutOrderMessageItem($punchoutOrderMessageItem); + } + + return $punchOutOrderMessage; + } } diff --git a/src/CXml/Context.php b/src/CXml/Context.php index 9df7c46..8aa072f 100644 --- a/src/CXml/Context.php +++ b/src/CXml/Context.php @@ -6,75 +6,75 @@ class Context { - private ?CXml $cxml = null; - private array $options; - - private function __construct(array $options = []) - { - $this->options = $options; - } - - public static function create(array $options = []): self - { - return new self($options); - } - - public function getOption(string $key)/* : mixed */ - { - return $this->options[$key] ?? null; - } - - public function getOptions(): array - { - return $this->options; - } - - public function setDryRun(bool $dryrun): self - { - $this->options['dryrun'] = $dryrun; - - return $this; - } - - public function isDryRun(): bool - { - return $this->options['dryrun'] ?? false; - } - - public function getCXml(): ?CXml - { - return $this->cxml; - } - - public function setCXml(CXml $cxml): self - { - $this->cxml = $cxml; - - return $this; - } - - public function getSenderUserAgent(): ?string - { - $cxml = $this->getCxml(); - if (!$cxml) { - return null; - } - - $header = $cxml->getHeader(); - if (!$header) { - return null; - } - - return $header->getSender()->getUserAgent(); - } - - public function getPayloadId(): ?string - { - $cxml = $this->getCxml(); - if (!$cxml) { - return null; - } - - return $cxml->getPayloadId(); - } + private ?CXml $cxml = null; + private array $options; + + private function __construct(array $options = []) + { + $this->options = $options; + } + + public static function create(array $options = []): self + { + return new self($options); + } + + public function getOption(string $key)/* : mixed */ + { + return $this->options[$key] ?? null; + } + + public function getOptions(): array + { + return $this->options; + } + + public function setDryRun(bool $dryrun): self + { + $this->options['dryrun'] = $dryrun; + + return $this; + } + + public function isDryRun(): bool + { + return $this->options['dryrun'] ?? false; + } + + public function getCXml(): ?CXml + { + return $this->cxml; + } + + public function setCXml(CXml $cxml): self + { + $this->cxml = $cxml; + + return $this; + } + + public function getSenderUserAgent(): ?string + { + $cxml = $this->getCxml(); + if (!$cxml) { + return null; + } + + $header = $cxml->getHeader(); + if (!$header) { + return null; + } + + return $header->getSender()->getUserAgent(); + } + + public function getPayloadId(): ?string + { + $cxml = $this->getCxml(); + if (!$cxml) { + return null; + } + + return $cxml->getPayloadId(); + } } diff --git a/src/CXml/Credential/CredentialRepositoryInterface.php b/src/CXml/Credential/CredentialRepositoryInterface.php index 1f35ac8..1897445 100644 --- a/src/CXml/Credential/CredentialRepositoryInterface.php +++ b/src/CXml/Credential/CredentialRepositoryInterface.php @@ -7,8 +7,8 @@ interface CredentialRepositoryInterface { - /** - * @throws CXmlCredentialInvalidException - */ - public function getCredentialByDomainAndId(string $domain, string $identity): Credential; + /** + * @throws CXmlCredentialInvalidException + */ + public function getCredentialByDomainAndId(string $domain, string $identity): Credential; } diff --git a/src/CXml/Credential/Registry.php b/src/CXml/Credential/Registry.php index 6381b49..7b07141 100644 --- a/src/CXml/Credential/Registry.php +++ b/src/CXml/Credential/Registry.php @@ -11,45 +11,45 @@ class Registry implements CredentialRepositoryInterface, AuthenticatorInterface { - /** - * @var Credential[] - */ - private array $registeredCredentials = []; - - public function registerCredential(Credential $credential): void - { - $this->registeredCredentials[] = $credential; - } - - /** - * @throws CXmlCredentialInvalidException - */ - public function getCredentialByDomainAndId(string $domain, string $identity): Credential - { - foreach ($this->registeredCredentials as $registeredCredential) { - if ($registeredCredential->getDomain() === $domain && $registeredCredential->getIdentity() === $identity) { - return $registeredCredential; - } - } - - throw new CXmlCredentialInvalidException("Could not find credentials for '{$identity}@{$domain}'."); - } - - /** - * @throws CXmlAuthenticationInvalidException - * @throws CXmlCredentialInvalidException - */ - public function authenticate(Header $header, Context $context): void - { - $senderCredential = $header->getSender()->getCredential(); - - $baseCredential = $this->getCredentialByDomainAndId( - $senderCredential->getDomain(), - $senderCredential->getIdentity(), - ); - - if ($baseCredential->getSharedSecret() !== $senderCredential->getSharedSecret()) { - throw new CXmlAuthenticationInvalidException($senderCredential); - } - } + /** + * @var Credential[] + */ + private array $registeredCredentials = []; + + public function registerCredential(Credential $credential): void + { + $this->registeredCredentials[] = $credential; + } + + /** + * @throws CXmlCredentialInvalidException + */ + public function getCredentialByDomainAndId(string $domain, string $identity): Credential + { + foreach ($this->registeredCredentials as $registeredCredential) { + if ($registeredCredential->getDomain() === $domain && $registeredCredential->getIdentity() === $identity) { + return $registeredCredential; + } + } + + throw new CXmlCredentialInvalidException("Could not find credentials for '{$identity}@{$domain}'."); + } + + /** + * @throws CXmlAuthenticationInvalidException + * @throws CXmlCredentialInvalidException + */ + public function authenticate(Header $header, Context $context): void + { + $senderCredential = $header->getSender()->getCredential(); + + $baseCredential = $this->getCredentialByDomainAndId( + $senderCredential->getDomain(), + $senderCredential->getIdentity(), + ); + + if ($baseCredential->getSharedSecret() !== $senderCredential->getSharedSecret()) { + throw new CXmlAuthenticationInvalidException($senderCredential); + } + } } diff --git a/src/CXml/Document/DocumentRegistryInterface.php b/src/CXml/Document/DocumentRegistryInterface.php index 83b45e9..ea0a0fe 100644 --- a/src/CXml/Document/DocumentRegistryInterface.php +++ b/src/CXml/Document/DocumentRegistryInterface.php @@ -6,7 +6,7 @@ interface DocumentRegistryInterface { - public function register(CXml $cxml): void; + public function register(CXml $cxml): void; - public function getByDocumentReference(string $documentReferencePayloadId): ?CXml; + public function getByDocumentReference(string $documentReferencePayloadId): ?CXml; } diff --git a/src/CXml/Endpoint.php b/src/CXml/Endpoint.php index 22bb421..5029978 100644 --- a/src/CXml/Endpoint.php +++ b/src/CXml/Endpoint.php @@ -12,59 +12,59 @@ class Endpoint { - private Serializer $serializer; - private DtdValidator $dtdValidator; - private Processor $processor; - private LoggerInterface $logger; + private Serializer $serializer; + private DtdValidator $dtdValidator; + private Processor $processor; + private LoggerInterface $logger; - public function __construct( - Serializer $serializer, - DtdValidator $messageValidator, - Processor $processor, - LoggerInterface $logger = null - ) { - $this->serializer = $serializer; - $this->dtdValidator = $messageValidator; - $this->processor = $processor; - $this->logger = $logger ?? new NullLogger(); - } + public function __construct( + Serializer $serializer, + DtdValidator $messageValidator, + Processor $processor, + LoggerInterface $logger = null + ) { + $this->serializer = $serializer; + $this->dtdValidator = $messageValidator; + $this->processor = $processor; + $this->logger = $logger ?? new NullLogger(); + } - /** - * @throws Exception\CXmlException - */ - public function parseAndProcessStringAsCXml(string $xml, Context $context = null): ?CXml - { - $this->logger->info('Processing incoming CXml message', ['xml' => $xml]); + /** + * @throws Exception\CXmlException + */ + public function parseAndProcessStringAsCXml(string $xml, Context $context = null): ?CXml + { + $this->logger->info('Processing incoming CXml message', ['xml' => $xml]); - // validate - try { - $this->dtdValidator->validateAgainstDtd($xml); - } catch (CXmlInvalidException $e) { - $this->logger->error('Incoming CXml was invalid (via DTD)', ['xml' => $xml]); + // validate + try { + $this->dtdValidator->validateAgainstDtd($xml); + } catch (CXmlInvalidException $e) { + $this->logger->error('Incoming CXml was invalid (via DTD)', ['xml' => $xml]); - throw $e; - } + throw $e; + } - // deserialize - try { - $cxml = $this->serializer->deserialize($xml); - } catch (\RuntimeException $e) { - $this->logger->error('Error while deserializing xml to CXml: '.$e->getMessage(), ['xml' => $xml]); + // deserialize + try { + $cxml = $this->serializer->deserialize($xml); + } catch (\RuntimeException $e) { + $this->logger->error('Error while deserializing xml to CXml: '.$e->getMessage(), ['xml' => $xml]); - throw new CXmlInvalidException('Error while deserializing xml: '.$e->getMessage(), $xml, $e); - } + throw new CXmlInvalidException('Error while deserializing xml: '.$e->getMessage(), $xml, $e); + } - // process - try { - $result = $this->processor->process($cxml, $context); - } catch (CXmlException $e) { - $this->logger->error('Error while processing valid CXml: '.$e->getMessage(), ['xml' => $xml]); + // process + try { + $result = $this->processor->process($cxml, $context); + } catch (CXmlException $e) { + $this->logger->error('Error while processing valid CXml: '.$e->getMessage(), ['xml' => $xml]); - throw $e; - } + throw $e; + } - $this->logger->info('Success after processing incoming CXml message', ['xml' => $xml]); + $this->logger->info('Success after processing incoming CXml message', ['xml' => $xml]); - return $result; - } + return $result; + } } diff --git a/src/CXml/Exception/CXmlAuthenticationInvalidException.php b/src/CXml/Exception/CXmlAuthenticationInvalidException.php index d69937b..b506e54 100644 --- a/src/CXml/Exception/CXmlAuthenticationInvalidException.php +++ b/src/CXml/Exception/CXmlAuthenticationInvalidException.php @@ -6,8 +6,8 @@ class CXmlAuthenticationInvalidException extends CXmlCredentialInvalidException { - public function __construct(Credential $credential, \Throwable $previous = null) - { - parent::__construct('Given shared secret does not match.', $credential, $previous); - } + public function __construct(Credential $credential, \Throwable $previous = null) + { + parent::__construct('Given shared secret does not match.', $credential, $previous); + } } diff --git a/src/CXml/Exception/CXmlCredentialInvalidException.php b/src/CXml/Exception/CXmlCredentialInvalidException.php index cacebcc..1314d3e 100644 --- a/src/CXml/Exception/CXmlCredentialInvalidException.php +++ b/src/CXml/Exception/CXmlCredentialInvalidException.php @@ -6,17 +6,17 @@ class CXmlCredentialInvalidException extends CXmlExpectationFailedException { - private ?Credential $credential; + private ?Credential $credential; - public function __construct(string $message, Credential $credential = null, \Throwable $previous = null) - { - parent::__construct($message.($credential ? "\nCredential was:".$credential : ''), $previous); + public function __construct(string $message, Credential $credential = null, \Throwable $previous = null) + { + parent::__construct($message.($credential ? "\nCredential was:".$credential : ''), $previous); - $this->credential = $credential; - } + $this->credential = $credential; + } - public function getCredential(): ?Credential - { - return $this->credential; - } + public function getCredential(): ?Credential + { + return $this->credential; + } } diff --git a/src/CXml/Exception/CXmlException.php b/src/CXml/Exception/CXmlException.php index 9d47e31..00e1c24 100644 --- a/src/CXml/Exception/CXmlException.php +++ b/src/CXml/Exception/CXmlException.php @@ -4,8 +4,8 @@ class CXmlException extends \Exception { - public function __construct(string $message, \Throwable $previous = null) - { - parent::__construct($message, 0, $previous); - } + public function __construct(string $message, \Throwable $previous = null) + { + parent::__construct($message, 0, $previous); + } } diff --git a/src/CXml/Handler/Exception/CXmlHandlerNotFoundException.php b/src/CXml/Handler/Exception/CXmlHandlerNotFoundException.php index 4a7aa2e..4302953 100644 --- a/src/CXml/Handler/Exception/CXmlHandlerNotFoundException.php +++ b/src/CXml/Handler/Exception/CXmlHandlerNotFoundException.php @@ -6,8 +6,8 @@ class CXmlHandlerNotFoundException extends CXmlNotImplementedException { - public function __construct(string $handlerId, \Throwable $previous = null) - { - parent::__construct("Handler for {$handlerId} not found. Register first.", $previous); - } + public function __construct(string $handlerId, \Throwable $previous = null) + { + parent::__construct("Handler for {$handlerId} not found. Register first.", $previous); + } } diff --git a/src/CXml/Handler/HandlerInterface.php b/src/CXml/Handler/HandlerInterface.php index 7ceb44d..1518327 100644 --- a/src/CXml/Handler/HandlerInterface.php +++ b/src/CXml/Handler/HandlerInterface.php @@ -9,10 +9,10 @@ interface HandlerInterface { - /** - * @throws CXmlNotImplementedException - */ - public function handle(PayloadInterface $payload, Context $context): ?ResponsePayloadInterface; + /** + * @throws CXmlNotImplementedException + */ + public function handle(PayloadInterface $payload, Context $context): ?ResponsePayloadInterface; - public static function getRequestName(): string; + public static function getRequestName(): string; } diff --git a/src/CXml/Handler/HandlerRegistry.php b/src/CXml/Handler/HandlerRegistry.php index a7c65f9..b827749 100644 --- a/src/CXml/Handler/HandlerRegistry.php +++ b/src/CXml/Handler/HandlerRegistry.php @@ -7,36 +7,36 @@ class HandlerRegistry implements HandlerRegistryInterface { - /** - * @var HandlerInterface[] - */ - private array $registry = []; - - public function register(HandlerInterface $handler, string $handlerId = null): void - { - if (!$handlerId) { - $handlerId = $handler::getRequestName(); - } - - Assertion::keyNotExists($this->registry, $handlerId, "Handler for '{$handlerId}' already registered."); - - $this->registry[$handlerId] = $handler; - } - - public function all(): array - { - return $this->registry; - } - - /** - * @throws CXmlHandlerNotFoundException - */ - public function get(string $handlerId): HandlerInterface - { - if (!isset($this->registry[$handlerId])) { - throw new CXmlHandlerNotFoundException($handlerId); - } - - return $this->registry[$handlerId]; - } + /** + * @var HandlerInterface[] + */ + private array $registry = []; + + public function register(HandlerInterface $handler, string $handlerId = null): void + { + if (!$handlerId) { + $handlerId = $handler::getRequestName(); + } + + Assertion::keyNotExists($this->registry, $handlerId, "Handler for '{$handlerId}' already registered."); + + $this->registry[$handlerId] = $handler; + } + + public function all(): array + { + return $this->registry; + } + + /** + * @throws CXmlHandlerNotFoundException + */ + public function get(string $handlerId): HandlerInterface + { + if (!isset($this->registry[$handlerId])) { + throw new CXmlHandlerNotFoundException($handlerId); + } + + return $this->registry[$handlerId]; + } } diff --git a/src/CXml/Handler/HandlerRegistryInterface.php b/src/CXml/Handler/HandlerRegistryInterface.php index 24271b7..ab3eaae 100644 --- a/src/CXml/Handler/HandlerRegistryInterface.php +++ b/src/CXml/Handler/HandlerRegistryInterface.php @@ -4,5 +4,5 @@ interface HandlerRegistryInterface { - public function get(string $handlerId): HandlerInterface; + public function get(string $handlerId): HandlerInterface; } diff --git a/src/CXml/Handler/Request/SelfAwareProfileRequestHandler.php b/src/CXml/Handler/Request/SelfAwareProfileRequestHandler.php index 37e7b9f..d2ca54b 100644 --- a/src/CXml/Handler/Request/SelfAwareProfileRequestHandler.php +++ b/src/CXml/Handler/Request/SelfAwareProfileRequestHandler.php @@ -13,37 +13,37 @@ class SelfAwareProfileRequestHandler implements HandlerInterface { - private HandlerRegistry $handlerRegistry; - private UrlGeneratorInterface $urlGenerator; - private string $defaultRoute; - - public function __construct(HandlerRegistry $handlerRegistry, UrlGeneratorInterface $urlGenerator, string $defaultRoute = 'post_cxml') - { - $this->handlerRegistry = $handlerRegistry; - $this->urlGenerator = $urlGenerator; - $this->defaultRoute = $defaultRoute; - } - - public function handle(PayloadInterface $payload, Context $context): ?ResponsePayloadInterface - { - $profileResponse = new ProfileResponse(); - - foreach ($this->handlerRegistry->all() as $requestName => $handler) { - $transaction = new Transaction($requestName, $this->getEndpointUrl()); - - $profileResponse->addTransaction($transaction); - } - - return $profileResponse; - } - - private function getEndpointUrl(): string - { - return $this->urlGenerator->generate($this->defaultRoute, [], UrlGeneratorInterface::ABSOLUTE_URL); - } - - public static function getRequestName(): string - { - return 'ProfileRequest'; - } + private HandlerRegistry $handlerRegistry; + private UrlGeneratorInterface $urlGenerator; + private string $defaultRoute; + + public function __construct(HandlerRegistry $handlerRegistry, UrlGeneratorInterface $urlGenerator, string $defaultRoute = 'post_cxml') + { + $this->handlerRegistry = $handlerRegistry; + $this->urlGenerator = $urlGenerator; + $this->defaultRoute = $defaultRoute; + } + + public function handle(PayloadInterface $payload, Context $context): ?ResponsePayloadInterface + { + $profileResponse = new ProfileResponse(); + + foreach ($this->handlerRegistry->all() as $requestName => $handler) { + $transaction = new Transaction($requestName, $this->getEndpointUrl()); + + $profileResponse->addTransaction($transaction); + } + + return $profileResponse; + } + + private function getEndpointUrl(): string + { + return $this->urlGenerator->generate($this->defaultRoute, [], UrlGeneratorInterface::ABSOLUTE_URL); + } + + public static function getRequestName(): string + { + return 'ProfileRequest'; + } } diff --git a/src/CXml/Handler/Request/StaticStartPagePunchOutSetupRequestHandler.php b/src/CXml/Handler/Request/StaticStartPagePunchOutSetupRequestHandler.php index 670fc6a..4b73b21 100644 --- a/src/CXml/Handler/Request/StaticStartPagePunchOutSetupRequestHandler.php +++ b/src/CXml/Handler/Request/StaticStartPagePunchOutSetupRequestHandler.php @@ -11,24 +11,24 @@ class StaticStartPagePunchOutSetupRequestHandler implements HandlerInterface { - private string $startPageUrl; + private string $startPageUrl; - public function __construct(string $startPageUrl) - { - $this->startPageUrl = $startPageUrl; - } + public function __construct(string $startPageUrl) + { + $this->startPageUrl = $startPageUrl; + } - public function handle(PayloadInterface $payload, Context $context): ?ResponsePayloadInterface - { - return new PunchOutSetupResponse( - new Url( - $this->startPageUrl - ) - ); - } + public function handle(PayloadInterface $payload, Context $context): ?ResponsePayloadInterface + { + return new PunchOutSetupResponse( + new Url( + $this->startPageUrl + ) + ); + } - public static function getRequestName(): string - { - return 'PunchOutSetupRequest'; - } + public static function getRequestName(): string + { + return 'PunchOutSetupRequest'; + } } diff --git a/src/CXml/Jms/CXmlWrappingNodeJmsEventSubscriber.php b/src/CXml/Jms/CXmlWrappingNodeJmsEventSubscriber.php index 1c6197c..ca544cd 100644 --- a/src/CXml/Jms/CXmlWrappingNodeJmsEventSubscriber.php +++ b/src/CXml/Jms/CXmlWrappingNodeJmsEventSubscriber.php @@ -20,123 +20,123 @@ */ class CXmlWrappingNodeJmsEventSubscriber implements EventSubscriberInterface { - public static function getSubscribedEvents(): array - { - return [ - [ - 'event' => Events::POST_SERIALIZE, - 'method' => 'onPostSerializePayload', - 'class' => Message::class, - 'format' => 'xml', - ], - [ - 'event' => Events::POST_SERIALIZE, - 'method' => 'onPostSerializePayload', - 'class' => Request::class, - 'format' => 'xml', - ], - [ - 'event' => Events::POST_SERIALIZE, - 'method' => 'onPostSerializePayload', - 'class' => Response::class, - 'format' => 'xml', - ], - - [ - 'event' => Events::PRE_DESERIALIZE, - 'method' => 'onPreDeserializePayload', - 'class' => Message::class, - 'format' => 'xml', - ], - [ - 'event' => Events::PRE_DESERIALIZE, - 'method' => 'onPreDeserializePayload', - 'class' => Request::class, - 'format' => 'xml', - ], - [ - 'event' => Events::PRE_DESERIALIZE, - 'method' => 'onPreDeserializePayload', - 'class' => Response::class, - 'format' => 'xml', - ], - ]; - } - - private static function findPayloadNode(\SimpleXMLElement $cXmlNode): ?\SimpleXMLElement - { - foreach ($cXmlNode->children() as $child) { - if ('Status' === $child->getName()) { - continue; - } - - // first child if not 'Status' - return $child; - } - - return null; - } - - /** - * @throws \ReflectionException - */ - public function onPostSerializePayload(ObjectEvent $event): void - { - /** @var XmlSerializationVisitor $visitor */ - $visitor = $event->getVisitor(); - - // this is the actual payload object of type MessagePayloadInterface - /* @phpstan-ignore-next-line */ - $payload = $event->getObject()->getPayload(); - - if ($payload) { - $cls = (new \ReflectionClass($payload))->getShortName(); - - // tell jms to add the payload value in a wrapped node - $visitor->visitProperty( - new StaticPropertyMetadata($event->getType()['name'], $cls, null), - $payload - ); - } - } - - /** - * @throws CXmlModelNotFoundException - * @throws \ReflectionException - */ - public function onPreDeserializePayload(PreDeserializeEvent $event): void - { - /** @var ClassMetadata $metadata */ - $metadata = $event->getContext()->getMetadataFactory()->getMetadataForClass($event->getType()['name']); - - /** @var \SimpleXMLElement $data */ - $data = $event->getData(); - $payloadNode = self::findPayloadNode($data); - if (null === $payloadNode) { - return; - } - - $serializedName = $payloadNode->getName(); - $targetNamespace = (new \ReflectionClass($event->getType()['name']))->getNamespaceName(); - - $cls = $targetNamespace.'\\'.$serializedName; - if (!\class_exists($cls)) { - throw new CXmlModelNotFoundException($serializedName); - } - - // manipulate metadata of payload on-the-fly to match xml - - $propertyMetadata = new PropertyMetadata( - $event->getType()['name'], - 'payload' - ); - - $propertyMetadata->serializedName = $serializedName; - $propertyMetadata->setType([ - 'name' => $cls, - 'params' => [], - ]); - - $metadata->addPropertyMetadata($propertyMetadata); - } + public static function getSubscribedEvents(): array + { + return [ + [ + 'event' => Events::POST_SERIALIZE, + 'method' => 'onPostSerializePayload', + 'class' => Message::class, + 'format' => 'xml', + ], + [ + 'event' => Events::POST_SERIALIZE, + 'method' => 'onPostSerializePayload', + 'class' => Request::class, + 'format' => 'xml', + ], + [ + 'event' => Events::POST_SERIALIZE, + 'method' => 'onPostSerializePayload', + 'class' => Response::class, + 'format' => 'xml', + ], + + [ + 'event' => Events::PRE_DESERIALIZE, + 'method' => 'onPreDeserializePayload', + 'class' => Message::class, + 'format' => 'xml', + ], + [ + 'event' => Events::PRE_DESERIALIZE, + 'method' => 'onPreDeserializePayload', + 'class' => Request::class, + 'format' => 'xml', + ], + [ + 'event' => Events::PRE_DESERIALIZE, + 'method' => 'onPreDeserializePayload', + 'class' => Response::class, + 'format' => 'xml', + ], + ]; + } + + private static function findPayloadNode(\SimpleXMLElement $cXmlNode): ?\SimpleXMLElement + { + foreach ($cXmlNode->children() as $child) { + if ('Status' === $child->getName()) { + continue; + } + + // first child if not 'Status' + return $child; + } + + return null; + } + + /** + * @throws \ReflectionException + */ + public function onPostSerializePayload(ObjectEvent $event): void + { + /** @var XmlSerializationVisitor $visitor */ + $visitor = $event->getVisitor(); + + // this is the actual payload object of type MessagePayloadInterface + /* @phpstan-ignore-next-line */ + $payload = $event->getObject()->getPayload(); + + if ($payload) { + $cls = (new \ReflectionClass($payload))->getShortName(); + + // tell jms to add the payload value in a wrapped node + $visitor->visitProperty( + new StaticPropertyMetadata($event->getType()['name'], $cls, null), + $payload + ); + } + } + + /** + * @throws CXmlModelNotFoundException + * @throws \ReflectionException + */ + public function onPreDeserializePayload(PreDeserializeEvent $event): void + { + /** @var ClassMetadata $metadata */ + $metadata = $event->getContext()->getMetadataFactory()->getMetadataForClass($event->getType()['name']); + + /** @var \SimpleXMLElement $data */ + $data = $event->getData(); + $payloadNode = self::findPayloadNode($data); + if (null === $payloadNode) { + return; + } + + $serializedName = $payloadNode->getName(); + $targetNamespace = (new \ReflectionClass($event->getType()['name']))->getNamespaceName(); + + $cls = $targetNamespace.'\\'.$serializedName; + if (!\class_exists($cls)) { + throw new CXmlModelNotFoundException($serializedName); + } + + // manipulate metadata of payload on-the-fly to match xml + + $propertyMetadata = new PropertyMetadata( + $event->getType()['name'], + 'payload' + ); + + $propertyMetadata->serializedName = $serializedName; + $propertyMetadata->setType([ + 'name' => $cls, + 'params' => [], + ]); + + $metadata->addPropertyMetadata($propertyMetadata); + } } diff --git a/src/CXml/Jms/JmsDateTimeHandler.php b/src/CXml/Jms/JmsDateTimeHandler.php index 3e7c2af..b861550 100644 --- a/src/CXml/Jms/JmsDateTimeHandler.php +++ b/src/CXml/Jms/JmsDateTimeHandler.php @@ -15,48 +15,48 @@ */ class JmsDateTimeHandler { - public function serialize(XmlSerializationVisitor $visitor, \DateTimeInterface $date, array $type, Context $context) - { - if ($date instanceof Date) { - $format = 'Y-m-d'; - } else { - $format = $this->getFormat($type); - } - - return $visitor->visitSimpleString($date->format($format), $type); - } - - private function getFormat(array $type): string - { - return $type['params'][0] ?? \DateTimeInterface::ATOM; - } - - public function deserialize(XmlDeserializationVisitor $visitor, $dateAsString, array $type, Context $context) - { - // explicit date-format was defined in property annotation - if (isset($type['params'][0])) { - return \DateTime::createFromFormat($type['params'][0], $dateAsString); - } - - // else try ISO-8601 - $dateTime = \DateTime::createFromFormat(\DateTimeInterface::ATOM, $dateAsString); - if ($dateTime) { - return $dateTime; - } - - // else try milliseconds-format - $dateTime = \DateTime::createFromFormat('Y-m-d\TH:i:s.vP', $dateAsString); - if ($dateTime) { - return $dateTime; - } - - // else try simple date-format - $dateTime = Date::createFromFormat('Y-m-d', $dateAsString); - if ($dateTime) { - return $dateTime; - } - - // last resort: throw exception - throw new \RuntimeException('Could not parse date: '.$dateAsString); - } + public function serialize(XmlSerializationVisitor $visitor, \DateTimeInterface $date, array $type, Context $context) + { + if ($date instanceof Date) { + $format = 'Y-m-d'; + } else { + $format = $this->getFormat($type); + } + + return $visitor->visitSimpleString($date->format($format), $type); + } + + private function getFormat(array $type): string + { + return $type['params'][0] ?? \DateTimeInterface::ATOM; + } + + public function deserialize(XmlDeserializationVisitor $visitor, $dateAsString, array $type, Context $context) + { + // explicit date-format was defined in property annotation + if (isset($type['params'][0])) { + return \DateTime::createFromFormat($type['params'][0], $dateAsString); + } + + // else try ISO-8601 + $dateTime = \DateTime::createFromFormat(\DateTimeInterface::ATOM, $dateAsString); + if ($dateTime) { + return $dateTime; + } + + // else try milliseconds-format + $dateTime = \DateTime::createFromFormat('Y-m-d\TH:i:s.vP', $dateAsString); + if ($dateTime) { + return $dateTime; + } + + // else try simple date-format + $dateTime = Date::createFromFormat('Y-m-d', $dateAsString); + if ($dateTime) { + return $dateTime; + } + + // last resort: throw exception + throw new \RuntimeException('Could not parse date: '.$dateAsString); + } } diff --git a/src/CXml/Model/Address.php b/src/CXml/Model/Address.php index 9ca0516..998d838 100644 --- a/src/CXml/Model/Address.php +++ b/src/CXml/Model/Address.php @@ -6,102 +6,102 @@ class Address { - /** - * @Ser\XmlAttribute - * @Ser\SerializedName("addressID") - */ - private ?string $addressId = null; - - /** - * @Ser\XmlAttribute - * @Ser\SerializedName("addressIDDomain") - */ - private ?string $addressIdDomain = null; - - /** - * @Ser\SerializedName("Name") - * @Ser\XmlElement (cdata=false) - */ - private MultilanguageString $name; - - /** - * @Ser\SerializedName("PostalAddress") - */ - private ?PostalAddress $postalAddress = null; - - /** - * @Ser\SerializedName("Email") - * @Ser\XmlElement (cdata=false) - */ - private ?string $email = null; - - /** - * @Ser\SerializedName("Phone") - * @Ser\XmlElement (cdata=false) - */ - private ?string $phone = null; - - /** - * @Ser\SerializedName("Fax") - * @Ser\XmlElement (cdata=false) - */ - private ?string $fax = null; - - /** - * @Ser\SerializedName("URL") - * @Ser\XmlElement (cdata=false) - */ - private ?string $url = null; - - public function __construct(MultilanguageString $name, PostalAddress $postalAddress = null, string $addressId = null, string $addressIdDomain = null, string $email = null, string $phone = null, string $fax = null, string $url = null) - { - $this->addressId = $addressId; - $this->addressIdDomain = $addressIdDomain; - $this->name = $name; - $this->postalAddress = $postalAddress; - $this->email = $email; - $this->phone = $phone; - $this->fax = $fax; - $this->url = $url; - } - - public function getAddressId(): ?string - { - return $this->addressId; - } - - public function getAddressIdDomain(): ?string - { - return $this->addressIdDomain; - } - - public function getName(): MultilanguageString - { - return $this->name; - } - - public function getPostalAddress(): ?PostalAddress - { - return $this->postalAddress; - } - - public function getEmail(): ?string - { - return $this->email; - } - - public function getPhone(): ?string - { - return $this->phone; - } - - public function getFax(): ?string - { - return $this->fax; - } - - public function getUrl(): ?string - { - return $this->url; - } + /** + * @Ser\XmlAttribute + * @Ser\SerializedName("addressID") + */ + private ?string $addressId = null; + + /** + * @Ser\XmlAttribute + * @Ser\SerializedName("addressIDDomain") + */ + private ?string $addressIdDomain = null; + + /** + * @Ser\SerializedName("Name") + * @Ser\XmlElement (cdata=false) + */ + private MultilanguageString $name; + + /** + * @Ser\SerializedName("PostalAddress") + */ + private ?PostalAddress $postalAddress = null; + + /** + * @Ser\SerializedName("Email") + * @Ser\XmlElement (cdata=false) + */ + private ?string $email = null; + + /** + * @Ser\SerializedName("Phone") + * @Ser\XmlElement (cdata=false) + */ + private ?string $phone = null; + + /** + * @Ser\SerializedName("Fax") + * @Ser\XmlElement (cdata=false) + */ + private ?string $fax = null; + + /** + * @Ser\SerializedName("URL") + * @Ser\XmlElement (cdata=false) + */ + private ?string $url = null; + + public function __construct(MultilanguageString $name, PostalAddress $postalAddress = null, string $addressId = null, string $addressIdDomain = null, string $email = null, string $phone = null, string $fax = null, string $url = null) + { + $this->addressId = $addressId; + $this->addressIdDomain = $addressIdDomain; + $this->name = $name; + $this->postalAddress = $postalAddress; + $this->email = $email; + $this->phone = $phone; + $this->fax = $fax; + $this->url = $url; + } + + public function getAddressId(): ?string + { + return $this->addressId; + } + + public function getAddressIdDomain(): ?string + { + return $this->addressIdDomain; + } + + public function getName(): MultilanguageString + { + return $this->name; + } + + public function getPostalAddress(): ?PostalAddress + { + return $this->postalAddress; + } + + public function getEmail(): ?string + { + return $this->email; + } + + public function getPhone(): ?string + { + return $this->phone; + } + + public function getFax(): ?string + { + return $this->fax; + } + + public function getUrl(): ?string + { + return $this->url; + } } diff --git a/src/CXml/Model/BillTo.php b/src/CXml/Model/BillTo.php index a825839..627f54c 100644 --- a/src/CXml/Model/BillTo.php +++ b/src/CXml/Model/BillTo.php @@ -6,20 +6,20 @@ class BillTo { - use IdReferencesTrait; + use IdReferencesTrait; - /** - * @Ser\SerializedName("Address") - */ - private Address $address; + /** + * @Ser\SerializedName("Address") + */ + private Address $address; - public function __construct(Address $address) - { - $this->address = $address; - } + public function __construct(Address $address) + { + $this->address = $address; + } - public function getAddress(): Address - { - return $this->address; - } + public function getAddress(): Address + { + return $this->address; + } } diff --git a/src/CXml/Model/CXml.php b/src/CXml/Model/CXml.php index f1ce34a..da7f848 100644 --- a/src/CXml/Model/CXml.php +++ b/src/CXml/Model/CXml.php @@ -12,135 +12,135 @@ */ class CXml { - /** - * @Ser\XmlAttribute(namespace="http://www.w3.org/XML/1998/namespace") - */ - private ?string $lang = null; - - /** - * @Ser\XmlAttribute() - * @Ser\SerializedName("payloadID") - */ - private string $payloadId; - - /** - * @Ser\XmlAttribute() - */ - private \DateTimeInterface $timestamp; - - /** - * @Ser\SerializedName("Header") - */ - private ?Header $header = null; - - /** - * @Ser\SerializedName("Request") - */ - private ?Request $request = null; - - /** - * @Ser\SerializedName("Response") - */ - private ?Response $response = null; - - /** - * @Ser\SerializedName("Message") - */ - private ?Message $message = null; - - protected function __construct( - string $payloadId, - \DateTimeInterface $timestamp, - ?Request $request, - Response $response = null, - Message $message = null, - Header $header = null, - string $lang = null - ) { - $this->request = $request; - $this->response = $response; - $this->header = $header; - $this->payloadId = $payloadId; - $this->timestamp = $timestamp; - $this->message = $message; - $this->lang = $lang; - } - - public static function forMessage(PayloadIdentity $payloadIdentity, Message $message, Header $header, string $lang = null): self - { - return new self($payloadIdentity->getPayloadId(), $payloadIdentity->getTimestamp(), null, null, $message, $header, $lang); - } - - public static function forRequest(PayloadIdentity $payloadIdentity, Request $request, Header $header, string $lang = null): self - { - return new self($payloadIdentity->getPayloadId(), $payloadIdentity->getTimestamp(), $request, null, null, $header, $lang); - } - - public static function forResponse(PayloadIdentity $payloadIdentity, Response $response, string $lang = null): self - { - return new self($payloadIdentity->getPayloadId(), $payloadIdentity->getTimestamp(), null, $response, null, null, $lang); - } - - public function getPayloadId(): string - { - return $this->payloadId; - } - - public function getTimestamp(): \DateTimeInterface - { - return $this->timestamp; - } - - public function getHeader(): ?Header - { - return $this->header; - } - - public function getRequest(): ?Request - { - return $this->request; - } - - public function getResponse(): ?Response - { - return $this->response; - } - - public function getMessage(): ?Message - { - return $this->message; - } - - public function __toString(): string - { - $wrapper = $this->message ?? $this->request ?? $this->response; - - $shortName = 'undefined'; - if ($wrapper) { - $payload = $wrapper->getPayload(); - - if ($payload) { - $shortName = (new \ReflectionClass($payload))->getShortName(); - } else { - $shortName = (new \ReflectionClass($wrapper))->getShortName(); - } - } - - return $shortName.'_'.$this->payloadId; - } - - public function getStatus(): ?Status - { - if ($this->request) { - return $this->request->getStatus(); - } - if ($this->message) { - return $this->message->getStatus(); - } - if ($this->response) { - return $this->response->getStatus(); - } - - return null; - } + /** + * @Ser\XmlAttribute(namespace="http://www.w3.org/XML/1998/namespace") + */ + private ?string $lang = null; + + /** + * @Ser\XmlAttribute() + * @Ser\SerializedName("payloadID") + */ + private string $payloadId; + + /** + * @Ser\XmlAttribute() + */ + private \DateTimeInterface $timestamp; + + /** + * @Ser\SerializedName("Header") + */ + private ?Header $header = null; + + /** + * @Ser\SerializedName("Request") + */ + private ?Request $request = null; + + /** + * @Ser\SerializedName("Response") + */ + private ?Response $response = null; + + /** + * @Ser\SerializedName("Message") + */ + private ?Message $message = null; + + protected function __construct( + string $payloadId, + \DateTimeInterface $timestamp, + ?Request $request, + Response $response = null, + Message $message = null, + Header $header = null, + string $lang = null + ) { + $this->request = $request; + $this->response = $response; + $this->header = $header; + $this->payloadId = $payloadId; + $this->timestamp = $timestamp; + $this->message = $message; + $this->lang = $lang; + } + + public static function forMessage(PayloadIdentity $payloadIdentity, Message $message, Header $header, string $lang = null): self + { + return new self($payloadIdentity->getPayloadId(), $payloadIdentity->getTimestamp(), null, null, $message, $header, $lang); + } + + public static function forRequest(PayloadIdentity $payloadIdentity, Request $request, Header $header, string $lang = null): self + { + return new self($payloadIdentity->getPayloadId(), $payloadIdentity->getTimestamp(), $request, null, null, $header, $lang); + } + + public static function forResponse(PayloadIdentity $payloadIdentity, Response $response, string $lang = null): self + { + return new self($payloadIdentity->getPayloadId(), $payloadIdentity->getTimestamp(), null, $response, null, null, $lang); + } + + public function getPayloadId(): string + { + return $this->payloadId; + } + + public function getTimestamp(): \DateTimeInterface + { + return $this->timestamp; + } + + public function getHeader(): ?Header + { + return $this->header; + } + + public function getRequest(): ?Request + { + return $this->request; + } + + public function getResponse(): ?Response + { + return $this->response; + } + + public function getMessage(): ?Message + { + return $this->message; + } + + public function __toString(): string + { + $wrapper = $this->message ?? $this->request ?? $this->response; + + $shortName = 'undefined'; + if ($wrapper) { + $payload = $wrapper->getPayload(); + + if ($payload) { + $shortName = (new \ReflectionClass($payload))->getShortName(); + } else { + $shortName = (new \ReflectionClass($wrapper))->getShortName(); + } + } + + return $shortName.'_'.$this->payloadId; + } + + public function getStatus(): ?Status + { + if ($this->request) { + return $this->request->getStatus(); + } + if ($this->message) { + return $this->message->getStatus(); + } + if ($this->response) { + return $this->response->getStatus(); + } + + return null; + } } diff --git a/src/CXml/Model/CarrierIdentifier.php b/src/CXml/Model/CarrierIdentifier.php index 23b36a1..6ff9232 100644 --- a/src/CXml/Model/CarrierIdentifier.php +++ b/src/CXml/Model/CarrierIdentifier.php @@ -6,39 +6,39 @@ class CarrierIdentifier { - public const DOMAIN_SCAC = 'SCAC'; - public const DOMAIN_COMPANYNAME = 'companyName'; - public const DOMAIN_SKU = 'sku'; - public const DOMAIN_CARRIER_METHOD = 'carrierMethod'; - - /** - * @Ser\XmlAttribute - */ - private string $domain; - - /** - * @Ser\XmlValue(cdata=false) - */ - private string $value; - - public function __construct(string $domain, string $value) - { - $this->domain = $domain; - $this->value = $value; - } - - public static function fromScacCode(string $scacCarrierCode): self - { - return new self(self::DOMAIN_SCAC, $scacCarrierCode); - } - - public function getDomain(): string - { - return $this->domain; - } - - public function getValue(): string - { - return $this->value; - } + public const DOMAIN_SCAC = 'SCAC'; + public const DOMAIN_COMPANYNAME = 'companyName'; + public const DOMAIN_SKU = 'sku'; + public const DOMAIN_CARRIER_METHOD = 'carrierMethod'; + + /** + * @Ser\XmlAttribute + */ + private string $domain; + + /** + * @Ser\XmlValue(cdata=false) + */ + private string $value; + + public function __construct(string $domain, string $value) + { + $this->domain = $domain; + $this->value = $value; + } + + public static function fromScacCode(string $scacCarrierCode): self + { + return new self(self::DOMAIN_SCAC, $scacCarrierCode); + } + + public function getDomain(): string + { + return $this->domain; + } + + public function getValue(): string + { + return $this->value; + } } diff --git a/src/CXml/Model/Classification.php b/src/CXml/Model/Classification.php index daa818d..07c4d12 100644 --- a/src/CXml/Model/Classification.php +++ b/src/CXml/Model/Classification.php @@ -6,19 +6,19 @@ class Classification { - /** - * @Ser\XmlAttribute - */ - private string $domain; + /** + * @Ser\XmlAttribute + */ + private string $domain; - /** - * @Ser\XmlValue(cdata=false) - */ - private string $value; + /** + * @Ser\XmlValue(cdata=false) + */ + private string $value; - public function __construct(string $domain, string $value) - { - $this->domain = $domain; - $this->value = $value; - } + public function __construct(string $domain, string $value) + { + $this->domain = $domain; + $this->value = $value; + } } diff --git a/src/CXml/Model/Comment.php b/src/CXml/Model/Comment.php index 70f4630..6e5daf1 100644 --- a/src/CXml/Model/Comment.php +++ b/src/CXml/Model/Comment.php @@ -6,51 +6,51 @@ class Comment { - /** - * @Ser\SerializedName("Attachment") - */ - private ?Url $attachment = null; - - /** - * @Ser\XmlValue(cdata=false) - */ - private ?string $value = null; - - /** - * @Ser\XmlAttribute(namespace="http://www.w3.org/XML/1998/namespace") - */ - private ?string $lang = null; - - /** - * @Ser\XmlAttribute() - */ - private ?string $type = null; - - public function __construct(string $value = null, string $type = null, string $lang = null, string $attachment = null) - { - $this->value = $value; - $this->type = $type; - $this->lang = $lang; - $this->attachment = $attachment ? new Url($attachment) : null; - } - - public function getAttachment(): ?Url - { - return $this->attachment; - } - - public function getValue(): ?string - { - return $this->value; - } - - public function getLang(): ?string - { - return $this->lang; - } - - public function getType(): ?string - { - return $this->type; - } + /** + * @Ser\SerializedName("Attachment") + */ + private ?Url $attachment = null; + + /** + * @Ser\XmlValue(cdata=false) + */ + private ?string $value = null; + + /** + * @Ser\XmlAttribute(namespace="http://www.w3.org/XML/1998/namespace") + */ + private ?string $lang = null; + + /** + * @Ser\XmlAttribute() + */ + private ?string $type = null; + + public function __construct(string $value = null, string $type = null, string $lang = null, string $attachment = null) + { + $this->value = $value; + $this->type = $type; + $this->lang = $lang; + $this->attachment = $attachment ? new Url($attachment) : null; + } + + public function getAttachment(): ?Url + { + return $this->attachment; + } + + public function getValue(): ?string + { + return $this->value; + } + + public function getLang(): ?string + { + return $this->lang; + } + + public function getType(): ?string + { + return $this->type; + } } diff --git a/src/CXml/Model/Contact.php b/src/CXml/Model/Contact.php index fbc8d7e..27aabc9 100644 --- a/src/CXml/Model/Contact.php +++ b/src/CXml/Model/Contact.php @@ -6,66 +6,66 @@ class Contact { - use ExtrinsicsTrait; - use IdReferencesTrait; + use ExtrinsicsTrait; + use IdReferencesTrait; - public const ROLE_ENDUSER = 'endUser'; - public const ROLE_ADMINISTRATOR = 'administrator'; - public const ROLE_PURCHASINGAGENT = 'purchasingAgent'; - public const ROLE_TECHNICALSUPPORT = 'technicalSupport'; - public const ROLE_CUSTOMERSERVICE = 'customerService'; - public const ROLE_SALES = 'sales'; - public const ROLE_SUPPLIERCORPORATE = 'supplierCorporate'; - public const ROLE_SUPPLIERMASTERACCOUNT = 'supplierMasterAccount'; - public const ROLE_SUPPLIERACCOUNT = 'supplierAccount'; - public const ROLE_BUYERCORPORATE = 'buyerCorporate'; - public const ROLE_BUYERMASTERACCOUNT = 'buyerMasterAccount'; - public const ROLE_BUYERACCOUNT = 'buyerAccount'; - public const ROLE_BUYER = 'buyer'; - public const ROLE_SUBSEQUENTBUYER = 'subsequentBuyer'; + public const ROLE_ENDUSER = 'endUser'; + public const ROLE_ADMINISTRATOR = 'administrator'; + public const ROLE_PURCHASINGAGENT = 'purchasingAgent'; + public const ROLE_TECHNICALSUPPORT = 'technicalSupport'; + public const ROLE_CUSTOMERSERVICE = 'customerService'; + public const ROLE_SALES = 'sales'; + public const ROLE_SUPPLIERCORPORATE = 'supplierCorporate'; + public const ROLE_SUPPLIERMASTERACCOUNT = 'supplierMasterAccount'; + public const ROLE_SUPPLIERACCOUNT = 'supplierAccount'; + public const ROLE_BUYERCORPORATE = 'buyerCorporate'; + public const ROLE_BUYERMASTERACCOUNT = 'buyerMasterAccount'; + public const ROLE_BUYERACCOUNT = 'buyerAccount'; + public const ROLE_BUYER = 'buyer'; + public const ROLE_SUBSEQUENTBUYER = 'subsequentBuyer'; - /** - * @Ser\XmlAttribute - */ - private ?string $role = null; + /** + * @Ser\XmlAttribute + */ + private ?string $role = null; - /** - * @Ser\SerializedName("Name") - * @Ser\XmlElement (cdata=false) - */ - private MultilanguageString $name; + /** + * @Ser\SerializedName("Name") + * @Ser\XmlElement (cdata=false) + */ + private MultilanguageString $name; - /** - * @Ser\SerializedName("Email") - * @Ser\XmlElement (cdata=false) - */ - private ?string $email = null; + /** + * @Ser\SerializedName("Email") + * @Ser\XmlElement (cdata=false) + */ + private ?string $email = null; - public function __construct(MultilanguageString $name, string $role = null) - { - $this->role = $role; - $this->name = $name; - } + public function __construct(MultilanguageString $name, string $role = null) + { + $this->role = $role; + $this->name = $name; + } - public static function create(MultilanguageString $name, string $role = null): self - { - return new self($name, $role); - } + public static function create(MultilanguageString $name, string $role = null): self + { + return new self($name, $role); + } - public function getRole(): ?string - { - return $this->role; - } + public function getRole(): ?string + { + return $this->role; + } - public function getName(): MultilanguageString - { - return $this->name; - } + public function getName(): MultilanguageString + { + return $this->name; + } - public function addEmail(string $email): self - { - $this->email = $email; + public function addEmail(string $email): self + { + $this->email = $email; - return $this; - } + return $this; + } } diff --git a/src/CXml/Model/Country.php b/src/CXml/Model/Country.php index 7b904c4..692b20a 100644 --- a/src/CXml/Model/Country.php +++ b/src/CXml/Model/Country.php @@ -6,30 +6,30 @@ class Country { - /** - * @Ser\XmlAttribute - * @Ser\SerializedName("isoCountryCode") - */ - private string $isoCountryCode; + /** + * @Ser\XmlAttribute + * @Ser\SerializedName("isoCountryCode") + */ + private string $isoCountryCode; - /** - * @Ser\XmlValue(cdata=false) - */ - private ?string $name = null; + /** + * @Ser\XmlValue(cdata=false) + */ + private ?string $name = null; - public function __construct(string $isoCountryCode, string $name = null) - { - $this->isoCountryCode = $isoCountryCode; - $this->name = $name; - } + public function __construct(string $isoCountryCode, string $name = null) + { + $this->isoCountryCode = $isoCountryCode; + $this->name = $name; + } - public function getIsoCountryCode(): string - { - return $this->isoCountryCode; - } + public function getIsoCountryCode(): string + { + return $this->isoCountryCode; + } - public function getName(): ?string - { - return $this->name; - } + public function getName(): ?string + { + return $this->name; + } } diff --git a/src/CXml/Model/Credential.php b/src/CXml/Model/Credential.php index 53adfa2..8b20e2d 100644 --- a/src/CXml/Model/Credential.php +++ b/src/CXml/Model/Credential.php @@ -6,58 +6,58 @@ class Credential { - /** - * @Ser\XmlAttribute - */ - private string $domain; - - /** - * @Ser\SerializedName("Identity") - * @Ser\XmlElement (cdata=false) - */ - private string $identity; - - /** - * @Ser\SerializedName("CredentialMac") - * @Ser\XmlElement (cdata=false) - */ - // private CredentialMac $credentialMac; TODO - - /** - * @Ser\SerializedName("SharedSecret") - * @Ser\XmlElement (cdata=false) - */ - private ?string $sharedSecret = null; - - public function __construct(string $domain, string $identity, string $sharedSecret = null) - { - $this->domain = $domain; - $this->identity = $identity; - $this->sharedSecret = $sharedSecret; - } - - public function getDomain(): string - { - return $this->domain; - } - - public function getIdentity(): string - { - return $this->identity; - } - - public function getSharedSecret(): ?string - { - return $this->sharedSecret; - } - - public function setSharedSecret(?string $sharedSecret): void - { - $this->sharedSecret = $sharedSecret; - } - - public function __toString(): string - { - return \sprintf('%s@%s', $this->identity, $this->domain); - } + /** + * @Ser\XmlAttribute + */ + private string $domain; + + /** + * @Ser\SerializedName("Identity") + * @Ser\XmlElement (cdata=false) + */ + private string $identity; + + /** + * @Ser\SerializedName("CredentialMac") + * @Ser\XmlElement (cdata=false) + */ + // private CredentialMac $credentialMac; TODO + + /** + * @Ser\SerializedName("SharedSecret") + * @Ser\XmlElement (cdata=false) + */ + private ?string $sharedSecret = null; + + public function __construct(string $domain, string $identity, string $sharedSecret = null) + { + $this->domain = $domain; + $this->identity = $identity; + $this->sharedSecret = $sharedSecret; + } + + public function getDomain(): string + { + return $this->domain; + } + + public function getIdentity(): string + { + return $this->identity; + } + + public function getSharedSecret(): ?string + { + return $this->sharedSecret; + } + + public function setSharedSecret(?string $sharedSecret): void + { + $this->sharedSecret = $sharedSecret; + } + + public function __toString(): string + { + return \sprintf('%s@%s', $this->identity, $this->domain); + } } diff --git a/src/CXml/Model/Date.php b/src/CXml/Model/Date.php index e747bc5..102c998 100644 --- a/src/CXml/Model/Date.php +++ b/src/CXml/Model/Date.php @@ -3,42 +3,42 @@ namespace CXml\Model; if (\PHP_VERSION_ID < 80000) { - /** - * Represents a date *without* time. This is a separate class to allow for different serialization formats. - */ - class Date extends \DateTime - { - #[\ReturnTypeWillChange] - public static function createFromFormat($format, $datetime, \DateTimeZone $timezone = null) - { - $dateTime = parent::createFromFormat($format, $datetime, $timezone); - if (!$dateTime) { - return false; - } + /** + * Represents a date *without* time. This is a separate class to allow for different serialization formats. + */ + class Date extends \DateTime + { + #[\ReturnTypeWillChange] + public static function createFromFormat($format, $datetime, \DateTimeZone $timezone = null) + { + $dateTime = parent::createFromFormat($format, $datetime, $timezone); + if (!$dateTime) { + return false; + } - return new self($dateTime->format('Y-m-d'), $timezone); - } + return new self($dateTime->format('Y-m-d'), $timezone); + } - public static function createFromInterface(\DateTimeInterface $object): \DateTime - { - return new self($object->format('Y-m-d'), $object->getTimezone()); - } - } + public static function createFromInterface(\DateTimeInterface $object): \DateTime + { + return new self($object->format('Y-m-d'), $object->getTimezone()); + } + } } else { - /** - * Represents a date *without* time. This is a separate class to allow for different serialization formats. - */ - class Date extends \DateTime - { - #[\ReturnTypeWillChange] - public static function createFromFormat($format, $datetime, \DateTimeZone $timezone = null) - { - $dateTime = parent::createFromFormat($format, $datetime, $timezone); - if (!$dateTime) { - return false; - } + /** + * Represents a date *without* time. This is a separate class to allow for different serialization formats. + */ + class Date extends \DateTime + { + #[\ReturnTypeWillChange] + public static function createFromFormat($format, $datetime, \DateTimeZone $timezone = null) + { + $dateTime = parent::createFromFormat($format, $datetime, $timezone); + if (!$dateTime) { + return false; + } - return new self($dateTime->format('Y-m-d'), $timezone); - } - } + return new self($dateTime->format('Y-m-d'), $timezone); + } + } } diff --git a/src/CXml/Model/Description.php b/src/CXml/Model/Description.php index d303862..147d5a6 100644 --- a/src/CXml/Model/Description.php +++ b/src/CXml/Model/Description.php @@ -6,27 +6,27 @@ class Description extends MultilanguageString { - /** - * @Ser\SerializedName("ShortName") - * @Ser\XmlElement(cdata=false) - */ - private ?string $shortName = null; + /** + * @Ser\SerializedName("ShortName") + * @Ser\XmlElement(cdata=false) + */ + private ?string $shortName = null; - public function __construct(?string $value, string $type = null, string $lang = 'en') - { - parent::__construct($value, $type, $lang); - } + public function __construct(?string $value, string $type = null, string $lang = 'en') + { + parent::__construct($value, $type, $lang); + } - public static function createWithShortName(string $shortName, string $type = null, string $lang = 'en'): self - { - $new = new self(null, $type, $lang); - $new->setShortname($shortName); + public static function createWithShortName(string $shortName, string $type = null, string $lang = 'en'): self + { + $new = new self(null, $type, $lang); + $new->setShortname($shortName); - return $new; - } + return $new; + } - public function setShortname(?string $shortName): void - { - $this->shortName = $shortName; - } + public function setShortname(?string $shortName): void + { + $this->shortName = $shortName; + } } diff --git a/src/CXml/Model/DocumentReference.php b/src/CXml/Model/DocumentReference.php index 07d9aff..95167d0 100644 --- a/src/CXml/Model/DocumentReference.php +++ b/src/CXml/Model/DocumentReference.php @@ -6,19 +6,19 @@ class DocumentReference { - /** - * @Ser\XmlAttribute - * @Ser\SerializedName("payloadID") - */ - private string $payloadId; + /** + * @Ser\XmlAttribute + * @Ser\SerializedName("payloadID") + */ + private string $payloadId; - public function __construct(string $payloadId) - { - $this->payloadId = $payloadId; - } + public function __construct(string $payloadId) + { + $this->payloadId = $payloadId; + } - public function getPayloadId(): string - { - return $this->payloadId; - } + public function getPayloadId(): string + { + return $this->payloadId; + } } diff --git a/src/CXml/Model/Extrinsic.php b/src/CXml/Model/Extrinsic.php index eddd755..ae9bbed 100644 --- a/src/CXml/Model/Extrinsic.php +++ b/src/CXml/Model/Extrinsic.php @@ -6,29 +6,29 @@ class Extrinsic { - /** - * @Ser\XmlAttribute - */ - private string $name; + /** + * @Ser\XmlAttribute + */ + private string $name; - /** - * @Ser\XmlValue(cdata=false) - */ - private string $value; + /** + * @Ser\XmlValue(cdata=false) + */ + private string $value; - public function __construct(string $name, string $value) - { - $this->name = $name; - $this->value = $value; - } + public function __construct(string $name, string $value) + { + $this->name = $name; + $this->value = $value; + } - public function getName(): string - { - return $this->name; - } + public function getName(): string + { + return $this->name; + } - public function getValue(): string - { - return $this->value; - } + public function getValue(): string + { + return $this->value; + } } diff --git a/src/CXml/Model/ExtrinsicsTrait.php b/src/CXml/Model/ExtrinsicsTrait.php index 188da47..16a2322 100644 --- a/src/CXml/Model/ExtrinsicsTrait.php +++ b/src/CXml/Model/ExtrinsicsTrait.php @@ -6,59 +6,59 @@ trait ExtrinsicsTrait { - /** - * @Ser\XmlList(inline=true, entry="Extrinsic") - * @Ser\Type("array") - * - * @var Extrinsic[] - */ - protected array $extrinsics = []; + /** + * @Ser\XmlList(inline=true, entry="Extrinsic") + * @Ser\Type("array") + * + * @var Extrinsic[] + */ + protected array $extrinsics = []; - public function addExtrinsic(Extrinsic $extrinsic): self - { - $this->extrinsics[] = $extrinsic; + public function addExtrinsic(Extrinsic $extrinsic): self + { + $this->extrinsics[] = $extrinsic; - return $this; - } + return $this; + } - /** - * @return Extrinsic[] - */ - public function getExtrinsics(): array - { - return $this->extrinsics; - } + /** + * @return Extrinsic[] + */ + public function getExtrinsics(): array + { + return $this->extrinsics; + } - public function getExtrinsicByName(string $name): ?Extrinsic - { - foreach ($this->extrinsics as $extrinsic) { - if ($extrinsic->getName() === $name) { - return $extrinsic; - } - } + public function getExtrinsicByName(string $name): ?Extrinsic + { + foreach ($this->extrinsics as $extrinsic) { + if ($extrinsic->getName() === $name) { + return $extrinsic; + } + } - return null; - } + return null; + } - /** - * Convenience method. - */ - public function addExtrinsicAsKeyValue(string $name, string $value): self - { - return $this->addExtrinsic(new Extrinsic($name, $value)); - } + /** + * Convenience method. + */ + public function addExtrinsicAsKeyValue(string $name, string $value): self + { + return $this->addExtrinsic(new Extrinsic($name, $value)); + } - /** - * Convenience method. - */ - public function getExtrinsicsAsKeyValue(): array - { - $extrinsics = []; + /** + * Convenience method. + */ + public function getExtrinsicsAsKeyValue(): array + { + $extrinsics = []; - foreach ($this->getExtrinsics() as $extrinsic) { - $extrinsics[\trim($extrinsic->getName())] = \trim($extrinsic->getValue()); - } + foreach ($this->getExtrinsics() as $extrinsic) { + $extrinsics[\trim($extrinsic->getName())] = \trim($extrinsic->getValue()); + } - return $extrinsics; - } + return $extrinsics; + } } diff --git a/src/CXml/Model/Header.php b/src/CXml/Model/Header.php index 099b80f..2865371 100644 --- a/src/CXml/Model/Header.php +++ b/src/CXml/Model/Header.php @@ -6,40 +6,40 @@ class Header { - /** - * @Ser\SerializedName("From") - */ - private Party $from; - - /** - * @Ser\SerializedName("To") - */ - private Party $to; - - /** - * @Ser\SerializedName("Sender") - */ - private Party $sender; - - public function __construct(Party $from, Party $to, Party $sender) - { - $this->from = $from; - $this->to = $to; - $this->sender = $sender; - } - - public function getFrom(): Party - { - return $this->from; - } - - public function getTo(): Party - { - return $this->to; - } - - public function getSender(): Party - { - return $this->sender; - } + /** + * @Ser\SerializedName("From") + */ + private Party $from; + + /** + * @Ser\SerializedName("To") + */ + private Party $to; + + /** + * @Ser\SerializedName("Sender") + */ + private Party $sender; + + public function __construct(Party $from, Party $to, Party $sender) + { + $this->from = $from; + $this->to = $to; + $this->sender = $sender; + } + + public function getFrom(): Party + { + return $this->from; + } + + public function getTo(): Party + { + return $this->to; + } + + public function getSender(): Party + { + return $this->sender; + } } diff --git a/src/CXml/Model/IdReference.php b/src/CXml/Model/IdReference.php index ad50009..f8c83e3 100644 --- a/src/CXml/Model/IdReference.php +++ b/src/CXml/Model/IdReference.php @@ -6,29 +6,29 @@ class IdReference { - /** - * @Ser\XmlAttribute - */ - private string $domain; + /** + * @Ser\XmlAttribute + */ + private string $domain; - /** - * @Ser\XmlAttribute - */ - private string $identifier; + /** + * @Ser\XmlAttribute + */ + private string $identifier; - public function __construct(string $domain, string $identifier) - { - $this->domain = $domain; - $this->identifier = $identifier; - } + public function __construct(string $domain, string $identifier) + { + $this->domain = $domain; + $this->identifier = $identifier; + } - public function getDomain(): string - { - return $this->domain; - } + public function getDomain(): string + { + return $this->domain; + } - public function getIdentifier(): string - { - return $this->identifier; - } + public function getIdentifier(): string + { + return $this->identifier; + } } diff --git a/src/CXml/Model/IdReferencesTrait.php b/src/CXml/Model/IdReferencesTrait.php index 9489585..8fbbf64 100644 --- a/src/CXml/Model/IdReferencesTrait.php +++ b/src/CXml/Model/IdReferencesTrait.php @@ -6,34 +6,34 @@ trait IdReferencesTrait { - /** - * @Ser\XmlList(inline=true, entry="IdReference") - * @Ser\Type("array") - * - * @var IdReference[] - */ - protected array $idReferences = []; - - public function addIdReference(string $domain, string $identifier): self - { - $this->idReferences[] = new IdReference($domain, $identifier); - - return $this; - } - - public function getIdReferences(): array - { - return $this->idReferences; - } - - public function getIdReference(string $domain): ?string - { - foreach ($this->idReferences as $idReference) { - if ($idReference->getDomain() === $domain) { - return $idReference->getIdentifier(); - } - } - - return null; - } + /** + * @Ser\XmlList(inline=true, entry="IdReference") + * @Ser\Type("array") + * + * @var IdReference[] + */ + protected array $idReferences = []; + + public function addIdReference(string $domain, string $identifier): self + { + $this->idReferences[] = new IdReference($domain, $identifier); + + return $this; + } + + public function getIdReferences(): array + { + return $this->idReferences; + } + + public function getIdReference(string $domain): ?string + { + foreach ($this->idReferences as $idReference) { + if ($idReference->getDomain() === $domain) { + return $idReference->getIdentifier(); + } + } + + return null; + } } diff --git a/src/CXml/Model/Inventory.php b/src/CXml/Model/Inventory.php index 6846ffc..db45ec3 100644 --- a/src/CXml/Model/Inventory.php +++ b/src/CXml/Model/Inventory.php @@ -6,42 +6,42 @@ class Inventory { - /** - * @Ser\SerializedName("StockOnHandQuantity") - */ - private ?InventoryQuantity $stockOnHandQuantity = null; - - /** - * @Ser\SerializedName("IncrementQuantity") - */ - private ?InventoryQuantity $incrementQuantity = null; - - public static function create(): self - { - return new self(); - } - - public function getStockOnHandQuantity(): ?InventoryQuantity - { - return $this->stockOnHandQuantity; - } - - public function setStockOnHandQuantity(InventoryQuantity $stockOnHandQuantity): self - { - $this->stockOnHandQuantity = $stockOnHandQuantity; - - return $this; - } - - public function getIncrementQuantity(): ?InventoryQuantity - { - return $this->incrementQuantity; - } - - public function setIncrementQuantity(InventoryQuantity $incrementQuantity): self - { - $this->incrementQuantity = $incrementQuantity; - - return $this; - } + /** + * @Ser\SerializedName("StockOnHandQuantity") + */ + private ?InventoryQuantity $stockOnHandQuantity = null; + + /** + * @Ser\SerializedName("IncrementQuantity") + */ + private ?InventoryQuantity $incrementQuantity = null; + + public static function create(): self + { + return new self(); + } + + public function getStockOnHandQuantity(): ?InventoryQuantity + { + return $this->stockOnHandQuantity; + } + + public function setStockOnHandQuantity(InventoryQuantity $stockOnHandQuantity): self + { + $this->stockOnHandQuantity = $stockOnHandQuantity; + + return $this; + } + + public function getIncrementQuantity(): ?InventoryQuantity + { + return $this->incrementQuantity; + } + + public function setIncrementQuantity(InventoryQuantity $incrementQuantity): self + { + $this->incrementQuantity = $incrementQuantity; + + return $this; + } } diff --git a/src/CXml/Model/InventoryQuantity.php b/src/CXml/Model/InventoryQuantity.php index 3e8c4cf..f06cd14 100644 --- a/src/CXml/Model/InventoryQuantity.php +++ b/src/CXml/Model/InventoryQuantity.php @@ -6,29 +6,29 @@ class InventoryQuantity { - /** - * @Ser\XmlAttribute - */ - private int $quantity; + /** + * @Ser\XmlAttribute + */ + private int $quantity; - /** - * @Ser\SerializedName("UnitOfMeasure") - */ - private UnitOfMeasure $unitOfMeasure; + /** + * @Ser\SerializedName("UnitOfMeasure") + */ + private UnitOfMeasure $unitOfMeasure; - public function __construct(int $quantity, string $unitOfMeasure) - { - $this->quantity = $quantity; - $this->unitOfMeasure = new UnitOfMeasure($unitOfMeasure); - } + public function __construct(int $quantity, string $unitOfMeasure) + { + $this->quantity = $quantity; + $this->unitOfMeasure = new UnitOfMeasure($unitOfMeasure); + } - public function getQuantity(): int - { - return $this->quantity; - } + public function getQuantity(): int + { + return $this->quantity; + } - public function getUnitOfMeasure(): string - { - return $this->unitOfMeasure->getValue(); - } + public function getUnitOfMeasure(): string + { + return $this->unitOfMeasure->getValue(); + } } diff --git a/src/CXml/Model/ItemDetail.php b/src/CXml/Model/ItemDetail.php index b10f1da..e9e1623 100644 --- a/src/CXml/Model/ItemDetail.php +++ b/src/CXml/Model/ItemDetail.php @@ -7,151 +7,151 @@ class ItemDetail { - use ExtrinsicsTrait; - public const UNIT_OF_MEASURE_EACH = 'EA'; - - /** - * @Ser\SerializedName("UnitPrice") - */ - private MoneyWrapper $unitPrice; - - /** - * @Ser\SerializedName("Description") - * @Ser\XmlElement (cdata=false) - */ - private Description $description; - - /** - * @Ser\SerializedName("UnitOfMeasure") - * @Ser\XmlElement (cdata=false) - */ - private string $unitOfMeasure; - - /** - * @Ser\XmlList(inline=true, entry="Classification") - * @Ser\Type("array") - * - * @var Classification[] - */ - private array $classifications = []; - - /** - * @Ser\SerializedName("ManufacturerPartID") - * @Ser\XmlElement (cdata=false) - */ - private ?string $manufacturerPartId = null; - - /** - * @Ser\SerializedName("ManufacturerName") - * @Ser\XmlElement (cdata=false) - */ - private ?string $manufacturerName = null; - - /** - * @Ser\SerializedName("URL") - * @Ser\XmlElement (cdata=false) - */ - private ?string $url = null; - - /** - * @Ser\SerializedName("LeadTime") - * @Ser\XmlElement (cdata=false) - */ - private ?int $leadtime = null; - - protected function __construct(Description $description, string $unitOfMeasure, MoneyWrapper $unitPrice) - { - $this->description = $description; - $this->unitOfMeasure = $unitOfMeasure; - $this->unitPrice = $unitPrice; - } - - public static function create(Description $description, string $unitOfMeasure, MoneyWrapper $unitPrice, array $classifications): self - { - Assertion::allIsInstanceOf($classifications, Classification::class); - Assertion::notEmpty($classifications); // at least one classification is necessary (via DTD) - - $itemDetail = new self($description, $unitOfMeasure, $unitPrice); - - foreach ($classifications as $classification) { - $itemDetail->addClassification($classification); - } - - return $itemDetail; - } - - public function setUrl(?string $url): self - { - $this->url = $url; - - return $this; - } - - public function setLeadtime(?int $leadtime): self - { - $this->leadtime = $leadtime; - - return $this; - } - - public function setManufacturerPartId(?string $manufacturerPartId): self - { - $this->manufacturerPartId = $manufacturerPartId; - - return $this; - } - - public function setManufacturerName(?string $manufacturerName): self - { - $this->manufacturerName = $manufacturerName; - - return $this; - } - - public function addClassification(Classification $classification): self - { - $this->classifications[] = $classification; - - return $this; - } - - public function getUnitPrice(): MoneyWrapper - { - return $this->unitPrice; - } - - public function getDescription(): Description - { - return $this->description; - } - - public function getUnitOfMeasure(): string - { - return $this->unitOfMeasure; - } - - public function getClassifications(): array - { - return $this->classifications; - } - - public function getManufacturerPartId(): ?string - { - return $this->manufacturerPartId; - } - - public function getManufacturerName(): ?string - { - return $this->manufacturerName; - } - - public function getUrl(): ?string - { - return $this->url; - } - - public function getLeadtime(): ?int - { - return $this->leadtime; - } + use ExtrinsicsTrait; + public const UNIT_OF_MEASURE_EACH = 'EA'; + + /** + * @Ser\SerializedName("UnitPrice") + */ + private MoneyWrapper $unitPrice; + + /** + * @Ser\SerializedName("Description") + * @Ser\XmlElement (cdata=false) + */ + private Description $description; + + /** + * @Ser\SerializedName("UnitOfMeasure") + * @Ser\XmlElement (cdata=false) + */ + private string $unitOfMeasure; + + /** + * @Ser\XmlList(inline=true, entry="Classification") + * @Ser\Type("array") + * + * @var Classification[] + */ + private array $classifications = []; + + /** + * @Ser\SerializedName("ManufacturerPartID") + * @Ser\XmlElement (cdata=false) + */ + private ?string $manufacturerPartId = null; + + /** + * @Ser\SerializedName("ManufacturerName") + * @Ser\XmlElement (cdata=false) + */ + private ?string $manufacturerName = null; + + /** + * @Ser\SerializedName("URL") + * @Ser\XmlElement (cdata=false) + */ + private ?string $url = null; + + /** + * @Ser\SerializedName("LeadTime") + * @Ser\XmlElement (cdata=false) + */ + private ?int $leadtime = null; + + protected function __construct(Description $description, string $unitOfMeasure, MoneyWrapper $unitPrice) + { + $this->description = $description; + $this->unitOfMeasure = $unitOfMeasure; + $this->unitPrice = $unitPrice; + } + + public static function create(Description $description, string $unitOfMeasure, MoneyWrapper $unitPrice, array $classifications): self + { + Assertion::allIsInstanceOf($classifications, Classification::class); + Assertion::notEmpty($classifications); // at least one classification is necessary (via DTD) + + $itemDetail = new self($description, $unitOfMeasure, $unitPrice); + + foreach ($classifications as $classification) { + $itemDetail->addClassification($classification); + } + + return $itemDetail; + } + + public function setUrl(?string $url): self + { + $this->url = $url; + + return $this; + } + + public function setLeadtime(?int $leadtime): self + { + $this->leadtime = $leadtime; + + return $this; + } + + public function setManufacturerPartId(?string $manufacturerPartId): self + { + $this->manufacturerPartId = $manufacturerPartId; + + return $this; + } + + public function setManufacturerName(?string $manufacturerName): self + { + $this->manufacturerName = $manufacturerName; + + return $this; + } + + public function addClassification(Classification $classification): self + { + $this->classifications[] = $classification; + + return $this; + } + + public function getUnitPrice(): MoneyWrapper + { + return $this->unitPrice; + } + + public function getDescription(): Description + { + return $this->description; + } + + public function getUnitOfMeasure(): string + { + return $this->unitOfMeasure; + } + + public function getClassifications(): array + { + return $this->classifications; + } + + public function getManufacturerPartId(): ?string + { + return $this->manufacturerPartId; + } + + public function getManufacturerName(): ?string + { + return $this->manufacturerName; + } + + public function getUrl(): ?string + { + return $this->url; + } + + public function getLeadtime(): ?int + { + return $this->leadtime; + } } diff --git a/src/CXml/Model/ItemId.php b/src/CXml/Model/ItemId.php index ed05c11..af3cc17 100644 --- a/src/CXml/Model/ItemId.php +++ b/src/CXml/Model/ItemId.php @@ -6,45 +6,45 @@ class ItemId { - use IdReferencesTrait; - - /** - * @Ser\SerializedName("SupplierPartID") - * @Ser\XmlElement (cdata=false) - */ - private string $supplierPartId; - - /** - * @Ser\SerializedName("SupplierPartAuxiliaryID") - * @Ser\XmlElement (cdata=false) - */ - private ?string $supplierPartAuxiliaryId = null; - - /** - * @Ser\SerializedName("BuyerPartID") - * @Ser\XmlElement (cdata=false) - */ - private ?string $buyerPartId = null; - - public function __construct(string $supplierPartId, string $supplierPartAuxiliaryId = null, string $buyerPartId = null) - { - $this->supplierPartId = $supplierPartId; - $this->supplierPartAuxiliaryId = $supplierPartAuxiliaryId; - $this->buyerPartId = $buyerPartId; - } - - public function getSupplierPartId(): string - { - return $this->supplierPartId; - } - - public function getSupplierPartAuxiliaryId(): ?string - { - return $this->supplierPartAuxiliaryId; - } - - public function getBuyerPartId(): ?string - { - return $this->buyerPartId; - } + use IdReferencesTrait; + + /** + * @Ser\SerializedName("SupplierPartID") + * @Ser\XmlElement (cdata=false) + */ + private string $supplierPartId; + + /** + * @Ser\SerializedName("SupplierPartAuxiliaryID") + * @Ser\XmlElement (cdata=false) + */ + private ?string $supplierPartAuxiliaryId = null; + + /** + * @Ser\SerializedName("BuyerPartID") + * @Ser\XmlElement (cdata=false) + */ + private ?string $buyerPartId = null; + + public function __construct(string $supplierPartId, string $supplierPartAuxiliaryId = null, string $buyerPartId = null) + { + $this->supplierPartId = $supplierPartId; + $this->supplierPartAuxiliaryId = $supplierPartAuxiliaryId; + $this->buyerPartId = $buyerPartId; + } + + public function getSupplierPartId(): string + { + return $this->supplierPartId; + } + + public function getSupplierPartAuxiliaryId(): ?string + { + return $this->supplierPartAuxiliaryId; + } + + public function getBuyerPartId(): ?string + { + return $this->buyerPartId; + } } diff --git a/src/CXml/Model/ItemIn.php b/src/CXml/Model/ItemIn.php index 6629b9d..09d37e1 100644 --- a/src/CXml/Model/ItemIn.php +++ b/src/CXml/Model/ItemIn.php @@ -6,64 +6,64 @@ class ItemIn { - /** - * @Ser\XmlAttribute - * @Ser\SerializedName("quantity") - */ - private int $quantity; + /** + * @Ser\XmlAttribute + * @Ser\SerializedName("quantity") + */ + private int $quantity; - /** - * @Ser\SerializedName("ItemID") - */ - private ItemId $itemId; + /** + * @Ser\SerializedName("ItemID") + */ + private ItemId $itemId; - /** - * @Ser\SerializedName("ItemDetail") - */ - private ItemDetail $itemDetail; + /** + * @Ser\SerializedName("ItemDetail") + */ + private ItemDetail $itemDetail; - protected function __construct( - int $quantity, - ItemId $itemId, - ItemDetail $itemDetail - ) { - $this->quantity = $quantity; - $this->itemId = $itemId; - $this->itemDetail = $itemDetail; - } + protected function __construct( + int $quantity, + ItemId $itemId, + ItemDetail $itemDetail + ) { + $this->quantity = $quantity; + $this->itemId = $itemId; + $this->itemDetail = $itemDetail; + } - public static function create( - int $quantity, - ItemId $itemId, - ItemDetail $itemDetail - ): self { - return new self( - $quantity, - $itemId, - $itemDetail, - ); - } + public static function create( + int $quantity, + ItemId $itemId, + ItemDetail $itemDetail + ): self { + return new self( + $quantity, + $itemId, + $itemDetail, + ); + } - public function addClassification(string $domain, string $value): self - { - $classification = new Classification($domain, $value); - $this->itemDetail->addClassification($classification); + public function addClassification(string $domain, string $value): self + { + $classification = new Classification($domain, $value); + $this->itemDetail->addClassification($classification); - return $this; - } + return $this; + } - public function getQuantity(): int - { - return $this->quantity; - } + public function getQuantity(): int + { + return $this->quantity; + } - public function getItemId(): ItemId - { - return $this->itemId; - } + public function getItemId(): ItemId + { + return $this->itemId; + } - public function getItemDetail(): ItemDetail - { - return $this->itemDetail; - } + public function getItemDetail(): ItemDetail + { + return $this->itemDetail; + } } diff --git a/src/CXml/Model/ItemOut.php b/src/CXml/Model/ItemOut.php index c24f277..45744cd 100644 --- a/src/CXml/Model/ItemOut.php +++ b/src/CXml/Model/ItemOut.php @@ -6,109 +6,109 @@ class ItemOut { - /** - * @Ser\XmlAttribute - * @Ser\SerializedName("lineNumber") - */ - private int $lineNumber; - - /** - * @Ser\XmlAttribute - * @Ser\SerializedName("quantity") - */ - private int $quantity; - - /** - * @Ser\XmlAttribute - * @Ser\SerializedName("requestedDeliveryDate") - */ - private ?\DateTimeInterface $requestedDeliveryDate = null; - - /** - * @Ser\XmlAttribute - * @Ser\SerializedName("parentLineNumber") - */ - private ?int $parentLineNumber = null; - - /** - * @Ser\SerializedName("ItemID") - */ - private ItemId $itemId; - - /** - * @Ser\SerializedName("ItemDetail") - */ - private ItemDetail $itemDetail; - - private function __construct( - int $lineNumber, - int $quantity, - ItemId $itemId, - ItemDetail $itemDetail, - \DateTimeInterface $requestedDeliveryDate = null, - int $parentLineNumber = null - ) { - $this->lineNumber = $lineNumber; - $this->quantity = $quantity; - $this->itemId = $itemId; - $this->itemDetail = $itemDetail; - $this->requestedDeliveryDate = $requestedDeliveryDate; - $this->parentLineNumber = $parentLineNumber; - } - - public static function create( - int $lineNumber, - int $quantity, - ItemId $itemId, - ItemDetail $itemDetail, - \DateTimeInterface $requestedDeliveryDate = null, - int $parentLineNumber = null - ): self { - return new self( - $lineNumber, - $quantity, - $itemId, - $itemDetail, - $requestedDeliveryDate, - $parentLineNumber - ); - } - - public function addClassification(string $domain, string $value): self - { - $classification = new Classification($domain, $value); - $this->itemDetail->addClassification($classification); - - return $this; - } - - public function getLineNumber(): int - { - return $this->lineNumber; - } - - public function getQuantity(): int - { - return $this->quantity; - } - - public function getRequestedDeliveryDate(): ?\DateTimeInterface - { - return $this->requestedDeliveryDate; - } - - public function getItemId(): ItemId - { - return $this->itemId; - } - - public function getItemDetail(): ItemDetail - { - return $this->itemDetail; - } - - public function getParentLineNumber(): ?int - { - return $this->parentLineNumber; - } + /** + * @Ser\XmlAttribute + * @Ser\SerializedName("lineNumber") + */ + private int $lineNumber; + + /** + * @Ser\XmlAttribute + * @Ser\SerializedName("quantity") + */ + private int $quantity; + + /** + * @Ser\XmlAttribute + * @Ser\SerializedName("requestedDeliveryDate") + */ + private ?\DateTimeInterface $requestedDeliveryDate = null; + + /** + * @Ser\XmlAttribute + * @Ser\SerializedName("parentLineNumber") + */ + private ?int $parentLineNumber = null; + + /** + * @Ser\SerializedName("ItemID") + */ + private ItemId $itemId; + + /** + * @Ser\SerializedName("ItemDetail") + */ + private ItemDetail $itemDetail; + + private function __construct( + int $lineNumber, + int $quantity, + ItemId $itemId, + ItemDetail $itemDetail, + \DateTimeInterface $requestedDeliveryDate = null, + int $parentLineNumber = null + ) { + $this->lineNumber = $lineNumber; + $this->quantity = $quantity; + $this->itemId = $itemId; + $this->itemDetail = $itemDetail; + $this->requestedDeliveryDate = $requestedDeliveryDate; + $this->parentLineNumber = $parentLineNumber; + } + + public static function create( + int $lineNumber, + int $quantity, + ItemId $itemId, + ItemDetail $itemDetail, + \DateTimeInterface $requestedDeliveryDate = null, + int $parentLineNumber = null + ): self { + return new self( + $lineNumber, + $quantity, + $itemId, + $itemDetail, + $requestedDeliveryDate, + $parentLineNumber + ); + } + + public function addClassification(string $domain, string $value): self + { + $classification = new Classification($domain, $value); + $this->itemDetail->addClassification($classification); + + return $this; + } + + public function getLineNumber(): int + { + return $this->lineNumber; + } + + public function getQuantity(): int + { + return $this->quantity; + } + + public function getRequestedDeliveryDate(): ?\DateTimeInterface + { + return $this->requestedDeliveryDate; + } + + public function getItemId(): ItemId + { + return $this->itemId; + } + + public function getItemDetail(): ItemDetail + { + return $this->itemDetail; + } + + public function getParentLineNumber(): ?int + { + return $this->parentLineNumber; + } } diff --git a/src/CXml/Model/Message/Message.php b/src/CXml/Model/Message/Message.php index 3fc7583..3b071cf 100644 --- a/src/CXml/Model/Message/Message.php +++ b/src/CXml/Model/Message/Message.php @@ -7,71 +7,71 @@ class Message { - /** - * @Ser\SerializedName("Status") - */ - private ?Status $status = null; + /** + * @Ser\SerializedName("Status") + */ + private ?Status $status = null; - /** - * @Ser\XmlAttribute - * @Ser\SerializedName("deploymentMode") - */ - private ?string $deploymentMode = null; + /** + * @Ser\XmlAttribute + * @Ser\SerializedName("deploymentMode") + */ + private ?string $deploymentMode = null; - /** - * @Ser\XmlAttribute - * @Ser\SerializedName("inReplyTo") - */ - private ?string $inReplyTo = null; + /** + * @Ser\XmlAttribute + * @Ser\SerializedName("inReplyTo") + */ + private ?string $inReplyTo = null; - /** - * @Ser\XmlAttribute - * @Ser\SerializedName("Id") - */ - private ?string $id = null; + /** + * @Ser\XmlAttribute + * @Ser\SerializedName("Id") + */ + private ?string $id = null; - /** - * @Ser\Exclude - * see CXmlWrappingNodeJmsEventSubscriber - */ - private MessagePayloadInterface $payload; + /** + * @Ser\Exclude + * see CXmlWrappingNodeJmsEventSubscriber + */ + private MessagePayloadInterface $payload; - public function __construct( - MessagePayloadInterface $message, - Status $status = null, - string $id = null, - string $deploymentMode = null, - string $inReplyTo = null - ) { - $this->status = $status; - $this->payload = $message; - $this->deploymentMode = $deploymentMode; - $this->inReplyTo = $inReplyTo; - $this->id = $id; - } + public function __construct( + MessagePayloadInterface $message, + Status $status = null, + string $id = null, + string $deploymentMode = null, + string $inReplyTo = null + ) { + $this->status = $status; + $this->payload = $message; + $this->deploymentMode = $deploymentMode; + $this->inReplyTo = $inReplyTo; + $this->id = $id; + } - public function getStatus(): ?Status - { - return $this->status; - } + public function getStatus(): ?Status + { + return $this->status; + } - public function getDeploymentMode(): ?string - { - return $this->deploymentMode; - } + public function getDeploymentMode(): ?string + { + return $this->deploymentMode; + } - public function getInReplyTo(): ?string - { - return $this->inReplyTo; - } + public function getInReplyTo(): ?string + { + return $this->inReplyTo; + } - public function getId(): ?string - { - return $this->id; - } + public function getId(): ?string + { + return $this->id; + } - public function getPayload(): MessagePayloadInterface - { - return $this->payload; - } + public function getPayload(): MessagePayloadInterface + { + return $this->payload; + } } diff --git a/src/CXml/Model/Message/ProductActivityDetail.php b/src/CXml/Model/Message/ProductActivityDetail.php index 4dce20d..5b22b2c 100644 --- a/src/CXml/Model/Message/ProductActivityDetail.php +++ b/src/CXml/Model/Message/ProductActivityDetail.php @@ -11,60 +11,60 @@ class ProductActivityDetail { - use ExtrinsicsTrait; + use ExtrinsicsTrait; - /** - * @Ser\SerializedName("ItemID") - */ - private ItemId $itemId; + /** + * @Ser\SerializedName("ItemID") + */ + private ItemId $itemId; - /** - * @Ser\SerializedName("Description") - * @Ser\XmlElement (cdata=false) - */ - private ?MultilanguageString $description = null; + /** + * @Ser\SerializedName("Description") + * @Ser\XmlElement (cdata=false) + */ + private ?MultilanguageString $description = null; - /** - * @Ser\SerializedName("Contact") - * todo: more contact should be allowed - */ - private ?Contact $contact = null; + /** + * @Ser\SerializedName("Contact") + * todo: more contact should be allowed + */ + private ?Contact $contact = null; - /** - * @Ser\SerializedName("Inventory") - */ - private ?Inventory $inventory = null; + /** + * @Ser\SerializedName("Inventory") + */ + private ?Inventory $inventory = null; - private function __construct(ItemId $itemId, Inventory $inventory = null, Contact $contact = null, MultilanguageString $description = null) - { - $this->contact = $contact; - $this->description = $description; - $this->itemId = $itemId; - $this->inventory = $inventory; - } + private function __construct(ItemId $itemId, Inventory $inventory = null, Contact $contact = null, MultilanguageString $description = null) + { + $this->contact = $contact; + $this->description = $description; + $this->itemId = $itemId; + $this->inventory = $inventory; + } - public static function create(ItemId $itemId, Inventory $inventory = null, Contact $contact = null, MultilanguageString $description = null): self - { - return new self($itemId, $inventory, $contact, $description); - } + public static function create(ItemId $itemId, Inventory $inventory = null, Contact $contact = null, MultilanguageString $description = null): self + { + return new self($itemId, $inventory, $contact, $description); + } - public function getItemId(): ItemId - { - return $this->itemId; - } + public function getItemId(): ItemId + { + return $this->itemId; + } - public function getDescription(): ?MultilanguageString - { - return $this->description; - } + public function getDescription(): ?MultilanguageString + { + return $this->description; + } - public function getInventory(): ?Inventory - { - return $this->inventory; - } + public function getInventory(): ?Inventory + { + return $this->inventory; + } - public function getContact(): ?Contact - { - return $this->contact; - } + public function getContact(): ?Contact + { + return $this->contact; + } } diff --git a/src/CXml/Model/Message/ProductActivityHeader.php b/src/CXml/Model/Message/ProductActivityHeader.php index 03919c3..487a601 100644 --- a/src/CXml/Model/Message/ProductActivityHeader.php +++ b/src/CXml/Model/Message/ProductActivityHeader.php @@ -6,44 +6,44 @@ class ProductActivityHeader { - public const PROCESSTYPE_SUPPLIER_MANAGED_INVENTORY = 'SMI'; - public const PROCESSTYPE_THIRD_PARTY_LOGISTICS = '3PL'; - - /** - * @Ser\SerializedName("messageID") - * @Ser\XmlAttribute - */ - private string $messageId; - - /** - * @Ser\XmlAttribute - */ - private ?string $processType = null; - - /** - * @Ser\XmlAttribute - */ - private ?\DateTimeInterface $creationDate = null; - - public function __construct(string $messageId, string $processType = null, \DateTimeInterface $creationDate = null) - { - $this->messageId = $messageId; - $this->processType = $processType; - $this->creationDate = $creationDate; - } - - public function getMessageId(): string - { - return $this->messageId; - } - - public function getProcessType(): ?string - { - return $this->processType; - } - - public function getCreationDate(): ?\DateTimeInterface - { - return $this->creationDate; - } + public const PROCESSTYPE_SUPPLIER_MANAGED_INVENTORY = 'SMI'; + public const PROCESSTYPE_THIRD_PARTY_LOGISTICS = '3PL'; + + /** + * @Ser\SerializedName("messageID") + * @Ser\XmlAttribute + */ + private string $messageId; + + /** + * @Ser\XmlAttribute + */ + private ?string $processType = null; + + /** + * @Ser\XmlAttribute + */ + private ?\DateTimeInterface $creationDate = null; + + public function __construct(string $messageId, string $processType = null, \DateTimeInterface $creationDate = null) + { + $this->messageId = $messageId; + $this->processType = $processType; + $this->creationDate = $creationDate; + } + + public function getMessageId(): string + { + return $this->messageId; + } + + public function getProcessType(): ?string + { + return $this->processType; + } + + public function getCreationDate(): ?\DateTimeInterface + { + return $this->creationDate; + } } diff --git a/src/CXml/Model/Message/ProductActivityMessage.php b/src/CXml/Model/Message/ProductActivityMessage.php index 501a2e8..85967c2 100644 --- a/src/CXml/Model/Message/ProductActivityMessage.php +++ b/src/CXml/Model/Message/ProductActivityMessage.php @@ -7,45 +7,45 @@ class ProductActivityMessage implements MessagePayloadInterface { - use ExtrinsicsTrait; - - /** - * @Ser\SerializedName("ProductActivityHeader") - */ - private ProductActivityHeader $productActivityHeader; - - /** - * @Ser\XmlList(inline=true, entry="ProductActivityDetails") - * @Ser\Type("array") - * - * @var ProductActivityDetail[] - */ - private array $productActivityDetails = []; - - private function __construct(string $messageId, string $processType = null, \DateTimeInterface $creationDate = null) - { - $this->productActivityHeader = new ProductActivityHeader($messageId, $processType, $creationDate); - } - - public static function create(string $messageId, string $processType = null, \DateTimeInterface $creationDate = null): self - { - return new self($messageId, $processType, $creationDate); - } - - public function addProductActivityDetail(ProductActivityDetail $productActivityDetail): self - { - $this->productActivityDetails[] = $productActivityDetail; - - return $this; - } - - public function getProductActivityHeader(): ProductActivityHeader - { - return $this->productActivityHeader; - } - - public function getProductActivityDetails(): array - { - return $this->productActivityDetails; - } + use ExtrinsicsTrait; + + /** + * @Ser\SerializedName("ProductActivityHeader") + */ + private ProductActivityHeader $productActivityHeader; + + /** + * @Ser\XmlList(inline=true, entry="ProductActivityDetails") + * @Ser\Type("array") + * + * @var ProductActivityDetail[] + */ + private array $productActivityDetails = []; + + private function __construct(string $messageId, string $processType = null, \DateTimeInterface $creationDate = null) + { + $this->productActivityHeader = new ProductActivityHeader($messageId, $processType, $creationDate); + } + + public static function create(string $messageId, string $processType = null, \DateTimeInterface $creationDate = null): self + { + return new self($messageId, $processType, $creationDate); + } + + public function addProductActivityDetail(ProductActivityDetail $productActivityDetail): self + { + $this->productActivityDetails[] = $productActivityDetail; + + return $this; + } + + public function getProductActivityHeader(): ProductActivityHeader + { + return $this->productActivityHeader; + } + + public function getProductActivityDetails(): array + { + return $this->productActivityDetails; + } } diff --git a/src/CXml/Model/Message/PunchOutOrderMessage.php b/src/CXml/Model/Message/PunchOutOrderMessage.php index 95c1f7a..96fd6dc 100644 --- a/src/CXml/Model/Message/PunchOutOrderMessage.php +++ b/src/CXml/Model/Message/PunchOutOrderMessage.php @@ -7,55 +7,55 @@ class PunchOutOrderMessage implements MessagePayloadInterface { - /** - * @Ser\SerializedName("BuyerCookie") - * @Ser\XmlElement (cdata=false) - */ - private string $buyerCookie; - - /** - * @Ser\SerializedName("PunchOutOrderMessageHeader") - */ - private PunchOutOrderMessageHeader $punchOutOrderMessageHeader; - - /** - * @Ser\XmlList(inline=true, entry="ItemIn") - * @Ser\Type("array") - * - * @var ItemIn[] - */ - private array $punchoutOrderMessageItems = []; - - private function __construct(string $buyerCookie, PunchOutOrderMessageHeader $punchOutOrderMessageHeader) - { - $this->buyerCookie = $buyerCookie; - $this->punchOutOrderMessageHeader = $punchOutOrderMessageHeader; - } - - public static function create(string $buyerCookie, PunchOutOrderMessageHeader $punchOutOrderMessageHeader): self - { - return new self($buyerCookie, $punchOutOrderMessageHeader); - } - - public function getBuyerCookie(): string - { - return $this->buyerCookie; - } - - public function getPunchOutOrderMessageHeader(): PunchOutOrderMessageHeader - { - return $this->punchOutOrderMessageHeader; - } - - public function getPunchoutOrderMessageItems(): array - { - return $this->punchoutOrderMessageItems; - } - - public function addPunchoutOrderMessageItem(ItemIn $punchoutOrderMessageItem): self - { - $this->punchoutOrderMessageItems[] = $punchoutOrderMessageItem; - - return $this; - } + /** + * @Ser\SerializedName("BuyerCookie") + * @Ser\XmlElement (cdata=false) + */ + private string $buyerCookie; + + /** + * @Ser\SerializedName("PunchOutOrderMessageHeader") + */ + private PunchOutOrderMessageHeader $punchOutOrderMessageHeader; + + /** + * @Ser\XmlList(inline=true, entry="ItemIn") + * @Ser\Type("array") + * + * @var ItemIn[] + */ + private array $punchoutOrderMessageItems = []; + + private function __construct(string $buyerCookie, PunchOutOrderMessageHeader $punchOutOrderMessageHeader) + { + $this->buyerCookie = $buyerCookie; + $this->punchOutOrderMessageHeader = $punchOutOrderMessageHeader; + } + + public static function create(string $buyerCookie, PunchOutOrderMessageHeader $punchOutOrderMessageHeader): self + { + return new self($buyerCookie, $punchOutOrderMessageHeader); + } + + public function getBuyerCookie(): string + { + return $this->buyerCookie; + } + + public function getPunchOutOrderMessageHeader(): PunchOutOrderMessageHeader + { + return $this->punchOutOrderMessageHeader; + } + + public function getPunchoutOrderMessageItems(): array + { + return $this->punchoutOrderMessageItems; + } + + public function addPunchoutOrderMessageItem(ItemIn $punchoutOrderMessageItem): self + { + $this->punchoutOrderMessageItems[] = $punchoutOrderMessageItem; + + return $this; + } } diff --git a/src/CXml/Model/Message/PunchOutOrderMessageHeader.php b/src/CXml/Model/Message/PunchOutOrderMessageHeader.php index acaba11..3b43870 100644 --- a/src/CXml/Model/Message/PunchOutOrderMessageHeader.php +++ b/src/CXml/Model/Message/PunchOutOrderMessageHeader.php @@ -12,91 +12,91 @@ class PunchOutOrderMessageHeader { - public const OPERATION_CREATE = 'create'; - public const OPERATION_EDIT = 'edit'; - public const OPERATION_INSPECT = 'inspect'; - - /** - * @Ser\XmlAttribute - */ - private ?string $operationAllowed = null; - - /** - * @Ser\SerializedName("Total") - */ - private MoneyWrapper $total; - - /** - * @Ser\SerializedName("ShipTo") - */ - private ?ShipTo $shipTo = null; - - /** - * @Ser\SerializedName("Shipping") - */ - private ?Shipping $shipping = null; - - /** - * @Ser\SerializedName("Tax") - */ - private ?Tax $tax = null; - - /** - * @Ser\SerializedName("SupplierOrderInfo") - */ - private ?SupplierOrderInfo $supplierOrderInfo = null; - - public function __construct(MoneyWrapper $total, Shipping $shipping = null, Tax $tax = null, string $operationAllowed = null) - { - Assertion::inArray($operationAllowed, [self::OPERATION_CREATE, self::OPERATION_EDIT, self::OPERATION_INSPECT, null]); - - $this->total = $total; - $this->shipping = $shipping; - $this->tax = $tax; - $this->operationAllowed = $operationAllowed ?? self::OPERATION_CREATE; - } - - public function setShipTo(?ShipTo $shipTo): self - { - $this->shipTo = $shipTo; - - return $this; - } - - public function getShipTo(): ?ShipTo - { - return $this->shipTo; - } - - public function setSupplierOrderInfo(string $orderId, \DateTimeInterface $orderDate = null): self - { - $this->supplierOrderInfo = new SupplierOrderInfo($orderId, $orderDate); - - return $this; - } - - public function getOperationAllowed(): ?string - { - return $this->operationAllowed; - } - - public function getTotal(): MoneyWrapper - { - return $this->total; - } - - public function getShipping(): ?Shipping - { - return $this->shipping; - } - - public function getTax(): ?Tax - { - return $this->tax; - } - - public function getSupplierOrderInfo(): ?SupplierOrderInfo - { - return $this->supplierOrderInfo; - } + public const OPERATION_CREATE = 'create'; + public const OPERATION_EDIT = 'edit'; + public const OPERATION_INSPECT = 'inspect'; + + /** + * @Ser\XmlAttribute + */ + private ?string $operationAllowed = null; + + /** + * @Ser\SerializedName("Total") + */ + private MoneyWrapper $total; + + /** + * @Ser\SerializedName("ShipTo") + */ + private ?ShipTo $shipTo = null; + + /** + * @Ser\SerializedName("Shipping") + */ + private ?Shipping $shipping = null; + + /** + * @Ser\SerializedName("Tax") + */ + private ?Tax $tax = null; + + /** + * @Ser\SerializedName("SupplierOrderInfo") + */ + private ?SupplierOrderInfo $supplierOrderInfo = null; + + public function __construct(MoneyWrapper $total, Shipping $shipping = null, Tax $tax = null, string $operationAllowed = null) + { + Assertion::inArray($operationAllowed, [self::OPERATION_CREATE, self::OPERATION_EDIT, self::OPERATION_INSPECT, null]); + + $this->total = $total; + $this->shipping = $shipping; + $this->tax = $tax; + $this->operationAllowed = $operationAllowed ?? self::OPERATION_CREATE; + } + + public function setShipTo(?ShipTo $shipTo): self + { + $this->shipTo = $shipTo; + + return $this; + } + + public function getShipTo(): ?ShipTo + { + return $this->shipTo; + } + + public function setSupplierOrderInfo(string $orderId, \DateTimeInterface $orderDate = null): self + { + $this->supplierOrderInfo = new SupplierOrderInfo($orderId, $orderDate); + + return $this; + } + + public function getOperationAllowed(): ?string + { + return $this->operationAllowed; + } + + public function getTotal(): MoneyWrapper + { + return $this->total; + } + + public function getShipping(): ?Shipping + { + return $this->shipping; + } + + public function getTax(): ?Tax + { + return $this->tax; + } + + public function getSupplierOrderInfo(): ?SupplierOrderInfo + { + return $this->supplierOrderInfo; + } } diff --git a/src/CXml/Model/Money.php b/src/CXml/Model/Money.php index 6d2a7b0..ea49fc6 100644 --- a/src/CXml/Model/Money.php +++ b/src/CXml/Model/Money.php @@ -6,40 +6,40 @@ class Money { - /** - * @Ser\XmlAttribute - */ - private string $currency; - - /** - * @Ser\XmlValue(cdata=false) - */ - private string $value; - - /** - * @Ser\Exclude() - */ - private int $valueCent; - - public function __construct(string $currency, int $valueCent) - { - $this->currency = $currency; - $this->valueCent = $valueCent; - $this->value = \number_format($valueCent / 100, 2, '.', ''); - } - - public function getCurrency(): string - { - return $this->currency; - } - - public function getValue(): string - { - return $this->value; - } - - public function getValueCent(): int - { - return $this->valueCent ?? (int) (((float) $this->value) * 100); - } + /** + * @Ser\XmlAttribute + */ + private string $currency; + + /** + * @Ser\XmlValue(cdata=false) + */ + private string $value; + + /** + * @Ser\Exclude() + */ + private int $valueCent; + + public function __construct(string $currency, int $valueCent) + { + $this->currency = $currency; + $this->valueCent = $valueCent; + $this->value = \number_format($valueCent / 100, 2, '.', ''); + } + + public function getCurrency(): string + { + return $this->currency; + } + + public function getValue(): string + { + return $this->value; + } + + public function getValueCent(): int + { + return $this->valueCent ?? (int) (((float) $this->value) * 100); + } } diff --git a/src/CXml/Model/MoneyWrapper.php b/src/CXml/Model/MoneyWrapper.php index 0f91a37..1e5dc7d 100644 --- a/src/CXml/Model/MoneyWrapper.php +++ b/src/CXml/Model/MoneyWrapper.php @@ -6,18 +6,18 @@ class MoneyWrapper { - /** - * @Ser\SerializedName("Money") - */ - private Money $money; + /** + * @Ser\SerializedName("Money") + */ + private Money $money; - public function __construct(string $currency, int $value) - { - $this->money = new Money($currency, $value); - } + public function __construct(string $currency, int $value) + { + $this->money = new Money($currency, $value); + } - public function getMoney(): Money - { - return $this->money; - } + public function getMoney(): Money + { + return $this->money; + } } diff --git a/src/CXml/Model/MultilanguageString.php b/src/CXml/Model/MultilanguageString.php index 72f471e..45a1033 100644 --- a/src/CXml/Model/MultilanguageString.php +++ b/src/CXml/Model/MultilanguageString.php @@ -6,40 +6,40 @@ class MultilanguageString { - /** - * @Ser\XmlValue(cdata=false) - */ - private ?string $value = null; - - /** - * @Ser\XmlAttribute - */ - private ?string $type = null; - - /** - * @Ser\XmlAttribute(namespace="http://www.w3.org/XML/1998/namespace") - */ - private ?string $lang = null; - - public function __construct(?string $value, string $type = null, string $lang = 'en') - { - $this->value = $value; - $this->lang = $lang; - $this->type = $type; - } - - public function getValue(): ?string - { - return $this->value; - } - - public function getType(): ?string - { - return $this->type; - } - - public function getLang(): ?string - { - return $this->lang; - } + /** + * @Ser\XmlValue(cdata=false) + */ + private ?string $value = null; + + /** + * @Ser\XmlAttribute + */ + private ?string $type = null; + + /** + * @Ser\XmlAttribute(namespace="http://www.w3.org/XML/1998/namespace") + */ + private ?string $lang = null; + + public function __construct(?string $value, string $type = null, string $lang = 'en') + { + $this->value = $value; + $this->lang = $lang; + $this->type = $type; + } + + public function getValue(): ?string + { + return $this->value; + } + + public function getType(): ?string + { + return $this->type; + } + + public function getLang(): ?string + { + return $this->lang; + } } diff --git a/src/CXml/Model/Option.php b/src/CXml/Model/Option.php index a02e28b..4d8977a 100644 --- a/src/CXml/Model/Option.php +++ b/src/CXml/Model/Option.php @@ -6,19 +6,19 @@ class Option { - /** - * @Ser\XmlAttribute - */ - private string $name; + /** + * @Ser\XmlAttribute + */ + private string $name; - /** - * @Ser\XmlValue(cdata=false) - */ - private string $value; + /** + * @Ser\XmlValue(cdata=false) + */ + private string $value; - public function __construct(string $name, string $value) - { - $this->name = $name; - $this->value = $value; - } + public function __construct(string $name, string $value) + { + $this->name = $name; + $this->value = $value; + } } diff --git a/src/CXml/Model/OrderReference.php b/src/CXml/Model/OrderReference.php index b57ab94..71be241 100644 --- a/src/CXml/Model/OrderReference.php +++ b/src/CXml/Model/OrderReference.php @@ -6,48 +6,48 @@ class OrderReference { - /** - * @Ser\SerializedName("DocumentReference") - */ - private ?DocumentReference $documentReference = null; - - /** - * @Ser\SerializedName("orderID") - * @Ser\XmlAttribute - */ - private ?string $orderId = null; - - /** - * @Ser\XmlAttribute - */ - private ?\DateTimeInterface $orderDate = null; - - public function __construct(DocumentReference $documentReference, string $orderId = null, \DateTimeInterface $orderDate = null) - { - $this->documentReference = $documentReference; - $this->orderId = $orderId; - $this->orderDate = $orderDate; - } - - public static function create(string $documentReference): self - { - return new self( - new DocumentReference($documentReference) - ); - } - - public function getDocumentReference(): ?DocumentReference - { - return $this->documentReference; - } - - public function getOrderId(): ?string - { - return $this->orderId; - } - - public function getOrderDate(): ?\DateTimeInterface - { - return $this->orderDate; - } + /** + * @Ser\SerializedName("DocumentReference") + */ + private ?DocumentReference $documentReference = null; + + /** + * @Ser\SerializedName("orderID") + * @Ser\XmlAttribute + */ + private ?string $orderId = null; + + /** + * @Ser\XmlAttribute + */ + private ?\DateTimeInterface $orderDate = null; + + public function __construct(DocumentReference $documentReference, string $orderId = null, \DateTimeInterface $orderDate = null) + { + $this->documentReference = $documentReference; + $this->orderId = $orderId; + $this->orderDate = $orderDate; + } + + public static function create(string $documentReference): self + { + return new self( + new DocumentReference($documentReference) + ); + } + + public function getDocumentReference(): ?DocumentReference + { + return $this->documentReference; + } + + public function getOrderId(): ?string + { + return $this->orderId; + } + + public function getOrderDate(): ?\DateTimeInterface + { + return $this->orderDate; + } } diff --git a/src/CXml/Model/Party.php b/src/CXml/Model/Party.php index 8eee89d..c37c997 100644 --- a/src/CXml/Model/Party.php +++ b/src/CXml/Model/Party.php @@ -6,30 +6,30 @@ class Party { - /** - * @Ser\SerializedName("Credential") - */ - private Credential $credential; + /** + * @Ser\SerializedName("Credential") + */ + private Credential $credential; - /** - * @Ser\SerializedName("UserAgent") - * @Ser\XmlElement (cdata=false) - */ - private ?string $userAgent = null; + /** + * @Ser\SerializedName("UserAgent") + * @Ser\XmlElement (cdata=false) + */ + private ?string $userAgent = null; - public function __construct(Credential $credential, string $userAgent = null) - { - $this->credential = $credential; - $this->userAgent = $userAgent; - } + public function __construct(Credential $credential, string $userAgent = null) + { + $this->credential = $credential; + $this->userAgent = $userAgent; + } - public function getCredential(): Credential - { - return $this->credential; - } + public function getCredential(): Credential + { + return $this->credential; + } - public function getUserAgent(): ?string - { - return $this->userAgent; - } + public function getUserAgent(): ?string + { + return $this->userAgent; + } } diff --git a/src/CXml/Model/PayloadIdentity.php b/src/CXml/Model/PayloadIdentity.php index 6ef1266..b1a7c74 100644 --- a/src/CXml/Model/PayloadIdentity.php +++ b/src/CXml/Model/PayloadIdentity.php @@ -4,22 +4,22 @@ class PayloadIdentity { - private string $payloadId; - private \DateTimeInterface $timestamp; + private string $payloadId; + private \DateTimeInterface $timestamp; - public function __construct(string $payloadId, \DateTimeInterface $timestamp = null) - { - $this->payloadId = $payloadId; - $this->timestamp = $timestamp ?? new \DateTime(); - } + public function __construct(string $payloadId, \DateTimeInterface $timestamp = null) + { + $this->payloadId = $payloadId; + $this->timestamp = $timestamp ?? new \DateTime(); + } - public function getPayloadId(): string - { - return $this->payloadId; - } + public function getPayloadId(): string + { + return $this->payloadId; + } - public function getTimestamp(): \DateTimeInterface - { - return $this->timestamp; - } + public function getTimestamp(): \DateTimeInterface + { + return $this->timestamp; + } } diff --git a/src/CXml/Model/PostalAddress.php b/src/CXml/Model/PostalAddress.php index bc1688f..615051c 100644 --- a/src/CXml/Model/PostalAddress.php +++ b/src/CXml/Model/PostalAddress.php @@ -6,122 +6,122 @@ class PostalAddress { - use ExtrinsicsTrait; - - /** - * @Ser\XmlAttribute - * @Ser\SerializedName("name") - */ - private ?string $name = null; - - /** - * @Ser\XmlList(inline=true, entry="DeliverTo") - * @Ser\Type("array") - * @Ser\XmlElement(cdata=false) - */ - private array $deliverTo; - - /** - * @Ser\XmlList(inline=true, entry="Street") - * @Ser\Type("array") - * @Ser\XmlElement(cdata=false) - */ - private array $street; - - /** - * @Ser\SerializedName("City") - * @Ser\XmlElement (cdata=false) - */ - private string $city; - - /** - * @Ser\SerializedName("Municipality") - * @Ser\XmlElement (cdata=false) - */ - private ?string $municipality = null; - - /** - * @Ser\SerializedName("State") - * @Ser\XmlElement (cdata=false) - */ - private ?string $state = null; - - /** - * @Ser\SerializedName("PostalCode") - * @Ser\XmlElement (cdata=false) - */ - private ?string $postalCode = null; - - /** - * @Ser\SerializedName("Country") - * @Ser\XmlElement (cdata=false) - */ - private Country $country; - - public function __construct(array $deliverTo, array $street, string $city, Country $country, string $municipality = null, string $state = null, string $postalCode = null, string $name = null) - { - $this->name = $name; - $this->deliverTo = $deliverTo; - $this->street = $street; - $this->city = $city; - $this->municipality = $municipality; - $this->state = $state; - $this->postalCode = $postalCode; - $this->country = $country; - } - - public function getName(): ?string - { - return $this->name; - } - - public function getDeliverTo(): array - { - return $this->deliverTo; - } - - public function getStreet(): array - { - return $this->street; - } - - public function getCity(): string - { - return $this->city; - } - - public function getMunicipality(): ?string - { - return $this->municipality; - } - - public function getState(): ?string - { - return $this->state; - } - - public function getPostalCode(): ?string - { - return $this->postalCode; - } - - public function getCountry(): Country - { - return $this->country; - } - - /** - * Convenience method to detect empty-string filled addresses. - */ - public function isEmpty(): bool - { - return - empty($this->name) - && empty(\array_filter($this->deliverTo)) - && empty(\array_filter($this->street)) - && empty($this->city) - && empty($this->municipality) - && empty($this->state) - && empty($this->postalCode); - } + use ExtrinsicsTrait; + + /** + * @Ser\XmlAttribute + * @Ser\SerializedName("name") + */ + private ?string $name = null; + + /** + * @Ser\XmlList(inline=true, entry="DeliverTo") + * @Ser\Type("array") + * @Ser\XmlElement(cdata=false) + */ + private array $deliverTo; + + /** + * @Ser\XmlList(inline=true, entry="Street") + * @Ser\Type("array") + * @Ser\XmlElement(cdata=false) + */ + private array $street; + + /** + * @Ser\SerializedName("City") + * @Ser\XmlElement (cdata=false) + */ + private string $city; + + /** + * @Ser\SerializedName("Municipality") + * @Ser\XmlElement (cdata=false) + */ + private ?string $municipality = null; + + /** + * @Ser\SerializedName("State") + * @Ser\XmlElement (cdata=false) + */ + private ?string $state = null; + + /** + * @Ser\SerializedName("PostalCode") + * @Ser\XmlElement (cdata=false) + */ + private ?string $postalCode = null; + + /** + * @Ser\SerializedName("Country") + * @Ser\XmlElement (cdata=false) + */ + private Country $country; + + public function __construct(array $deliverTo, array $street, string $city, Country $country, string $municipality = null, string $state = null, string $postalCode = null, string $name = null) + { + $this->name = $name; + $this->deliverTo = $deliverTo; + $this->street = $street; + $this->city = $city; + $this->municipality = $municipality; + $this->state = $state; + $this->postalCode = $postalCode; + $this->country = $country; + } + + public function getName(): ?string + { + return $this->name; + } + + public function getDeliverTo(): array + { + return $this->deliverTo; + } + + public function getStreet(): array + { + return $this->street; + } + + public function getCity(): string + { + return $this->city; + } + + public function getMunicipality(): ?string + { + return $this->municipality; + } + + public function getState(): ?string + { + return $this->state; + } + + public function getPostalCode(): ?string + { + return $this->postalCode; + } + + public function getCountry(): Country + { + return $this->country; + } + + /** + * Convenience method to detect empty-string filled addresses. + */ + public function isEmpty(): bool + { + return + empty($this->name) + && empty(\array_filter($this->deliverTo)) + && empty(\array_filter($this->street)) + && empty($this->city) + && empty($this->municipality) + && empty($this->state) + && empty($this->postalCode); + } } diff --git a/src/CXml/Model/Request/ConfirmationHeader.php b/src/CXml/Model/Request/ConfirmationHeader.php index 24c43e8..1402697 100644 --- a/src/CXml/Model/Request/ConfirmationHeader.php +++ b/src/CXml/Model/Request/ConfirmationHeader.php @@ -9,60 +9,60 @@ class ConfirmationHeader { - use ExtrinsicsTrait; - use IdReferencesTrait; - public const TYPE_ACCEPT = 'accept'; - public const TYPE_ALLDETAIL = 'allDetail'; - public const TYPE_DETAIL = 'detail'; - public const TYPE_BACKORDERED = 'backordered'; - public const TYPE_EXCEPT = 'except'; - public const TYPE_REJECT = 'reject'; - public const TYPE_REQUESTTOPAY = 'requestToPay'; - public const TYPE_REPLACE = 'replace'; + use ExtrinsicsTrait; + use IdReferencesTrait; + public const TYPE_ACCEPT = 'accept'; + public const TYPE_ALLDETAIL = 'allDetail'; + public const TYPE_DETAIL = 'detail'; + public const TYPE_BACKORDERED = 'backordered'; + public const TYPE_EXCEPT = 'except'; + public const TYPE_REJECT = 'reject'; + public const TYPE_REQUESTTOPAY = 'requestToPay'; + public const TYPE_REPLACE = 'replace'; - /** - * @Ser\XmlAttribute - * @Ser\SerializedName("type") - */ - private string $type; + /** + * @Ser\XmlAttribute + * @Ser\SerializedName("type") + */ + private string $type; - /** - * @Ser\XmlAttribute - */ - private \DateTimeInterface $noticeDate; + /** + * @Ser\XmlAttribute + */ + private \DateTimeInterface $noticeDate; - public function __construct(string $type, \DateTimeInterface $noticeDate = null) - { - Assertion::inArray($type, [ - self::TYPE_ACCEPT, - self::TYPE_ALLDETAIL, - self::TYPE_DETAIL, - self::TYPE_BACKORDERED, - self::TYPE_EXCEPT, - self::TYPE_REJECT, - self::TYPE_REQUESTTOPAY, - self::TYPE_REPLACE, - ]); + public function __construct(string $type, \DateTimeInterface $noticeDate = null) + { + Assertion::inArray($type, [ + self::TYPE_ACCEPT, + self::TYPE_ALLDETAIL, + self::TYPE_DETAIL, + self::TYPE_BACKORDERED, + self::TYPE_EXCEPT, + self::TYPE_REJECT, + self::TYPE_REQUESTTOPAY, + self::TYPE_REPLACE, + ]); - $this->type = $type; - $this->noticeDate = $noticeDate ?? new \DateTime(); - } + $this->type = $type; + $this->noticeDate = $noticeDate ?? new \DateTime(); + } - public static function create(string $type, \DateTimeInterface $noticeDate = null): self - { - return new self( - $type, - $noticeDate - ); - } + public static function create(string $type, \DateTimeInterface $noticeDate = null): self + { + return new self( + $type, + $noticeDate + ); + } - public function getType(): string - { - return $this->type; - } + public function getType(): string + { + return $this->type; + } - public function getNoticeDate(): \DateTimeInterface - { - return $this->noticeDate; - } + public function getNoticeDate(): \DateTimeInterface + { + return $this->noticeDate; + } } diff --git a/src/CXml/Model/Request/ConfirmationRequest.php b/src/CXml/Model/Request/ConfirmationRequest.php index 00e5d42..4f5606d 100644 --- a/src/CXml/Model/Request/ConfirmationRequest.php +++ b/src/CXml/Model/Request/ConfirmationRequest.php @@ -7,34 +7,34 @@ class ConfirmationRequest implements RequestPayloadInterface { - /** - * @Ser\SerializedName("ConfirmationHeader") - */ - private ConfirmationHeader $confirmationHeader; - - /** - * @Ser\SerializedName("OrderReference") - */ - private OrderReference $orderReference; - - public function __construct(ConfirmationHeader $confirmationHeader, OrderReference $orderReference) - { - $this->confirmationHeader = $confirmationHeader; - $this->orderReference = $orderReference; - } - - public static function create(ConfirmationHeader $confirmationHeader, OrderReference $orderReference): self - { - return new self($confirmationHeader, $orderReference); - } - - public function getConfirmationHeader(): ConfirmationHeader - { - return $this->confirmationHeader; - } - - public function getOrderReference(): OrderReference - { - return $this->orderReference; - } + /** + * @Ser\SerializedName("ConfirmationHeader") + */ + private ConfirmationHeader $confirmationHeader; + + /** + * @Ser\SerializedName("OrderReference") + */ + private OrderReference $orderReference; + + public function __construct(ConfirmationHeader $confirmationHeader, OrderReference $orderReference) + { + $this->confirmationHeader = $confirmationHeader; + $this->orderReference = $orderReference; + } + + public static function create(ConfirmationHeader $confirmationHeader, OrderReference $orderReference): self + { + return new self($confirmationHeader, $orderReference); + } + + public function getConfirmationHeader(): ConfirmationHeader + { + return $this->confirmationHeader; + } + + public function getOrderReference(): OrderReference + { + return $this->orderReference; + } } diff --git a/src/CXml/Model/Request/OrderRequest.php b/src/CXml/Model/Request/OrderRequest.php index 1c88098..f0dad1b 100644 --- a/src/CXml/Model/Request/OrderRequest.php +++ b/src/CXml/Model/Request/OrderRequest.php @@ -7,54 +7,54 @@ class OrderRequest implements RequestPayloadInterface { - /** - * @Ser\SerializedName("OrderRequestHeader") - */ - private OrderRequestHeader $orderRequestHeader; - - /** - * @Ser\XmlList(inline=true, entry="ItemOut") - * @Ser\Type("array") - * - * @var ItemOut[] - */ - private array $itemOut = []; - - protected function __construct(OrderRequestHeader $orderRequestHeader) - { - $this->orderRequestHeader = $orderRequestHeader; - } - - public static function create(OrderRequestHeader $orderRequestHeader): self - { - return new self( - $orderRequestHeader - ); - } - - public function addItems(array $items): self - { - foreach ($items as $item) { - $this->addItem($item); - } - - return $this; - } - - public function addItem(ItemOut $item): self - { - $this->itemOut[] = $item; - - return $this; - } - - public function getOrderRequestHeader(): OrderRequestHeader - { - return $this->orderRequestHeader; - } - - public function getItems(): array - { - return $this->itemOut; - } + /** + * @Ser\SerializedName("OrderRequestHeader") + */ + private OrderRequestHeader $orderRequestHeader; + + /** + * @Ser\XmlList(inline=true, entry="ItemOut") + * @Ser\Type("array") + * + * @var ItemOut[] + */ + private array $itemOut = []; + + protected function __construct(OrderRequestHeader $orderRequestHeader) + { + $this->orderRequestHeader = $orderRequestHeader; + } + + public static function create(OrderRequestHeader $orderRequestHeader): self + { + return new self( + $orderRequestHeader + ); + } + + public function addItems(array $items): self + { + foreach ($items as $item) { + $this->addItem($item); + } + + return $this; + } + + public function addItem(ItemOut $item): self + { + $this->itemOut[] = $item; + + return $this; + } + + public function getOrderRequestHeader(): OrderRequestHeader + { + return $this->orderRequestHeader; + } + + public function getItems(): array + { + return $this->itemOut; + } } diff --git a/src/CXml/Model/Request/OrderRequestHeader.php b/src/CXml/Model/Request/OrderRequestHeader.php index e83e9c3..ed71b53 100644 --- a/src/CXml/Model/Request/OrderRequestHeader.php +++ b/src/CXml/Model/Request/OrderRequestHeader.php @@ -17,196 +17,196 @@ class OrderRequestHeader { - use ExtrinsicsTrait; - use IdReferencesTrait; - - public const TYPE_NEW = 'new'; - - /** - * @Ser\XmlAttribute - * @Ser\SerializedName("orderID") - */ - private string $orderId; - - /** - * @Ser\XmlAttribute - * @Ser\SerializedName("orderDate") - */ - private \DateTimeInterface $orderDate; - - /** - * @Ser\XmlAttribute - */ - private string $type = self::TYPE_NEW; - - /** - * @Ser\XmlElement - * @Ser\SerializedName("Total") - */ - private MoneyWrapper $total; - - /** - * @Ser\XmlElement - * @Ser\SerializedName("ShipTo") - */ - private ?ShipTo $shipTo = null; - - /** - * @Ser\XmlElement - * @Ser\SerializedName("BillTo") - */ - private BillTo $billTo; - - /** - * @Ser\XmlElement - * @Ser\SerializedName("Shipping") - */ - private ?Shipping $shipping = null; - - /** - * @Ser\XmlElement - * @Ser\SerializedName("Tax") - */ - private ?Tax $tax = null; - - /** - * @Ser\XmlList(inline=true, entry="Contact") - * @Ser\Type("array") - * - * @var Contact[] - */ - private ?array $contacts = null; - - /** - * @Ser\XmlList(inline=true, entry="Comments") - * @Ser\Type("array") - * - * @var Comment[] - */ - private ?array $comments = null; - - /** - * @Ser\SerializedName("SupplierOrderInfo") - */ - private ?SupplierOrderInfo $supplierOrderInfo = null; - - public function __construct( - string $orderId, - \DateTimeInterface $orderDate, - ?ShipTo $shipTo, - BillTo $billTo, - MoneyWrapper $total, - array $comments = null, - string $type = self::TYPE_NEW, - array $contacts = null - ) { - if ($comments) { - Assertion::allIsInstanceOf($comments, Comment::class); - } - if ($contacts) { - Assertion::allIsInstanceOf($contacts, Contact::class); - } - - $this->orderId = $orderId; - $this->orderDate = $orderDate; - $this->type = $type; - $this->total = $total; - $this->shipTo = $shipTo; - $this->billTo = $billTo; - $this->comments = $comments; - $this->contacts = $contacts; - } - - public static function create( - string $orderId, - \DateTimeInterface $orderDate, - ?ShipTo $shipTo, - BillTo $billTo, - MoneyWrapper $total, - array $comments = null, - string $type = self::TYPE_NEW, - array $contacts = null - ): self { - return new self($orderId, $orderDate, $shipTo, $billTo, $total, $comments, $type, $contacts); - } - - public function getShipping(): ?Shipping - { - return $this->shipping; - } - - public function setShipping(?Shipping $shipping): self - { - $this->shipping = $shipping; - - return $this; - } - - public function getTax(): ?Tax - { - return $this->tax; - } - - public function setTax(?Tax $tax): self - { - $this->tax = $tax; - - return $this; - } - - public function getOrderId(): string - { - return $this->orderId; - } - - public function getOrderDate(): \DateTimeInterface - { - return $this->orderDate; - } - - public function getType(): string - { - return $this->type; - } - - public function getTotal(): MoneyWrapper - { - return $this->total; - } - - public function getShipTo(): ?ShipTo - { - return $this->shipTo; - } - - public function getBillTo(): BillTo - { - return $this->billTo; - } - - public function getComments(): ?array - { - return $this->comments; - } - - public function addContact(Contact $contact): self - { - if (null === $this->contacts) { - $this->contacts = []; - } - - $this->contacts[] = $contact; - - return $this; - } - - public function getContacts(): ?array - { - return $this->contacts; - } - - public function getSupplierOrderInfo(): ?SupplierOrderInfo - { - return $this->supplierOrderInfo; - } + use ExtrinsicsTrait; + use IdReferencesTrait; + + public const TYPE_NEW = 'new'; + + /** + * @Ser\XmlAttribute + * @Ser\SerializedName("orderID") + */ + private string $orderId; + + /** + * @Ser\XmlAttribute + * @Ser\SerializedName("orderDate") + */ + private \DateTimeInterface $orderDate; + + /** + * @Ser\XmlAttribute + */ + private string $type = self::TYPE_NEW; + + /** + * @Ser\XmlElement + * @Ser\SerializedName("Total") + */ + private MoneyWrapper $total; + + /** + * @Ser\XmlElement + * @Ser\SerializedName("ShipTo") + */ + private ?ShipTo $shipTo = null; + + /** + * @Ser\XmlElement + * @Ser\SerializedName("BillTo") + */ + private BillTo $billTo; + + /** + * @Ser\XmlElement + * @Ser\SerializedName("Shipping") + */ + private ?Shipping $shipping = null; + + /** + * @Ser\XmlElement + * @Ser\SerializedName("Tax") + */ + private ?Tax $tax = null; + + /** + * @Ser\XmlList(inline=true, entry="Contact") + * @Ser\Type("array") + * + * @var Contact[] + */ + private ?array $contacts = null; + + /** + * @Ser\XmlList(inline=true, entry="Comments") + * @Ser\Type("array") + * + * @var Comment[] + */ + private ?array $comments = null; + + /** + * @Ser\SerializedName("SupplierOrderInfo") + */ + private ?SupplierOrderInfo $supplierOrderInfo = null; + + public function __construct( + string $orderId, + \DateTimeInterface $orderDate, + ?ShipTo $shipTo, + BillTo $billTo, + MoneyWrapper $total, + array $comments = null, + string $type = self::TYPE_NEW, + array $contacts = null + ) { + if ($comments) { + Assertion::allIsInstanceOf($comments, Comment::class); + } + if ($contacts) { + Assertion::allIsInstanceOf($contacts, Contact::class); + } + + $this->orderId = $orderId; + $this->orderDate = $orderDate; + $this->type = $type; + $this->total = $total; + $this->shipTo = $shipTo; + $this->billTo = $billTo; + $this->comments = $comments; + $this->contacts = $contacts; + } + + public static function create( + string $orderId, + \DateTimeInterface $orderDate, + ?ShipTo $shipTo, + BillTo $billTo, + MoneyWrapper $total, + array $comments = null, + string $type = self::TYPE_NEW, + array $contacts = null + ): self { + return new self($orderId, $orderDate, $shipTo, $billTo, $total, $comments, $type, $contacts); + } + + public function getShipping(): ?Shipping + { + return $this->shipping; + } + + public function setShipping(?Shipping $shipping): self + { + $this->shipping = $shipping; + + return $this; + } + + public function getTax(): ?Tax + { + return $this->tax; + } + + public function setTax(?Tax $tax): self + { + $this->tax = $tax; + + return $this; + } + + public function getOrderId(): string + { + return $this->orderId; + } + + public function getOrderDate(): \DateTimeInterface + { + return $this->orderDate; + } + + public function getType(): string + { + return $this->type; + } + + public function getTotal(): MoneyWrapper + { + return $this->total; + } + + public function getShipTo(): ?ShipTo + { + return $this->shipTo; + } + + public function getBillTo(): BillTo + { + return $this->billTo; + } + + public function getComments(): ?array + { + return $this->comments; + } + + public function addContact(Contact $contact): self + { + if (null === $this->contacts) { + $this->contacts = []; + } + + $this->contacts[] = $contact; + + return $this; + } + + public function getContacts(): ?array + { + return $this->contacts; + } + + public function getSupplierOrderInfo(): ?SupplierOrderInfo + { + return $this->supplierOrderInfo; + } } diff --git a/src/CXml/Model/Request/PunchOutSetupRequest.php b/src/CXml/Model/Request/PunchOutSetupRequest.php index 5daccd4..2b90b44 100644 --- a/src/CXml/Model/Request/PunchOutSetupRequest.php +++ b/src/CXml/Model/Request/PunchOutSetupRequest.php @@ -12,112 +12,112 @@ class PunchOutSetupRequest implements RequestPayloadInterface { - use ExtrinsicsTrait; - - /** - * @Ser\XmlAttribute - */ - private ?string $operation = null; - - /** - * @Ser\SerializedName("BuyerCookie") - */ - private string $buyerCookie; - - /** - * @Ser\XmlList(inline=true, entry="Extrinsic") - * @Ser\Type("array") - * - * @var Extrinsic[] - */ - protected array $extrinsics = []; - - /** - * @Ser\SerializedName("BrowserFormPost") - */ - private Url $browserFormPost; - - /** - * @Ser\SerializedName("SupplierSetup") - */ - private Url $supplierSetup; - - /** - * @Ser\SerializedName("ShipTo") - */ - private ?ShipTo $shipTo = null; - - /** - * @Ser\SerializedName("SelectedItem") - */ - private ?SelectedItem $selectedItem = null; - - /** - * @Ser\XmlList(inline=true, entry="ItemOut") - * @Ser\Type("array") - * - * @var ItemOut[] - */ - private array $itemOut = []; - - public function __construct(string $buyerCookie, string $browserFormPost, string $supplierSetup, ShipTo $shipTo = null, SelectedItem $selectedItem = null, string $operation = 'create') - { - $this->operation = $operation; - $this->buyerCookie = $buyerCookie; - $this->browserFormPost = new Url($browserFormPost); - $this->supplierSetup = new Url($supplierSetup); - $this->shipTo = $shipTo; - $this->selectedItem = $selectedItem; - } - - public function getOperation(): ?string - { - return $this->operation; - } - - public function getBuyerCookie(): string - { - return $this->buyerCookie; - } - - public function getBrowserFormPost(): Url - { - return $this->browserFormPost; - } - - public function getSupplierSetup(): Url - { - return $this->supplierSetup; - } - - public function getShipTo(): ?ShipTo - { - return $this->shipTo; - } - - public function getSelectedItem(): ?SelectedItem - { - return $this->selectedItem; - } - - public function getItems(): array - { - return $this->itemOut; - } - - public function addItems(array $items): self - { - foreach ($items as $item) { - $this->addItem($item); - } - - return $this; - } - - public function addItem(ItemOut $item): self - { - $this->itemOut[] = $item; - - return $this; - } + use ExtrinsicsTrait; + + /** + * @Ser\XmlAttribute + */ + private ?string $operation = null; + + /** + * @Ser\SerializedName("BuyerCookie") + */ + private string $buyerCookie; + + /** + * @Ser\XmlList(inline=true, entry="Extrinsic") + * @Ser\Type("array") + * + * @var Extrinsic[] + */ + protected array $extrinsics = []; + + /** + * @Ser\SerializedName("BrowserFormPost") + */ + private Url $browserFormPost; + + /** + * @Ser\SerializedName("SupplierSetup") + */ + private Url $supplierSetup; + + /** + * @Ser\SerializedName("ShipTo") + */ + private ?ShipTo $shipTo = null; + + /** + * @Ser\SerializedName("SelectedItem") + */ + private ?SelectedItem $selectedItem = null; + + /** + * @Ser\XmlList(inline=true, entry="ItemOut") + * @Ser\Type("array") + * + * @var ItemOut[] + */ + private array $itemOut = []; + + public function __construct(string $buyerCookie, string $browserFormPost, string $supplierSetup, ShipTo $shipTo = null, SelectedItem $selectedItem = null, string $operation = 'create') + { + $this->operation = $operation; + $this->buyerCookie = $buyerCookie; + $this->browserFormPost = new Url($browserFormPost); + $this->supplierSetup = new Url($supplierSetup); + $this->shipTo = $shipTo; + $this->selectedItem = $selectedItem; + } + + public function getOperation(): ?string + { + return $this->operation; + } + + public function getBuyerCookie(): string + { + return $this->buyerCookie; + } + + public function getBrowserFormPost(): Url + { + return $this->browserFormPost; + } + + public function getSupplierSetup(): Url + { + return $this->supplierSetup; + } + + public function getShipTo(): ?ShipTo + { + return $this->shipTo; + } + + public function getSelectedItem(): ?SelectedItem + { + return $this->selectedItem; + } + + public function getItems(): array + { + return $this->itemOut; + } + + public function addItems(array $items): self + { + foreach ($items as $item) { + $this->addItem($item); + } + + return $this; + } + + public function addItem(ItemOut $item): self + { + $this->itemOut[] = $item; + + return $this; + } } diff --git a/src/CXml/Model/Request/Request.php b/src/CXml/Model/Request/Request.php index bcc2fdb..020f612 100644 --- a/src/CXml/Model/Request/Request.php +++ b/src/CXml/Model/Request/Request.php @@ -8,65 +8,65 @@ class Request { - public const DEPLOYMENT_TEST = 'test'; - public const DEPLOYMENT_PROD = 'production'; + public const DEPLOYMENT_TEST = 'test'; + public const DEPLOYMENT_PROD = 'production'; - /** - * @Ser\SerializedName("Status") - */ - private ?Status $status = null; + /** + * @Ser\SerializedName("Status") + */ + private ?Status $status = null; - /** - * @Ser\XmlAttribute - * @Ser\SerializedName("deploymentMode") - */ - private ?string $deploymentMode = null; + /** + * @Ser\XmlAttribute + * @Ser\SerializedName("deploymentMode") + */ + private ?string $deploymentMode = null; - /** - * @Ser\XmlAttribute - * @Ser\SerializedName("Id") - */ - private ?string $id = null; + /** + * @Ser\XmlAttribute + * @Ser\SerializedName("Id") + */ + private ?string $id = null; - /** - * @Ser\Exclude - * see CXmlWrappingNodeJmsEventSubscriber - */ - private RequestPayloadInterface $payload; + /** + * @Ser\Exclude + * see CXmlWrappingNodeJmsEventSubscriber + */ + private RequestPayloadInterface $payload; - public function __construct( - RequestPayloadInterface $payload, - Status $status = null, - string $id = null, - string $deploymentMode = null - ) { - if (null !== $deploymentMode) { - Assertion::inArray($deploymentMode, [self::DEPLOYMENT_PROD, self::DEPLOYMENT_TEST]); - } + public function __construct( + RequestPayloadInterface $payload, + Status $status = null, + string $id = null, + string $deploymentMode = null + ) { + if (null !== $deploymentMode) { + Assertion::inArray($deploymentMode, [self::DEPLOYMENT_PROD, self::DEPLOYMENT_TEST]); + } - $this->status = $status; - $this->id = $id; - $this->payload = $payload; - $this->deploymentMode = $deploymentMode; - } + $this->status = $status; + $this->id = $id; + $this->payload = $payload; + $this->deploymentMode = $deploymentMode; + } - public function getStatus(): ?Status - { - return $this->status; - } + public function getStatus(): ?Status + { + return $this->status; + } - public function getId(): ?string - { - return $this->id; - } + public function getId(): ?string + { + return $this->id; + } - public function getDeploymentMode(): ?string - { - return $this->deploymentMode; - } + public function getDeploymentMode(): ?string + { + return $this->deploymentMode; + } - public function getPayload(): RequestPayloadInterface - { - return $this->payload; - } + public function getPayload(): RequestPayloadInterface + { + return $this->payload; + } } diff --git a/src/CXml/Model/Request/ShipNoticeHeader.php b/src/CXml/Model/Request/ShipNoticeHeader.php index 47038f6..53a67f7 100644 --- a/src/CXml/Model/Request/ShipNoticeHeader.php +++ b/src/CXml/Model/Request/ShipNoticeHeader.php @@ -10,95 +10,95 @@ class ShipNoticeHeader { - use ExtrinsicsTrait; - use IdReferencesTrait; - - /** - * @Ser\XmlAttribute - * @Ser\SerializedName("shipmentID") - */ - private string $shipmentId; - - /** - * @Ser\XmlAttribute - */ - private \DateTimeInterface $noticeDate; - - /** - * @Ser\XmlAttribute - */ - private ?\DateTimeInterface $shipmentDate = null; - - /** - * @Ser\XmlAttribute - */ - private ?\DateTimeInterface $deliveryDate = null; - - /** - * @Ser\SerializedName("DocumentReference") - */ - private ?DocumentReference $documentReference = null; - - /** - * @Ser\XmlList(inline=true, entry="Comments") - * @Ser\Type("array") - * - * @var Comment[] - */ - private ?array $comments = null; - - public function __construct(string $shipmentId, \DateTimeInterface $noticeDate = null, \DateTimeInterface $shipmentDate = null, \DateTimeInterface $deliveryDate = null, string $documentReference = null) - { - $this->shipmentId = $shipmentId; - $this->noticeDate = $noticeDate ?? new \DateTime(); - $this->shipmentDate = $shipmentDate; - $this->deliveryDate = $deliveryDate; - $this->documentReference = $documentReference ? new DocumentReference($documentReference) : null; - } - - public static function create(string $shipmentId, \DateTimeInterface $noticeDate = null, \DateTimeInterface $shipmentDate = null, \DateTimeInterface $deliveryDate = null, string $documentReference = null): self - { - return new self($shipmentId, $noticeDate, $shipmentDate, $deliveryDate, $documentReference); - } - - public function getDocumentReference(): ?DocumentReference - { - return $this->documentReference; - } - - public function addComment(string $comment, string $type = null, string $lang = null): self - { - if (null === $this->comments) { - $this->comments = []; - } - - $this->comments[] = new Comment($comment, $type, $lang); - - return $this; - } - - public function getComments(): ?array - { - return $this->comments; - } - - public function getShipmentId(): string - { - return $this->shipmentId; - } - - public function getNoticeDate(): \DateTimeInterface - { - return $this->noticeDate; - } - - public function getShipmentDate(): ?\DateTimeInterface - { - return $this->shipmentDate; - } - - public function getDeliveryDate(): ?\DateTimeInterface - { - return $this->deliveryDate; - } + use ExtrinsicsTrait; + use IdReferencesTrait; + + /** + * @Ser\XmlAttribute + * @Ser\SerializedName("shipmentID") + */ + private string $shipmentId; + + /** + * @Ser\XmlAttribute + */ + private \DateTimeInterface $noticeDate; + + /** + * @Ser\XmlAttribute + */ + private ?\DateTimeInterface $shipmentDate = null; + + /** + * @Ser\XmlAttribute + */ + private ?\DateTimeInterface $deliveryDate = null; + + /** + * @Ser\SerializedName("DocumentReference") + */ + private ?DocumentReference $documentReference = null; + + /** + * @Ser\XmlList(inline=true, entry="Comments") + * @Ser\Type("array") + * + * @var Comment[] + */ + private ?array $comments = null; + + public function __construct(string $shipmentId, \DateTimeInterface $noticeDate = null, \DateTimeInterface $shipmentDate = null, \DateTimeInterface $deliveryDate = null, string $documentReference = null) + { + $this->shipmentId = $shipmentId; + $this->noticeDate = $noticeDate ?? new \DateTime(); + $this->shipmentDate = $shipmentDate; + $this->deliveryDate = $deliveryDate; + $this->documentReference = $documentReference ? new DocumentReference($documentReference) : null; + } + + public static function create(string $shipmentId, \DateTimeInterface $noticeDate = null, \DateTimeInterface $shipmentDate = null, \DateTimeInterface $deliveryDate = null, string $documentReference = null): self + { + return new self($shipmentId, $noticeDate, $shipmentDate, $deliveryDate, $documentReference); + } + + public function getDocumentReference(): ?DocumentReference + { + return $this->documentReference; + } + + public function addComment(string $comment, string $type = null, string $lang = null): self + { + if (null === $this->comments) { + $this->comments = []; + } + + $this->comments[] = new Comment($comment, $type, $lang); + + return $this; + } + + public function getComments(): ?array + { + return $this->comments; + } + + public function getShipmentId(): string + { + return $this->shipmentId; + } + + public function getNoticeDate(): \DateTimeInterface + { + return $this->noticeDate; + } + + public function getShipmentDate(): ?\DateTimeInterface + { + return $this->shipmentDate; + } + + public function getDeliveryDate(): ?\DateTimeInterface + { + return $this->deliveryDate; + } } diff --git a/src/CXml/Model/Request/ShipNoticeRequest.php b/src/CXml/Model/Request/ShipNoticeRequest.php index cfa5d8c..abfd9c1 100644 --- a/src/CXml/Model/Request/ShipNoticeRequest.php +++ b/src/CXml/Model/Request/ShipNoticeRequest.php @@ -8,76 +8,76 @@ class ShipNoticeRequest implements RequestPayloadInterface { - /** - * @Ser\SerializedName("ShipNoticeHeader") - */ - private ShipNoticeHeader $shipNoticeHeader; - - /** - * @Ser\XmlList(inline=true, entry="ShipControl") - * @Ser\Type("array") - * - * @var ShipControl[] - */ - private array $shipControls = []; - - /** - * @Ser\XmlList(inline=true, entry="ShipNoticePortion") - * @Ser\Type("array") - * - * @var ShipNoticePortion[] - */ - private array $shipNoticePortions = []; - - public function __construct(ShipNoticeHeader $shipNoticeHeader) - { - $this->shipNoticeHeader = $shipNoticeHeader; - } - - public static function create(ShipNoticeHeader $shipNoticeHeader): self - { - return new self($shipNoticeHeader); - } - - public function addShipControl(ShipControl $shipControl): self - { - $this->shipControls[] = $shipControl; - - return $this; - } - - public function addShipNoticePortion(ShipNoticePortion $shipNoticePortion): self - { - $this->shipNoticePortions[] = $shipNoticePortion; - - return $this; - } - - public function getShipNoticeHeader(): ShipNoticeHeader - { - return $this->shipNoticeHeader; - } - - public function getShipControls(): array - { - return $this->shipControls; - } - - public function getShipNoticePortions(): array - { - return $this->shipNoticePortions; - } - - public function getCommentsAsString(): ?string - { - $commentStrings = []; - - if ($comments = $this->shipNoticeHeader->getComments()) { - foreach ($comments as $comment) { - $commentStrings[] = $comment->getValue(); - } - } - - return empty($commentStrings) ? null : \implode("\n", $commentStrings); - } + /** + * @Ser\SerializedName("ShipNoticeHeader") + */ + private ShipNoticeHeader $shipNoticeHeader; + + /** + * @Ser\XmlList(inline=true, entry="ShipControl") + * @Ser\Type("array") + * + * @var ShipControl[] + */ + private array $shipControls = []; + + /** + * @Ser\XmlList(inline=true, entry="ShipNoticePortion") + * @Ser\Type("array") + * + * @var ShipNoticePortion[] + */ + private array $shipNoticePortions = []; + + public function __construct(ShipNoticeHeader $shipNoticeHeader) + { + $this->shipNoticeHeader = $shipNoticeHeader; + } + + public static function create(ShipNoticeHeader $shipNoticeHeader): self + { + return new self($shipNoticeHeader); + } + + public function addShipControl(ShipControl $shipControl): self + { + $this->shipControls[] = $shipControl; + + return $this; + } + + public function addShipNoticePortion(ShipNoticePortion $shipNoticePortion): self + { + $this->shipNoticePortions[] = $shipNoticePortion; + + return $this; + } + + public function getShipNoticeHeader(): ShipNoticeHeader + { + return $this->shipNoticeHeader; + } + + public function getShipControls(): array + { + return $this->shipControls; + } + + public function getShipNoticePortions(): array + { + return $this->shipNoticePortions; + } + + public function getCommentsAsString(): ?string + { + $commentStrings = []; + + if ($comments = $this->shipNoticeHeader->getComments()) { + foreach ($comments as $comment) { + $commentStrings[] = $comment->getValue(); + } + } + + return empty($commentStrings) ? null : \implode("\n", $commentStrings); + } } diff --git a/src/CXml/Model/Request/StatusUpdateRequest.php b/src/CXml/Model/Request/StatusUpdateRequest.php index 141b1fa..f8c6b05 100644 --- a/src/CXml/Model/Request/StatusUpdateRequest.php +++ b/src/CXml/Model/Request/StatusUpdateRequest.php @@ -9,39 +9,39 @@ class StatusUpdateRequest implements RequestPayloadInterface { - use ExtrinsicsTrait; - - /** - * @Ser\SerializedName("DocumentReference") - */ - private ?DocumentReference $documentReference = null; - - /** - * @Ser\SerializedName("Status") - */ - private Status $status; - - public function __construct(Status $status, string $documentReference = null) - { - $this->status = $status; - $this->documentReference = $documentReference ? new DocumentReference($documentReference) : null; - } - - public static function create(Status $status, string $documentReference = null): self - { - return new self( - $status, - $documentReference - ); - } - - public function getDocumentReference(): ?DocumentReference - { - return $this->documentReference; - } - - public function getStatus(): Status - { - return $this->status; - } + use ExtrinsicsTrait; + + /** + * @Ser\SerializedName("DocumentReference") + */ + private ?DocumentReference $documentReference = null; + + /** + * @Ser\SerializedName("Status") + */ + private Status $status; + + public function __construct(Status $status, string $documentReference = null) + { + $this->status = $status; + $this->documentReference = $documentReference ? new DocumentReference($documentReference) : null; + } + + public static function create(Status $status, string $documentReference = null): self + { + return new self( + $status, + $documentReference + ); + } + + public function getDocumentReference(): ?DocumentReference + { + return $this->documentReference; + } + + public function getStatus(): Status + { + return $this->status; + } } diff --git a/src/CXml/Model/Response/ProfileResponse.php b/src/CXml/Model/Response/ProfileResponse.php index e2e4387..0f5af2d 100644 --- a/src/CXml/Model/Response/ProfileResponse.php +++ b/src/CXml/Model/Response/ProfileResponse.php @@ -8,45 +8,45 @@ class ProfileResponse implements ResponsePayloadInterface { - /** - * @Ser\XmlAttribute - */ - private \DateTimeInterface $effectiveDate; - - /** - * @Ser\XmlAttribute - */ - private ?\DateTimeInterface $lastRefresh = null; - - /** - * @Ser\XmlList(inline=true, entry="Option") - * @Ser\Type("array") - * - * @var Option[] - */ - private array $options = []; - - /** - * @Ser\XmlList(inline=true, entry="Transaction") - * @Ser\Type("array") - * - * @var Transaction[] - */ - private array $transactions = []; - - public function __construct(\DateTimeInterface $effectiveDate = null, \DateTimeInterface $lastRefresh = null) - { - $this->effectiveDate = $effectiveDate ?? new \DateTime(); - $this->lastRefresh = $lastRefresh; - } - - public function addTransaction(Transaction $transaction): void - { - $this->transactions[] = $transaction; - } - - public function addOption(Option $option): void - { - $this->options[] = $option; - } + /** + * @Ser\XmlAttribute + */ + private \DateTimeInterface $effectiveDate; + + /** + * @Ser\XmlAttribute + */ + private ?\DateTimeInterface $lastRefresh = null; + + /** + * @Ser\XmlList(inline=true, entry="Option") + * @Ser\Type("array") + * + * @var Option[] + */ + private array $options = []; + + /** + * @Ser\XmlList(inline=true, entry="Transaction") + * @Ser\Type("array") + * + * @var Transaction[] + */ + private array $transactions = []; + + public function __construct(\DateTimeInterface $effectiveDate = null, \DateTimeInterface $lastRefresh = null) + { + $this->effectiveDate = $effectiveDate ?? new \DateTime(); + $this->lastRefresh = $lastRefresh; + } + + public function addTransaction(Transaction $transaction): void + { + $this->transactions[] = $transaction; + } + + public function addOption(Option $option): void + { + $this->options[] = $option; + } } diff --git a/src/CXml/Model/Response/PunchOutSetupResponse.php b/src/CXml/Model/Response/PunchOutSetupResponse.php index dc8b3e8..e4aff8f 100644 --- a/src/CXml/Model/Response/PunchOutSetupResponse.php +++ b/src/CXml/Model/Response/PunchOutSetupResponse.php @@ -7,13 +7,13 @@ class PunchOutSetupResponse implements ResponsePayloadInterface { - /** - * @Ser\SerializedName("StartPage") - */ - private Url $startPage; + /** + * @Ser\SerializedName("StartPage") + */ + private Url $startPage; - public function __construct(Url $startPage) - { - $this->startPage = $startPage; - } + public function __construct(Url $startPage) + { + $this->startPage = $startPage; + } } diff --git a/src/CXml/Model/Response/Response.php b/src/CXml/Model/Response/Response.php index f1e6c1e..9e63386 100644 --- a/src/CXml/Model/Response/Response.php +++ b/src/CXml/Model/Response/Response.php @@ -7,45 +7,45 @@ class Response { - /** - * @Ser\SerializedName("Status") - */ - private Status $status; - - /** - * @Ser\XmlAttribute - * @Ser\SerializedName("Id") - */ - private ?string $id = null; - - /** - * @Ser\Exclude - * see CXmlWrappingNodeJmsEventSubscriber - */ - private ?ResponsePayloadInterface $payload = null; - - public function __construct( - Status $status, - ResponsePayloadInterface $payload = null, - string $id = null - ) { - $this->status = $status; - $this->id = $id; - $this->payload = $payload; - } - - public function getStatus(): Status - { - return $this->status; - } - - public function getId(): ?string - { - return $this->id; - } - - public function getPayload(): ?ResponsePayloadInterface - { - return $this->payload; - } + /** + * @Ser\SerializedName("Status") + */ + private Status $status; + + /** + * @Ser\XmlAttribute + * @Ser\SerializedName("Id") + */ + private ?string $id = null; + + /** + * @Ser\Exclude + * see CXmlWrappingNodeJmsEventSubscriber + */ + private ?ResponsePayloadInterface $payload = null; + + public function __construct( + Status $status, + ResponsePayloadInterface $payload = null, + string $id = null + ) { + $this->status = $status; + $this->id = $id; + $this->payload = $payload; + } + + public function getStatus(): Status + { + return $this->status; + } + + public function getId(): ?string + { + return $this->id; + } + + public function getPayload(): ?ResponsePayloadInterface + { + return $this->payload; + } } diff --git a/src/CXml/Model/SelectedItem.php b/src/CXml/Model/SelectedItem.php index 9b1261c..4df34ba 100644 --- a/src/CXml/Model/SelectedItem.php +++ b/src/CXml/Model/SelectedItem.php @@ -6,18 +6,18 @@ class SelectedItem { - /** - * @Ser\SerializedName("ItemID") - */ - private ItemId $itemId; + /** + * @Ser\SerializedName("ItemID") + */ + private ItemId $itemId; - public function __construct(ItemId $itemId) - { - $this->itemId = $itemId; - } + public function __construct(ItemId $itemId) + { + $this->itemId = $itemId; + } - public function getItemId(): ItemId - { - return $this->itemId; - } + public function getItemId(): ItemId + { + return $this->itemId; + } } diff --git a/src/CXml/Model/ShipControl.php b/src/CXml/Model/ShipControl.php index e2e5e74..a9be86a 100644 --- a/src/CXml/Model/ShipControl.php +++ b/src/CXml/Model/ShipControl.php @@ -6,69 +6,69 @@ class ShipControl { - /** - * @Ser\XmlList(inline=true, entry="CarrierIdentifier") - * @Ser\Type("array") - * - * @var CarrierIdentifier[] - */ - private array $carrierIdentifiers = []; + /** + * @Ser\XmlList(inline=true, entry="CarrierIdentifier") + * @Ser\Type("array") + * + * @var CarrierIdentifier[] + */ + private array $carrierIdentifiers = []; - /** - * @Ser\XmlList(inline=true, entry="ShipmentIdentifier") - * @Ser\Type("array") - * - * @var ShipmentIdentifier[] - */ - private array $shipmentIdentifiers = []; + /** + * @Ser\XmlList(inline=true, entry="ShipmentIdentifier") + * @Ser\Type("array") + * + * @var ShipmentIdentifier[] + */ + private array $shipmentIdentifiers = []; - public function __construct(CarrierIdentifier $carrierIdentifier, ShipmentIdentifier $shipmentIdentifier) - { - $this->carrierIdentifiers[] = $carrierIdentifier; - $this->shipmentIdentifiers[] = $shipmentIdentifier; - } + public function __construct(CarrierIdentifier $carrierIdentifier, ShipmentIdentifier $shipmentIdentifier) + { + $this->carrierIdentifiers[] = $carrierIdentifier; + $this->shipmentIdentifiers[] = $shipmentIdentifier; + } - public static function create(CarrierIdentifier $carrierIdentifier, ShipmentIdentifier $shipmentIdentifier): self - { - return new self($carrierIdentifier, $shipmentIdentifier); - } + public static function create(CarrierIdentifier $carrierIdentifier, ShipmentIdentifier $shipmentIdentifier): self + { + return new self($carrierIdentifier, $shipmentIdentifier); + } - public function addCarrierIdentifier(string $domain, string $value): self - { - $this->carrierIdentifiers[] = new CarrierIdentifier($domain, $value); + public function addCarrierIdentifier(string $domain, string $value): self + { + $this->carrierIdentifiers[] = new CarrierIdentifier($domain, $value); - return $this; - } + return $this; + } - public function getCarrierIdentifier(string $domain): ?string - { - foreach ($this->carrierIdentifiers as $carrierIdentifier) { - if ($carrierIdentifier->getDomain() === $domain) { - return $carrierIdentifier->getValue(); - } - } + public function getCarrierIdentifier(string $domain): ?string + { + foreach ($this->carrierIdentifiers as $carrierIdentifier) { + if ($carrierIdentifier->getDomain() === $domain) { + return $carrierIdentifier->getValue(); + } + } - return null; - } + return null; + } - public function getShipmentIdentifier(string $domain = null): ?string - { - foreach ($this->shipmentIdentifiers as $shipmentIdentifier) { - if ($shipmentIdentifier->getDomain() === $domain) { - return $shipmentIdentifier->getValue(); - } - } + public function getShipmentIdentifier(string $domain = null): ?string + { + foreach ($this->shipmentIdentifiers as $shipmentIdentifier) { + if ($shipmentIdentifier->getDomain() === $domain) { + return $shipmentIdentifier->getValue(); + } + } - return null; - } + return null; + } - public function getCarrierIdentifiers(): array - { - return $this->carrierIdentifiers; - } + public function getCarrierIdentifiers(): array + { + return $this->carrierIdentifiers; + } - public function getShipmentIdentifiers(): array - { - return $this->shipmentIdentifiers; - } + public function getShipmentIdentifiers(): array + { + return $this->shipmentIdentifiers; + } } diff --git a/src/CXml/Model/ShipNoticePortion.php b/src/CXml/Model/ShipNoticePortion.php index 35bd75d..cb31c0c 100644 --- a/src/CXml/Model/ShipNoticePortion.php +++ b/src/CXml/Model/ShipNoticePortion.php @@ -6,24 +6,24 @@ class ShipNoticePortion { - /** - * @Ser\SerializedName("OrderReference") - */ - private OrderReference $orderReference; + /** + * @Ser\SerializedName("OrderReference") + */ + private OrderReference $orderReference; - public function __construct(string $documentReference, string $orderId = null, \DateTimeInterface $orderDate = null) - { - $this->orderReference = new OrderReference( - new DocumentReference( - $documentReference - ), - $orderId, - $orderDate - ); - } + public function __construct(string $documentReference, string $orderId = null, \DateTimeInterface $orderDate = null) + { + $this->orderReference = new OrderReference( + new DocumentReference( + $documentReference + ), + $orderId, + $orderDate + ); + } - public function getOrderReference(): OrderReference - { - return $this->orderReference; - } + public function getOrderReference(): OrderReference + { + return $this->orderReference; + } } diff --git a/src/CXml/Model/ShipTo.php b/src/CXml/Model/ShipTo.php index 1e754f2..8d83061 100644 --- a/src/CXml/Model/ShipTo.php +++ b/src/CXml/Model/ShipTo.php @@ -6,41 +6,41 @@ class ShipTo { - use IdReferencesTrait; - - /** - * @Ser\SerializedName("Address") - */ - private Address $address; - - /** - * @Ser\XmlList(inline=true, entry="CarrierIdentifier") - * @Ser\Type("array") - * - * @var CarrierIdentifier[] - */ - private array $carrierIdentifiers = []; - - /** - * @Ser\SerializedName("TransportInformation") - */ - private ?TransportInformation $transportInformation = null; - - public function __construct(Address $address, TransportInformation $transportInformation = null) - { - $this->address = $address; - $this->transportInformation = $transportInformation; - } - - public function addCarrierIdentifier(string $domain, string $identifier): self - { - $this->carrierIdentifiers[] = new CarrierIdentifier($domain, $identifier); - - return $this; - } - - public function getAddress(): Address - { - return $this->address; - } + use IdReferencesTrait; + + /** + * @Ser\SerializedName("Address") + */ + private Address $address; + + /** + * @Ser\XmlList(inline=true, entry="CarrierIdentifier") + * @Ser\Type("array") + * + * @var CarrierIdentifier[] + */ + private array $carrierIdentifiers = []; + + /** + * @Ser\SerializedName("TransportInformation") + */ + private ?TransportInformation $transportInformation = null; + + public function __construct(Address $address, TransportInformation $transportInformation = null) + { + $this->address = $address; + $this->transportInformation = $transportInformation; + } + + public function addCarrierIdentifier(string $domain, string $identifier): self + { + $this->carrierIdentifiers[] = new CarrierIdentifier($domain, $identifier); + + return $this; + } + + public function getAddress(): Address + { + return $this->address; + } } diff --git a/src/CXml/Model/ShipmentIdentifier.php b/src/CXml/Model/ShipmentIdentifier.php index 79686a5..1400213 100644 --- a/src/CXml/Model/ShipmentIdentifier.php +++ b/src/CXml/Model/ShipmentIdentifier.php @@ -6,51 +6,51 @@ class ShipmentIdentifier { - /** - * @Ser\XmlAttribute - */ - private ?string $domain = null; - - /** - * @Ser\XmlAttribute - */ - private ?string $trackingNumberDate = null; - - /** - * @Ser\XmlAttribute - */ - private ?string $trackingURL = null; - - /** - * @Ser\XmlValue(cdata=false) - */ - private string $value; - - public function __construct(string $value, string $domain = null, string $trackingNumberDate = null, string $trackingURL = null) - { - $this->value = $value; - $this->domain = $domain; - $this->trackingNumberDate = $trackingNumberDate; - $this->trackingURL = $trackingURL; - } - - public function getDomain(): ?string - { - return $this->domain; - } - - public function getValue(): string - { - return $this->value; - } - - public function getTrackingNumberDate(): ?string - { - return $this->trackingNumberDate; - } - - public function getTrackingURL(): ?string - { - return $this->trackingURL; - } + /** + * @Ser\XmlAttribute + */ + private ?string $domain = null; + + /** + * @Ser\XmlAttribute + */ + private ?string $trackingNumberDate = null; + + /** + * @Ser\XmlAttribute + */ + private ?string $trackingURL = null; + + /** + * @Ser\XmlValue(cdata=false) + */ + private string $value; + + public function __construct(string $value, string $domain = null, string $trackingNumberDate = null, string $trackingURL = null) + { + $this->value = $value; + $this->domain = $domain; + $this->trackingNumberDate = $trackingNumberDate; + $this->trackingURL = $trackingURL; + } + + public function getDomain(): ?string + { + return $this->domain; + } + + public function getValue(): string + { + return $this->value; + } + + public function getTrackingNumberDate(): ?string + { + return $this->trackingNumberDate; + } + + public function getTrackingURL(): ?string + { + return $this->trackingURL; + } } diff --git a/src/CXml/Model/Shipping.php b/src/CXml/Model/Shipping.php index 47da105..6ae7736 100644 --- a/src/CXml/Model/Shipping.php +++ b/src/CXml/Model/Shipping.php @@ -6,30 +6,30 @@ class Shipping { - /** - * @Ser\SerializedName("Money") - */ - private Money $money; + /** + * @Ser\SerializedName("Money") + */ + private Money $money; - /** - * @Ser\SerializedName("Description") - * @Ser\XmlElement (cdata=false) - */ - private Description $description; + /** + * @Ser\SerializedName("Description") + * @Ser\XmlElement (cdata=false) + */ + private Description $description; - public function __construct(string $currency, int $value, Description $description) - { - $this->money = new Money($currency, $value); - $this->description = $description; - } + public function __construct(string $currency, int $value, Description $description) + { + $this->money = new Money($currency, $value); + $this->description = $description; + } - public function getMoney(): Money - { - return $this->money; - } + public function getMoney(): Money + { + return $this->money; + } - public function getDescription(): ?MultilanguageString - { - return $this->description; - } + public function getDescription(): ?MultilanguageString + { + return $this->description; + } } diff --git a/src/CXml/Model/ShippingContractNumber.php b/src/CXml/Model/ShippingContractNumber.php index 24b9f27..451d078 100644 --- a/src/CXml/Model/ShippingContractNumber.php +++ b/src/CXml/Model/ShippingContractNumber.php @@ -6,13 +6,13 @@ class ShippingContractNumber { - /** - * @Ser\XmlValue(cdata=false) - */ - private string $value; + /** + * @Ser\XmlValue(cdata=false) + */ + private string $value; - public function __construct(string $value) - { - $this->value = $value; - } + public function __construct(string $value) + { + $this->value = $value; + } } diff --git a/src/CXml/Model/Status.php b/src/CXml/Model/Status.php index 92be839..2026a50 100644 --- a/src/CXml/Model/Status.php +++ b/src/CXml/Model/Status.php @@ -6,46 +6,46 @@ class Status { - /** - * @Ser\XmlAttribute(namespace="http://www.w3.org/XML/1998/namespace") - */ - private ?string $lang = null; - - /** - * @Ser\XmlAttribute - */ - private int $code; - - /** - * @Ser\XmlAttribute - */ - private string $text; - - /** - * @Ser\XmlValue(cdata=false) - */ - private ?string $message = null; - - public function __construct(int $code = 200, string $text = 'OK', string $message = null, string $lang = null) - { - $this->code = $code; - $this->text = $text; - $this->message = $message; - $this->lang = $lang; - } - - public function getCode(): int - { - return $this->code; - } - - public function getText(): string - { - return $this->text; - } - - public function getMessage(): ?string - { - return $this->message; - } + /** + * @Ser\XmlAttribute(namespace="http://www.w3.org/XML/1998/namespace") + */ + private ?string $lang = null; + + /** + * @Ser\XmlAttribute + */ + private int $code; + + /** + * @Ser\XmlAttribute + */ + private string $text; + + /** + * @Ser\XmlValue(cdata=false) + */ + private ?string $message = null; + + public function __construct(int $code = 200, string $text = 'OK', string $message = null, string $lang = null) + { + $this->code = $code; + $this->text = $text; + $this->message = $message; + $this->lang = $lang; + } + + public function getCode(): int + { + return $this->code; + } + + public function getText(): string + { + return $this->text; + } + + public function getMessage(): ?string + { + return $this->message; + } } diff --git a/src/CXml/Model/SupplierOrderInfo.php b/src/CXml/Model/SupplierOrderInfo.php index 7425443..7847f03 100644 --- a/src/CXml/Model/SupplierOrderInfo.php +++ b/src/CXml/Model/SupplierOrderInfo.php @@ -6,30 +6,30 @@ class SupplierOrderInfo { - /** - * @Ser\XmlAttribute - * @Ser\SerializedName("orderID") - */ - private string $orderId; + /** + * @Ser\XmlAttribute + * @Ser\SerializedName("orderID") + */ + private string $orderId; - /** - * @Ser\XmlAttribute - */ - private ?\DateTimeInterface $orderDate; + /** + * @Ser\XmlAttribute + */ + private ?\DateTimeInterface $orderDate; - public function __construct(string $orderId, \DateTimeInterface $orderDate = null) - { - $this->orderId = $orderId; - $this->orderDate = $orderDate; - } + public function __construct(string $orderId, \DateTimeInterface $orderDate = null) + { + $this->orderId = $orderId; + $this->orderDate = $orderDate; + } - public function getOrderId(): string - { - return $this->orderId; - } + public function getOrderId(): string + { + return $this->orderId; + } - public function getOrderDate(): ?\DateTimeInterface - { - return $this->orderDate; - } + public function getOrderDate(): ?\DateTimeInterface + { + return $this->orderDate; + } } diff --git a/src/CXml/Model/Tax.php b/src/CXml/Model/Tax.php index 5605057..41cefa7 100644 --- a/src/CXml/Model/Tax.php +++ b/src/CXml/Model/Tax.php @@ -6,30 +6,30 @@ class Tax { - /** - * @Ser\SerializedName("Money") - */ - private Money $money; + /** + * @Ser\SerializedName("Money") + */ + private Money $money; - /** - * @Ser\SerializedName("Description") - * @Ser\XmlElement (cdata=false) - */ - private MultilanguageString $description; + /** + * @Ser\SerializedName("Description") + * @Ser\XmlElement (cdata=false) + */ + private MultilanguageString $description; - public function __construct(string $currency, int $value, MultilanguageString $description) - { - $this->money = new Money($currency, $value); - $this->description = $description; - } + public function __construct(string $currency, int $value, MultilanguageString $description) + { + $this->money = new Money($currency, $value); + $this->description = $description; + } - public function getMoney(): Money - { - return $this->money; - } + public function getMoney(): Money + { + return $this->money; + } - public function getDescription(): MultilanguageString - { - return $this->description; - } + public function getDescription(): MultilanguageString + { + return $this->description; + } } diff --git a/src/CXml/Model/Transaction.php b/src/CXml/Model/Transaction.php index 0452dda..a8587c1 100644 --- a/src/CXml/Model/Transaction.php +++ b/src/CXml/Model/Transaction.php @@ -6,33 +6,33 @@ class Transaction { - /** - * @Ser\XmlAttribute - */ - private string $requestName; + /** + * @Ser\XmlAttribute + */ + private string $requestName; - /** - * @Ser\SerializedName("URL") - * @Ser\XmlElement(cdata=false) - */ - private string $url; + /** + * @Ser\SerializedName("URL") + * @Ser\XmlElement(cdata=false) + */ + private string $url; - /** - * @Ser\XmlList(inline=true, entry="Option") - * @Ser\Type("array") - * - * @var Option[] - */ - private array $options = []; + /** + * @Ser\XmlList(inline=true, entry="Option") + * @Ser\Type("array") + * + * @var Option[] + */ + private array $options = []; - public function __construct(string $requestName, string $url) - { - $this->requestName = $requestName; - $this->url = $url; - } + public function __construct(string $requestName, string $url) + { + $this->requestName = $requestName; + $this->url = $url; + } - public function addOption(Option $option): void - { - $this->options[] = $option; - } + public function addOption(Option $option): void + { + $this->options[] = $option; + } } diff --git a/src/CXml/Model/TransportInformation.php b/src/CXml/Model/TransportInformation.php index bc4de90..bb77cbe 100644 --- a/src/CXml/Model/TransportInformation.php +++ b/src/CXml/Model/TransportInformation.php @@ -6,18 +6,18 @@ class TransportInformation { - /** - * @Ser\SerializedName("ShippingContractNumber") - */ - private ?ShippingContractNumber $shippingContractNumber = null; + /** + * @Ser\SerializedName("ShippingContractNumber") + */ + private ?ShippingContractNumber $shippingContractNumber = null; - public function __construct(?ShippingContractNumber $shippingContractNumber) - { - $this->shippingContractNumber = $shippingContractNumber; - } + public function __construct(?ShippingContractNumber $shippingContractNumber) + { + $this->shippingContractNumber = $shippingContractNumber; + } - public static function fromContractAccountNumber(string $carrierAccountNo): self - { - return new self(new ShippingContractNumber($carrierAccountNo)); - } + public static function fromContractAccountNumber(string $carrierAccountNo): self + { + return new self(new ShippingContractNumber($carrierAccountNo)); + } } diff --git a/src/CXml/Model/UnitOfMeasure.php b/src/CXml/Model/UnitOfMeasure.php index c5f2d2f..8459ea3 100644 --- a/src/CXml/Model/UnitOfMeasure.php +++ b/src/CXml/Model/UnitOfMeasure.php @@ -6,18 +6,18 @@ class UnitOfMeasure { - /** - * @Ser\XmlValue(cdata=false) - */ - private string $value; + /** + * @Ser\XmlValue(cdata=false) + */ + private string $value; - public function __construct(string $value) - { - $this->value = $value; - } + public function __construct(string $value) + { + $this->value = $value; + } - public function getValue(): string - { - return $this->value; - } + public function getValue(): string + { + return $this->value; + } } diff --git a/src/CXml/Model/Url.php b/src/CXml/Model/Url.php index db2c4db..74ca3a3 100644 --- a/src/CXml/Model/Url.php +++ b/src/CXml/Model/Url.php @@ -6,19 +6,19 @@ class Url { - /** - * @Ser\SerializedName("URL") - * @Ser\XmlElement(cdata=false) - */ - private string $url; + /** + * @Ser\SerializedName("URL") + * @Ser\XmlElement(cdata=false) + */ + private string $url; - public function __construct(string $url) - { - $this->url = $url; - } + public function __construct(string $url) + { + $this->url = $url; + } - public function getUrl(): string - { - return $this->url; - } + public function getUrl(): string + { + return $this->url; + } } diff --git a/src/CXml/Payload/DefaultPayloadIdentityFactory.php b/src/CXml/Payload/DefaultPayloadIdentityFactory.php index 3020480..9c6c728 100644 --- a/src/CXml/Payload/DefaultPayloadIdentityFactory.php +++ b/src/CXml/Payload/DefaultPayloadIdentityFactory.php @@ -6,40 +6,40 @@ class DefaultPayloadIdentityFactory implements PayloadIdentityFactoryInterface { - /** - * @var callable|\Closure - */ - private $timeCallable; + /** + * @var callable|\Closure + */ + private $timeCallable; - public function __construct(callable $timeCallable = null) - { - $this->timeCallable = $timeCallable ?? function () { - return new \DateTime(); - }; - } + public function __construct(callable $timeCallable = null) + { + $this->timeCallable = $timeCallable ?? function () { + return new \DateTime(); + }; + } - private static function generateNewPayloadId(\DateTimeInterface $timestamp): string - { - // The recommended implementation is: - // datetime.process id.random number@hostname - return \sprintf( - '%s.%s.%s@%s', - $timestamp->format('U.v'), // include milliseconds - \getmypid(), - \mt_rand(1000, 9999), - \gethostname() - ); - } + private static function generateNewPayloadId(\DateTimeInterface $timestamp): string + { + // The recommended implementation is: + // datetime.process id.random number@hostname + return \sprintf( + '%s.%s.%s@%s', + $timestamp->format('U.v'), // include milliseconds + \getmypid(), + \mt_rand(1000, 9999), + \gethostname() + ); + } - public function newPayloadIdentity(): PayloadIdentity - { - /** @var \DateTimeInterface $timestamp */ - $timestamp = \call_user_func($this->timeCallable); - $payloadId = self::generateNewPayloadId($timestamp); + public function newPayloadIdentity(): PayloadIdentity + { + /** @var \DateTimeInterface $timestamp */ + $timestamp = \call_user_func($this->timeCallable); + $payloadId = self::generateNewPayloadId($timestamp); - return new PayloadIdentity( - $payloadId, - $timestamp - ); - } + return new PayloadIdentity( + $payloadId, + $timestamp + ); + } } diff --git a/src/CXml/Payload/PayloadIdentityFactoryInterface.php b/src/CXml/Payload/PayloadIdentityFactoryInterface.php index 3025c19..a48b4da 100644 --- a/src/CXml/Payload/PayloadIdentityFactoryInterface.php +++ b/src/CXml/Payload/PayloadIdentityFactoryInterface.php @@ -6,5 +6,5 @@ interface PayloadIdentityFactoryInterface { - public function newPayloadIdentity(): PayloadIdentity; + public function newPayloadIdentity(): PayloadIdentity; } diff --git a/src/CXml/Processor/Exception/CXmlProcessException.php b/src/CXml/Processor/Exception/CXmlProcessException.php index 41c8e6b..5c5077a 100644 --- a/src/CXml/Processor/Exception/CXmlProcessException.php +++ b/src/CXml/Processor/Exception/CXmlProcessException.php @@ -6,8 +6,8 @@ class CXmlProcessException extends CXmlException { - public function __construct(\Throwable $previous) - { - parent::__construct('Error while processing cXML message: '.$previous->getMessage(), $previous); - } + public function __construct(\Throwable $previous) + { + parent::__construct('Error while processing cXML message: '.$previous->getMessage(), $previous); + } } diff --git a/src/CXml/Processor/HeaderProcessor.php b/src/CXml/Processor/HeaderProcessor.php index 1c66d40..a72168f 100644 --- a/src/CXml/Processor/HeaderProcessor.php +++ b/src/CXml/Processor/HeaderProcessor.php @@ -12,47 +12,47 @@ class HeaderProcessor { - private CredentialRepositoryInterface $credentialRepository; - private AuthenticatorInterface $authenticator; - - public function __construct(CredentialRepositoryInterface $credentialRepository, AuthenticatorInterface $authenticator) - { - $this->credentialRepository = $credentialRepository; - $this->authenticator = $authenticator; - } - - /** - * @throws CXmlCredentialInvalidException - * @throws CXmlAuthenticationInvalidException - */ - public function process(Header $header, Context $context): void - { - $this->validatePartys($header); - - $this->authenticator->authenticate($header, $context); - } - - /** - * @throws CXmlCredentialInvalidException - */ - private function validatePartys(Header $header): void - { - $this->checkCredentialIsValid($header->getFrom()->getCredential()); - - $this->checkCredentialIsValid($header->getTo()->getCredential()); - - $this->checkCredentialIsValid($header->getSender()->getCredential()); - } - - /** - * @throws CXmlCredentialInvalidException - */ - private function checkCredentialIsValid(Credential $testCredential): void - { - // provoke an exception if credential was not found - $this->credentialRepository->getCredentialByDomainAndId( - $testCredential->getDomain(), - $testCredential->getIdentity() - ); - } + private CredentialRepositoryInterface $credentialRepository; + private AuthenticatorInterface $authenticator; + + public function __construct(CredentialRepositoryInterface $credentialRepository, AuthenticatorInterface $authenticator) + { + $this->credentialRepository = $credentialRepository; + $this->authenticator = $authenticator; + } + + /** + * @throws CXmlCredentialInvalidException + * @throws CXmlAuthenticationInvalidException + */ + public function process(Header $header, Context $context): void + { + $this->validatePartys($header); + + $this->authenticator->authenticate($header, $context); + } + + /** + * @throws CXmlCredentialInvalidException + */ + private function validatePartys(Header $header): void + { + $this->checkCredentialIsValid($header->getFrom()->getCredential()); + + $this->checkCredentialIsValid($header->getTo()->getCredential()); + + $this->checkCredentialIsValid($header->getSender()->getCredential()); + } + + /** + * @throws CXmlCredentialInvalidException + */ + private function checkCredentialIsValid(Credential $testCredential): void + { + // provoke an exception if credential was not found + $this->credentialRepository->getCredentialByDomainAndId( + $testCredential->getDomain(), + $testCredential->getIdentity() + ); + } } diff --git a/src/CXml/Processor/Processor.php b/src/CXml/Processor/Processor.php index 10107b9..9fa7973 100644 --- a/src/CXml/Processor/Processor.php +++ b/src/CXml/Processor/Processor.php @@ -24,215 +24,215 @@ class Processor { - // according to cXML reference document - private static array $exceptionMapping = [ - CXmlAuthenticationInvalidException::class => 401, - CXmlNotAcceptableException::class => 406, - CXmlConflictException::class => 409, - CXmlPreconditionFailedException::class => 412, - CXmlExpectationFailedException::class => 417, - CXmlNotImplementedException::class => 450, - ]; - - private static array $exceptionCodeMapping = [ - // cxml - 450 => 'Not Implemented', - - // http - shamelessly copied from Symfony\Component\HttpFoundation\Response - 100 => 'Continue', - 101 => 'Switching Protocols', - 102 => 'Processing', // RFC2518 - 103 => 'Early Hints', - 200 => 'OK', - 201 => 'Created', - 202 => 'Accepted', - 203 => 'Non-Authoritative Information', - 204 => 'No Content', - 205 => 'Reset Content', - 206 => 'Partial Content', - 207 => 'Multi-Status', // RFC4918 - 208 => 'Already Reported', // RFC5842 - 226 => 'IM Used', // RFC3229 - 300 => 'Multiple Choices', - 301 => 'Moved Permanently', - 302 => 'Found', - 303 => 'See Other', - 304 => 'Not Modified', - 305 => 'Use Proxy', - 307 => 'Temporary Redirect', - 308 => 'Permanent Redirect', // RFC7238 - 400 => 'Bad Request', - 401 => 'Unauthorized', - 402 => 'Payment Required', - 403 => 'Forbidden', - 404 => 'Not Found', - 405 => 'Method Not Allowed', - 406 => 'Not Acceptable', - 407 => 'Proxy Authentication Required', - 408 => 'Request Timeout', - 409 => 'Conflict', - 410 => 'Gone', - 411 => 'Length Required', - 412 => 'Precondition Failed', - 413 => 'Payload Too Large', - 414 => 'URI Too Long', - 415 => 'Unsupported Media Type', - 416 => 'Range Not Satisfiable', - 417 => 'Expectation Failed', - 418 => 'I\'m a teapot', // RFC2324 - 421 => 'Misdirected Request', // RFC7540 - 422 => 'Unprocessable Entity', // RFC4918 - 423 => 'Locked', // RFC4918 - 424 => 'Failed Dependency', // RFC4918 - 425 => 'Too Early', // RFC-ietf-httpbis-replay-04 - 426 => 'Upgrade Required', // RFC2817 - 428 => 'Precondition Required', // RFC6585 - 429 => 'Too Many Requests', // RFC6585 - 431 => 'Request Header Fields Too Large', // RFC6585 - 451 => 'Unavailable For Legal Reasons', // RFC7725 - 500 => 'Internal Server Error', - 501 => 'Not Implemented', - 502 => 'Bad Gateway', - 503 => 'Service Unavailable', - 504 => 'Gateway Timeout', - 505 => 'HTTP Version Not Supported', - 506 => 'Variant Also Negotiates', // RFC2295 - 507 => 'Insufficient Storage', // RFC4918 - 508 => 'Loop Detected', // RFC5842 - 510 => 'Not Extended', // RFC2774 - 511 => 'Network Authentication Required', // RFC6585 - ]; - - private HeaderProcessor $headerProcessor; - private HandlerRegistryInterface $handlerRegistry; - private Builder $builder; - - public function __construct( - HeaderProcessor $requestProcessor, - HandlerRegistryInterface $handlerRepository, - Builder $builder - ) { - $this->headerProcessor = $requestProcessor; - $this->handlerRegistry = $handlerRepository; - $this->builder = $builder; - } - - /** - * @throws CXmlException - */ - public function process(CXml $cxml, Context $context = null): ?CXml - { - $context ??= Context::create(); - $context->setCXml($cxml); - - $request = $cxml->getRequest(); - if ($request) { - return $this->processRequest($request, $context); - } - - $response = $cxml->getResponse(); - if ($response) { - $this->processResponse($response, $context); - - return null; - } - - $message = $cxml->getMessage(); - if ($message) { - $this->processMessage($message, $context); - - return null; - } - - throw new CXmlException('Invalid CXml. Either request, response or message must be given.'); - } - - private function getHandlerForPayload(PayloadInterface $payload): HandlerInterface - { - $handlerId = (new \ReflectionClass($payload))->getShortName(); - - return $this->handlerRegistry->get($handlerId); - } - - /** - * @throws CXmlProcessException - * @throws CXmlException - */ - private function processMessage(Message $message, Context $context): void - { - $payload = $message->getPayload(); - - try { - $this->getHandlerForPayload($payload)->handle($payload, $context); - } catch (\Throwable $e) { - throw new CXmlProcessException($e); - } - } - - /** - * @throws CXmlProcessException - * @throws CXmlException - */ - private function processResponse(Response $response, Context $context): void - { - $payload = $response->getPayload(); - - if (!$payload instanceof ResponsePayloadInterface) { - return; - } - - try { - $this->getHandlerForPayload($payload)->handle($payload, $context); - } catch (\Throwable $e) { - throw new CXmlProcessException($e); - } - } - - /** - * @throws CXmlProcessException - * @throws CXmlException - */ - private function processRequest(Request $request, Context $context): CXml - { - $header = $context->getCXml() ? $context->getCXml()->getHeader() : null; - if (!$header) { - throw new CXmlException('Invalid CXml. Header is mandatory for request message.'); - } - - try { - $this->headerProcessor->process($header, $context); - } catch (\Throwable $e) { - throw new CXmlProcessException($e); - } - - $payload = $request->getPayload(); - $handler = $this->getHandlerForPayload($payload); - - $response = $handler->handle($payload, $context); - - // if no response was returned, set an implicit 200/OK - if (!$response) { - $this->builder->status(new Status( - 200, - 'OK' - )); - } - - return $this->builder - ->payload($response) - ->build() - ; - } - - public function buildResponseForException(CXmlException $exception): CXml - { - $statusCode = self::$exceptionMapping[\get_class($exception)] ?? 500; - $statusText = self::$exceptionCodeMapping[$statusCode] ?? 'Unknown status'; - $status = new Status($statusCode, $statusText, $exception->getMessage()); - - return $this->builder - ->status($status) - ->build() - ; - } + // according to cXML reference document + private static array $exceptionMapping = [ + CXmlAuthenticationInvalidException::class => 401, + CXmlNotAcceptableException::class => 406, + CXmlConflictException::class => 409, + CXmlPreconditionFailedException::class => 412, + CXmlExpectationFailedException::class => 417, + CXmlNotImplementedException::class => 450, + ]; + + private static array $exceptionCodeMapping = [ + // cxml + 450 => 'Not Implemented', + + // http - shamelessly copied from Symfony\Component\HttpFoundation\Response + 100 => 'Continue', + 101 => 'Switching Protocols', + 102 => 'Processing', // RFC2518 + 103 => 'Early Hints', + 200 => 'OK', + 201 => 'Created', + 202 => 'Accepted', + 203 => 'Non-Authoritative Information', + 204 => 'No Content', + 205 => 'Reset Content', + 206 => 'Partial Content', + 207 => 'Multi-Status', // RFC4918 + 208 => 'Already Reported', // RFC5842 + 226 => 'IM Used', // RFC3229 + 300 => 'Multiple Choices', + 301 => 'Moved Permanently', + 302 => 'Found', + 303 => 'See Other', + 304 => 'Not Modified', + 305 => 'Use Proxy', + 307 => 'Temporary Redirect', + 308 => 'Permanent Redirect', // RFC7238 + 400 => 'Bad Request', + 401 => 'Unauthorized', + 402 => 'Payment Required', + 403 => 'Forbidden', + 404 => 'Not Found', + 405 => 'Method Not Allowed', + 406 => 'Not Acceptable', + 407 => 'Proxy Authentication Required', + 408 => 'Request Timeout', + 409 => 'Conflict', + 410 => 'Gone', + 411 => 'Length Required', + 412 => 'Precondition Failed', + 413 => 'Payload Too Large', + 414 => 'URI Too Long', + 415 => 'Unsupported Media Type', + 416 => 'Range Not Satisfiable', + 417 => 'Expectation Failed', + 418 => 'I\'m a teapot', // RFC2324 + 421 => 'Misdirected Request', // RFC7540 + 422 => 'Unprocessable Entity', // RFC4918 + 423 => 'Locked', // RFC4918 + 424 => 'Failed Dependency', // RFC4918 + 425 => 'Too Early', // RFC-ietf-httpbis-replay-04 + 426 => 'Upgrade Required', // RFC2817 + 428 => 'Precondition Required', // RFC6585 + 429 => 'Too Many Requests', // RFC6585 + 431 => 'Request Header Fields Too Large', // RFC6585 + 451 => 'Unavailable For Legal Reasons', // RFC7725 + 500 => 'Internal Server Error', + 501 => 'Not Implemented', + 502 => 'Bad Gateway', + 503 => 'Service Unavailable', + 504 => 'Gateway Timeout', + 505 => 'HTTP Version Not Supported', + 506 => 'Variant Also Negotiates', // RFC2295 + 507 => 'Insufficient Storage', // RFC4918 + 508 => 'Loop Detected', // RFC5842 + 510 => 'Not Extended', // RFC2774 + 511 => 'Network Authentication Required', // RFC6585 + ]; + + private HeaderProcessor $headerProcessor; + private HandlerRegistryInterface $handlerRegistry; + private Builder $builder; + + public function __construct( + HeaderProcessor $requestProcessor, + HandlerRegistryInterface $handlerRepository, + Builder $builder + ) { + $this->headerProcessor = $requestProcessor; + $this->handlerRegistry = $handlerRepository; + $this->builder = $builder; + } + + /** + * @throws CXmlException + */ + public function process(CXml $cxml, Context $context = null): ?CXml + { + $context ??= Context::create(); + $context->setCXml($cxml); + + $request = $cxml->getRequest(); + if ($request) { + return $this->processRequest($request, $context); + } + + $response = $cxml->getResponse(); + if ($response) { + $this->processResponse($response, $context); + + return null; + } + + $message = $cxml->getMessage(); + if ($message) { + $this->processMessage($message, $context); + + return null; + } + + throw new CXmlException('Invalid CXml. Either request, response or message must be given.'); + } + + private function getHandlerForPayload(PayloadInterface $payload): HandlerInterface + { + $handlerId = (new \ReflectionClass($payload))->getShortName(); + + return $this->handlerRegistry->get($handlerId); + } + + /** + * @throws CXmlProcessException + * @throws CXmlException + */ + private function processMessage(Message $message, Context $context): void + { + $payload = $message->getPayload(); + + try { + $this->getHandlerForPayload($payload)->handle($payload, $context); + } catch (\Throwable $e) { + throw new CXmlProcessException($e); + } + } + + /** + * @throws CXmlProcessException + * @throws CXmlException + */ + private function processResponse(Response $response, Context $context): void + { + $payload = $response->getPayload(); + + if (!$payload instanceof ResponsePayloadInterface) { + return; + } + + try { + $this->getHandlerForPayload($payload)->handle($payload, $context); + } catch (\Throwable $e) { + throw new CXmlProcessException($e); + } + } + + /** + * @throws CXmlProcessException + * @throws CXmlException + */ + private function processRequest(Request $request, Context $context): CXml + { + $header = $context->getCXml() ? $context->getCXml()->getHeader() : null; + if (!$header) { + throw new CXmlException('Invalid CXml. Header is mandatory for request message.'); + } + + try { + $this->headerProcessor->process($header, $context); + } catch (\Throwable $e) { + throw new CXmlProcessException($e); + } + + $payload = $request->getPayload(); + $handler = $this->getHandlerForPayload($payload); + + $response = $handler->handle($payload, $context); + + // if no response was returned, set an implicit 200/OK + if (!$response) { + $this->builder->status(new Status( + 200, + 'OK' + )); + } + + return $this->builder + ->payload($response) + ->build() + ; + } + + public function buildResponseForException(CXmlException $exception): CXml + { + $statusCode = self::$exceptionMapping[\get_class($exception)] ?? 500; + $statusText = self::$exceptionCodeMapping[$statusCode] ?? 'Unknown status'; + $status = new Status($statusCode, $statusText, $exception->getMessage()); + + return $this->builder + ->status($status) + ->build() + ; + } } diff --git a/src/CXml/Serializer.php b/src/CXml/Serializer.php index e877fc4..bebf83c 100644 --- a/src/CXml/Serializer.php +++ b/src/CXml/Serializer.php @@ -14,66 +14,66 @@ class Serializer { - private SerializerInterface $jmsSerializer; + private SerializerInterface $jmsSerializer; - private function __construct(SerializerInterface $jmsSerializer) - { - $this->jmsSerializer = $jmsSerializer; - } + private function __construct(SerializerInterface $jmsSerializer) + { + $this->jmsSerializer = $jmsSerializer; + } - public static function create(): self - { - $jmsSerializer = SerializerBuilder::create() - ->configureListeners(function (EventDispatcherInterface $dispatcher): void { - $dispatcher->addSubscriber(new CXmlWrappingNodeJmsEventSubscriber()); - }) - ->configureHandlers(function (HandlerRegistry $registry): void { - $handler = new JmsDateTimeHandler(); + public static function create(): self + { + $jmsSerializer = SerializerBuilder::create() + ->configureListeners(function (EventDispatcherInterface $dispatcher): void { + $dispatcher->addSubscriber(new CXmlWrappingNodeJmsEventSubscriber()); + }) + ->configureHandlers(function (HandlerRegistry $registry): void { + $handler = new JmsDateTimeHandler(); - $callable = [ - $handler, - 'serialize', - ]; - $registry->registerHandler(GraphNavigatorInterface::DIRECTION_SERIALIZATION, \DateTimeInterface::class, 'xml', $callable); - $registry->registerHandler(GraphNavigatorInterface::DIRECTION_SERIALIZATION, \DateTime::class, 'xml', $callable); + $callable = [ + $handler, + 'serialize', + ]; + $registry->registerHandler(GraphNavigatorInterface::DIRECTION_SERIALIZATION, \DateTimeInterface::class, 'xml', $callable); + $registry->registerHandler(GraphNavigatorInterface::DIRECTION_SERIALIZATION, \DateTime::class, 'xml', $callable); - $callable = [ - $handler, - 'deserialize', - ]; - $registry->registerHandler(GraphNavigatorInterface::DIRECTION_DESERIALIZATION, \DateTimeInterface::class, 'xml', $callable); - $registry->registerHandler(GraphNavigatorInterface::DIRECTION_DESERIALIZATION, \DateTime::class, 'xml', $callable); - }) - ->setPropertyNamingStrategy( - new IdenticalPropertyNamingStrategy() - ) - ->build() - ; + $callable = [ + $handler, + 'deserialize', + ]; + $registry->registerHandler(GraphNavigatorInterface::DIRECTION_DESERIALIZATION, \DateTimeInterface::class, 'xml', $callable); + $registry->registerHandler(GraphNavigatorInterface::DIRECTION_DESERIALIZATION, \DateTime::class, 'xml', $callable); + }) + ->setPropertyNamingStrategy( + new IdenticalPropertyNamingStrategy() + ) + ->build() + ; - return new self($jmsSerializer); - } + return new self($jmsSerializer); + } - public function deserialize(string $xml): CXml - { - // remove doctype (if exists), as it would throw a JMS\Serializer\Exception\InvalidArgumentException - $xml = \preg_replace('//i', '', $xml); + public function deserialize(string $xml): CXml + { + // remove doctype (if exists), as it would throw a JMS\Serializer\Exception\InvalidArgumentException + $xml = \preg_replace('//i', '', $xml); - if (empty($xml)) { - throw new \RuntimeException('Cannot deserialize empty string'); - } + if (empty($xml)) { + throw new \RuntimeException('Cannot deserialize empty string'); + } - /* @phpstan-ignore-next-line */ - return $this->jmsSerializer->deserialize($xml, CXml::class, 'xml'); - } + /* @phpstan-ignore-next-line */ + return $this->jmsSerializer->deserialize($xml, CXml::class, 'xml'); + } - public function serialize(CXml $cxml, string $docTypeVersion = '1.2.054'): string - { - $xml = $this->jmsSerializer->serialize($cxml, 'xml'); + public function serialize(CXml $cxml, string $docTypeVersion = '1.2.054'): string + { + $xml = $this->jmsSerializer->serialize($cxml, 'xml'); - $docType = ''; - $xmlPrefix = ''; + $docType = ''; + $xmlPrefix = ''; - // add doctype, as it is mandatory in cXML - return \str_replace($xmlPrefix, $xmlPrefix.$docType, $xml); - } + // add doctype, as it is mandatory in cXML + return \str_replace($xmlPrefix, $xmlPrefix.$docType, $xml); + } } diff --git a/src/CXml/Validation/DtdValidator.php b/src/CXml/Validation/DtdValidator.php index d870176..0cf5f4e 100644 --- a/src/CXml/Validation/DtdValidator.php +++ b/src/CXml/Validation/DtdValidator.php @@ -7,80 +7,80 @@ class DtdValidator { - private string $pathToCxmlDtds; - - public function __construct(string $pathToCxmlDtds) - { - Assertion::directory($pathToCxmlDtds); - Assertion::file($pathToCxmlDtds.'/cXML.dtd'); - Assertion::file($pathToCxmlDtds.'/Fulfill.dtd'); - - $this->pathToCxmlDtds = $pathToCxmlDtds; - } - - /** - * @throws CXmlInvalidException - */ - public function validateAgainstDtd(string $xml): void - { - if (empty($xml)) { - throw new CXmlInvalidException('XML was empty', $xml); - } - - // disable throwing of php errors for libxml - $internalErrors = \libxml_use_internal_errors(true); - - $old = new \DOMDocument(); - $old->loadXML($xml); - - $validateFiles = ['cXML.dtd', 'Fulfill.dtd']; - - $this->validateAgainstMultipleDtd($validateFiles, $old); - - // reset throwing of php errors for libxml - \libxml_use_internal_errors($internalErrors); - } - - /** - * @throws CXmlInvalidException - */ - private function injectDtd(\DOMDocument $originalDomDocument, string $dtdFilename): \DOMDocument - { - $creator = new \DOMImplementation(); - - try { - $doctype = $creator->createDocumentType('cXML', '', $this->pathToCxmlDtds.'/'.$dtdFilename); - $new = $creator->createDocument('', '', $doctype); - } catch (\DOMException $e) { - throw new CXmlInvalidException($e->getMessage(), (string) $originalDomDocument->saveXML(), $e); - } - - $new->encoding = 'utf-8'; - - $oldNode = $originalDomDocument->getElementsByTagName('cXML')->item(0); - if (!$oldNode) { - throw new CXmlInvalidException('Missing cXML root node', (string) $originalDomDocument->saveXML()); - } - - $newNode = $new->importNode($oldNode, true); - $new->appendChild($newNode); - - return $new; - } - - /** - * @throws CXmlInvalidException - */ - private function validateAgainstMultipleDtd(array $validateFiles, \DOMDocument $old): void - { - foreach ($validateFiles as $validateFile) { - $dtdInjectedDomDocument = $this->injectDtd($old, $validateFile); - - if ($dtdInjectedDomDocument->validate()) { - return; - } - } - - throw CXmlInvalidException::fromLibXmlError(\libxml_get_last_error(), (string) $old->saveXML()); - } + private string $pathToCxmlDtds; + + public function __construct(string $pathToCxmlDtds) + { + Assertion::directory($pathToCxmlDtds); + Assertion::file($pathToCxmlDtds.'/cXML.dtd'); + Assertion::file($pathToCxmlDtds.'/Fulfill.dtd'); + + $this->pathToCxmlDtds = $pathToCxmlDtds; + } + + /** + * @throws CXmlInvalidException + */ + public function validateAgainstDtd(string $xml): void + { + if (empty($xml)) { + throw new CXmlInvalidException('XML was empty', $xml); + } + + // disable throwing of php errors for libxml + $internalErrors = \libxml_use_internal_errors(true); + + $old = new \DOMDocument(); + $old->loadXML($xml); + + $validateFiles = ['cXML.dtd', 'Fulfill.dtd']; + + $this->validateAgainstMultipleDtd($validateFiles, $old); + + // reset throwing of php errors for libxml + \libxml_use_internal_errors($internalErrors); + } + + /** + * @throws CXmlInvalidException + */ + private function injectDtd(\DOMDocument $originalDomDocument, string $dtdFilename): \DOMDocument + { + $creator = new \DOMImplementation(); + + try { + $doctype = $creator->createDocumentType('cXML', '', $this->pathToCxmlDtds.'/'.$dtdFilename); + $new = $creator->createDocument('', '', $doctype); + } catch (\DOMException $e) { + throw new CXmlInvalidException($e->getMessage(), (string) $originalDomDocument->saveXML(), $e); + } + + $new->encoding = 'utf-8'; + + $oldNode = $originalDomDocument->getElementsByTagName('cXML')->item(0); + if (!$oldNode) { + throw new CXmlInvalidException('Missing cXML root node', (string) $originalDomDocument->saveXML()); + } + + $newNode = $new->importNode($oldNode, true); + $new->appendChild($newNode); + + return $new; + } + + /** + * @throws CXmlInvalidException + */ + private function validateAgainstMultipleDtd(array $validateFiles, \DOMDocument $old): void + { + foreach ($validateFiles as $validateFile) { + $dtdInjectedDomDocument = $this->injectDtd($old, $validateFile); + + if ($dtdInjectedDomDocument->validate()) { + return; + } + } + + throw CXmlInvalidException::fromLibXmlError(\libxml_get_last_error(), (string) $old->saveXML()); + } } diff --git a/src/CXml/Validation/Exception/CXmlInvalidException.php b/src/CXml/Validation/Exception/CXmlInvalidException.php index d0c8ee5..be646f8 100644 --- a/src/CXml/Validation/Exception/CXmlInvalidException.php +++ b/src/CXml/Validation/Exception/CXmlInvalidException.php @@ -6,32 +6,32 @@ class CXmlInvalidException extends CXmlNotAcceptableException { - private string $xml; - - public function __construct(string $message, string $xml, \Throwable $previous = null) - { - parent::__construct($message, $previous); - - $this->xml = $xml; - } - - public function getXml(): string - { - return $this->xml; - } - - /** @phpstan-ignore-next-line */ - public static function fromLibXmlError($libXmlError, string $xml): self - { - if ($libXmlError instanceof \LibXMLError) { - $message = \sprintf('%s at line %d, column %d. Code %s.', \trim($libXmlError->message), $libXmlError->line, $libXmlError->column, $libXmlError->code); - } else { - $message = 'No LibXMLError was given.'; - } - - return new self( - $message, - $xml - ); - } + private string $xml; + + public function __construct(string $message, string $xml, \Throwable $previous = null) + { + parent::__construct($message, $previous); + + $this->xml = $xml; + } + + public function getXml(): string + { + return $this->xml; + } + + /** @phpstan-ignore-next-line */ + public static function fromLibXmlError($libXmlError, string $xml): self + { + if ($libXmlError instanceof \LibXMLError) { + $message = \sprintf('%s at line %d, column %d. Code %s.', \trim($libXmlError->message), $libXmlError->line, $libXmlError->column, $libXmlError->code); + } else { + $message = 'No LibXMLError was given.'; + } + + return new self( + $message, + $xml + ); + } } diff --git a/tests/CXmlTest/Builder/OrderRequestBuilderTest.php b/tests/CXmlTest/Builder/OrderRequestBuilderTest.php index 6aaccfa..a19a3fd 100644 --- a/tests/CXmlTest/Builder/OrderRequestBuilderTest.php +++ b/tests/CXmlTest/Builder/OrderRequestBuilderTest.php @@ -16,37 +16,37 @@ */ class OrderRequestBuilderTest extends TestCase implements PayloadIdentityFactoryInterface { - public function testFromPunchOutOrderMessage(): void - { - $serializer = Serializer::create(); - $poomXml = \file_get_contents(__DIR__.'/fixtures/poom.xml'); - $poom = $serializer->deserialize($poomXml); - - $orb = OrderRequestBuilder::fromPunchOutOrderMessage($poom->getMessage()->getPayload()); - $actualOrderRequest = $orb - ->billTo('name') - ->build() - ; - - $actualOrderRequest = Builder::create('cxml-php UserAgent', null, $this) - ->payload($actualOrderRequest) - ->from(new Credential('NetworkId', 'inbound@prominate-platform.com')) - ->to(new Credential('NetworkId', 'supplier@supplier.com')) - ->sender(new Credential('NetworkId', 'inbound@prominate-platform.com')) - ->build() - ; - $actualOrderRequest = $serializer->serialize($actualOrderRequest); - - $expectedOrderRequest = \file_get_contents(__DIR__.'/fixtures/order_request.xml'); - - $this->assertXmlStringEqualsXmlString($expectedOrderRequest, $actualOrderRequest); - } - - public function newPayloadIdentity(): PayloadIdentity - { - return new PayloadIdentity( - '933695160894', - new \DateTime('2021-01-08T23:00:06-08:00') - ); - } + public function testFromPunchOutOrderMessage(): void + { + $serializer = Serializer::create(); + $poomXml = \file_get_contents(__DIR__.'/fixtures/poom.xml'); + $poom = $serializer->deserialize($poomXml); + + $orb = OrderRequestBuilder::fromPunchOutOrderMessage($poom->getMessage()->getPayload()); + $actualOrderRequest = $orb + ->billTo('name') + ->build() + ; + + $actualOrderRequest = Builder::create('cxml-php UserAgent', null, $this) + ->payload($actualOrderRequest) + ->from(new Credential('NetworkId', 'inbound@prominate-platform.com')) + ->to(new Credential('NetworkId', 'supplier@supplier.com')) + ->sender(new Credential('NetworkId', 'inbound@prominate-platform.com')) + ->build() + ; + $actualOrderRequest = $serializer->serialize($actualOrderRequest); + + $expectedOrderRequest = \file_get_contents(__DIR__.'/fixtures/order_request.xml'); + + $this->assertXmlStringEqualsXmlString($expectedOrderRequest, $actualOrderRequest); + } + + public function newPayloadIdentity(): PayloadIdentity + { + return new PayloadIdentity( + '933695160894', + new \DateTime('2021-01-08T23:00:06-08:00') + ); + } } diff --git a/tests/CXmlTest/Model/OrderRequestTest.php b/tests/CXmlTest/Model/OrderRequestTest.php index fe12de5..38f65a5 100644 --- a/tests/CXmlTest/Model/OrderRequestTest.php +++ b/tests/CXmlTest/Model/OrderRequestTest.php @@ -31,130 +31,130 @@ */ class OrderRequestTest extends TestCase implements PayloadIdentityFactoryInterface { - public function testMinimumExample(): void - { - $from = new Credential( - 'NetworkId', - 'inbound@prominate-platform.com' - ); - $to = new Credential( - 'NetworkId', - 'supplier@supplier.com' - ); - $sender = new Credential( - 'NetworkId', - 'inbound@prominate-platform.com', - 'coyote' - ); + public function testMinimumExample(): void + { + $from = new Credential( + 'NetworkId', + 'inbound@prominate-platform.com' + ); + $to = new Credential( + 'NetworkId', + 'supplier@supplier.com' + ); + $sender = new Credential( + 'NetworkId', + 'inbound@prominate-platform.com', + 'coyote' + ); - $orderRequestHeader = OrderRequestHeader::create( - 'DO1234', - new \DateTime('2000-10-12T18:41:29-08:00'), - new ShipTo( - new Address( - new MultilanguageString('Acme'), - new PostalAddress( - [ - 'Joe Smith', - 'Mailstop M-543', - ], - [ - '123 Anystreet', - ], - 'Sunnyvale', - new Country('US', 'United States'), - null, - 'CA', - '90489', - 'default' - ) - ) - ), - new BillTo( - new Address( - new MultilanguageString('Zinc GmbH'), - new PostalAddress( - [], - [ - 'An den Eichen 18', - ], - 'Solingen', - new Country('DE', 'Deutschland'), - null, - null, - '42699', - 'default' - ) - ) - ), - new MoneyWrapper( - 'EUR', - 8500 - ), - [new Comment(null, null, null, 'delivery-note.pdf')] - ); + $orderRequestHeader = OrderRequestHeader::create( + 'DO1234', + new \DateTime('2000-10-12T18:41:29-08:00'), + new ShipTo( + new Address( + new MultilanguageString('Acme'), + new PostalAddress( + [ + 'Joe Smith', + 'Mailstop M-543', + ], + [ + '123 Anystreet', + ], + 'Sunnyvale', + new Country('US', 'United States'), + null, + 'CA', + '90489', + 'default' + ) + ) + ), + new BillTo( + new Address( + new MultilanguageString('Zinc GmbH'), + new PostalAddress( + [], + [ + 'An den Eichen 18', + ], + 'Solingen', + new Country('DE', 'Deutschland'), + null, + null, + '42699', + 'default' + ) + ) + ), + new MoneyWrapper( + 'EUR', + 8500 + ), + [new Comment(null, null, null, 'delivery-note.pdf')] + ); - $orderRequest = OrderRequest::create( - $orderRequestHeader - ); + $orderRequest = OrderRequest::create( + $orderRequestHeader + ); - $item = ItemOut::create( - 1, - 10, - new ItemId('1233244'), - ItemDetail::create( - new Description('hello from item 1'), - 'EA', - new MoneyWrapper( - 'EUR', - 210 - ), - [ - new Classification('custom', 0), - ] - ), - new \DateTime('2020-02-28') - ); - $orderRequest->addItem($item); + $item = ItemOut::create( + 1, + 10, + new ItemId('1233244'), + ItemDetail::create( + new Description('hello from item 1'), + 'EA', + new MoneyWrapper( + 'EUR', + 210 + ), + [ + new Classification('custom', 0), + ] + ), + new \DateTime('2020-02-28') + ); + $orderRequest->addItem($item); - $item = ItemOut::create( - 2, - 20, - new ItemId('1233245'), - ItemDetail::create( - new Description('hello from item 2'), - 'EA', - new MoneyWrapper( - 'EUR', - 320 - ), - [ - new Classification('custom', 0), - ] - ), - new \DateTime('2020-02-28') - ); - $orderRequest->addItem($item); + $item = ItemOut::create( + 2, + 20, + new ItemId('1233245'), + ItemDetail::create( + new Description('hello from item 2'), + 'EA', + new MoneyWrapper( + 'EUR', + 320 + ), + [ + new Classification('custom', 0), + ] + ), + new \DateTime('2020-02-28') + ); + $orderRequest->addItem($item); - $cxml = Builder::create('Platform Order Fulfillment Hub', null, $this) - ->from($from) - ->to($to) - ->sender($sender) - ->payload($orderRequest) - ->build(Request::DEPLOYMENT_TEST) - ; + $cxml = Builder::create('Platform Order Fulfillment Hub', null, $this) + ->from($from) + ->to($to) + ->sender($sender) + ->payload($orderRequest) + ->build(Request::DEPLOYMENT_TEST) + ; - $this->assertEquals('OrderRequest_1625586002.193314.7293@dev', (string) $cxml); + $this->assertEquals('OrderRequest_1625586002.193314.7293@dev', (string) $cxml); - $xml = Serializer::create()->serialize($cxml); - $this->assertXmlStringEqualsXmlFile('tests/metadata/cxml/samples/OrderRequest.xml', $xml); - } + $xml = Serializer::create()->serialize($cxml); + $this->assertXmlStringEqualsXmlFile('tests/metadata/cxml/samples/OrderRequest.xml', $xml); + } - public function newPayloadIdentity(): PayloadIdentity - { - return new PayloadIdentity( - '1625586002.193314.7293@dev', - new \DateTime('2000-10-12T18:39:09-08:00') - ); - } + public function newPayloadIdentity(): PayloadIdentity + { + return new PayloadIdentity( + '1625586002.193314.7293@dev', + new \DateTime('2000-10-12T18:39:09-08:00') + ); + } } diff --git a/tests/CXmlTest/Model/ProductActivityMessageTest.php b/tests/CXmlTest/Model/ProductActivityMessageTest.php index 0601146..71d537c 100644 --- a/tests/CXmlTest/Model/ProductActivityMessageTest.php +++ b/tests/CXmlTest/Model/ProductActivityMessageTest.php @@ -22,54 +22,54 @@ */ class ProductActivityMessageTest extends TestCase implements PayloadIdentityFactoryInterface { - public function testMinimumExample(): void - { - $from = new Credential( - 'NetworkId', - 'AN00000123' - ); - $to = new Credential( - 'NetworkId', - 'AN00000456' - ); - $sender = new Credential( - 'NetworkId', - 'AN00000123', - 'abracadabra' - ); + public function testMinimumExample(): void + { + $from = new Credential( + 'NetworkId', + 'AN00000123' + ); + $to = new Credential( + 'NetworkId', + 'AN00000456' + ); + $sender = new Credential( + 'NetworkId', + 'AN00000123', + 'abracadabra' + ); - $productActivityMessage = ProductActivityMessage::create( - 'CP12465192-1552965424130', - 'SMI', - new \DateTime('2019-02-20T14:39:48-08:00') - )->addProductActivityDetail( - ProductActivityDetail::create( - new ItemId('SII99825', null, 'II99825'), - Inventory::create()->setStockOnHandQuantity(new InventoryQuantity(200, 'EA')), - Contact::create(new MultilanguageString('Warehouse', null, 'en'), 'locationFrom') - ->addIdReference('NetworkId', '0003') - ) - ); + $productActivityMessage = ProductActivityMessage::create( + 'CP12465192-1552965424130', + 'SMI', + new \DateTime('2019-02-20T14:39:48-08:00') + )->addProductActivityDetail( + ProductActivityDetail::create( + new ItemId('SII99825', null, 'II99825'), + Inventory::create()->setStockOnHandQuantity(new InventoryQuantity(200, 'EA')), + Contact::create(new MultilanguageString('Warehouse', null, 'en'), 'locationFrom') + ->addIdReference('NetworkId', '0003') + ) + ); - $cxml = Builder::create('Supplier’s Super Order Processor', 'en-US', $this) - ->from($from) - ->to($to) - ->sender($sender) - ->payload($productActivityMessage) - ->build() - ; + $cxml = Builder::create('Supplier’s Super Order Processor', 'en-US', $this) + ->from($from) + ->to($to) + ->sender($sender) + ->payload($productActivityMessage) + ->build() + ; - $this->assertEquals('ProductActivityMessage_0c30050@supplierorg.com', (string) $cxml); + $this->assertEquals('ProductActivityMessage_0c30050@supplierorg.com', (string) $cxml); - $xml = Serializer::create()->serialize($cxml); - $this->assertXmlStringEqualsXmlFile('tests/metadata/cxml/samples/ProductActivityMessage.xml', $xml); - } + $xml = Serializer::create()->serialize($cxml); + $this->assertXmlStringEqualsXmlFile('tests/metadata/cxml/samples/ProductActivityMessage.xml', $xml); + } - public function newPayloadIdentity(): PayloadIdentity - { - return new PayloadIdentity( - '0c30050@supplierorg.com', - new \DateTime('2021-01-08T23:00:06-08:00') - ); - } + public function newPayloadIdentity(): PayloadIdentity + { + return new PayloadIdentity( + '0c30050@supplierorg.com', + new \DateTime('2021-01-08T23:00:06-08:00') + ); + } } diff --git a/tests/CXmlTest/Model/PunchOutSetupRequestTest.php b/tests/CXmlTest/Model/PunchOutSetupRequestTest.php index 98690ec..40bc8ce 100644 --- a/tests/CXmlTest/Model/PunchOutSetupRequestTest.php +++ b/tests/CXmlTest/Model/PunchOutSetupRequestTest.php @@ -31,114 +31,114 @@ */ class PunchOutSetupRequestTest extends TestCase implements PayloadIdentityFactoryInterface { - private DtdValidator $dtdValidator; + private DtdValidator $dtdValidator; - protected function setUp(): void - { - $this->dtdValidator = new DtdValidator(__DIR__.'/../../metadata/cxml/dtd/1.2.053/'); - } + protected function setUp(): void + { + $this->dtdValidator = new DtdValidator(__DIR__.'/../../metadata/cxml/dtd/1.2.053/'); + } - public function testMinimumExample(): void - { - $from = new Credential( - 'NetworkId', - 'inbound@prominate-platform.com' - ); - $to = new Credential( - 'NetworkId', - 'supplier@supplier.com' - ); - $sender = new Credential( - 'NetworkId', - 'inbound@prominate-platform.com', - 's3cr3t' - ); + public function testMinimumExample(): void + { + $from = new Credential( + 'NetworkId', + 'inbound@prominate-platform.com' + ); + $to = new Credential( + 'NetworkId', + 'supplier@supplier.com' + ); + $sender = new Credential( + 'NetworkId', + 'inbound@prominate-platform.com', + 's3cr3t' + ); - $punchoutSetupRequest = (new PunchOutSetupRequest( - '550bce3e592023b2e7b015307f965133', - 'https://prominate-platform.com/hook-url', - 'http://workchairs.com/cxml', - new ShipTo( - new Address( - new MultilanguageString('Acme'), - new PostalAddress( - [ - 'Joe Smith', - 'Mailstop M-543', - ], - [ - '123 Anystreet', - ], - 'Sunnyvale', - new Country('US', 'United States'), - null, - 'CA', - '90489', - 'default' - ) - ) - ), - new SelectedItem( - new ItemId('4545321', null, 'II99825') - ), - ))->addItem( - ItemOut::create( - 10, - 2, - new ItemId('5555'), - ItemDetail::create( - Description::createWithShortName('Excelsior Desk Chair', null, 'en'), - 'EA', - new MoneyWrapper('EUR', 76320), - [ - new Classification('UNSPSC', 'ean1234'), - ] - ), - new \DateTime('2023-01-23T16:00:06-01:00'), - ) - )->addItem( - ItemOut::create( - 20, - 1, - new ItemId('6666'), - ItemDetail::create( - Description::createWithShortName('22Excelsior Desk Chair', null, 'en'), - 'EA', - new MoneyWrapper('EUR', 76420), - [ - new Classification('UNSPSC', 'ean1230'), - ] - ), - new \DateTime('2023-01-23T16:00:06-01:00'), - ) - ); + $punchoutSetupRequest = (new PunchOutSetupRequest( + '550bce3e592023b2e7b015307f965133', + 'https://prominate-platform.com/hook-url', + 'http://workchairs.com/cxml', + new ShipTo( + new Address( + new MultilanguageString('Acme'), + new PostalAddress( + [ + 'Joe Smith', + 'Mailstop M-543', + ], + [ + '123 Anystreet', + ], + 'Sunnyvale', + new Country('US', 'United States'), + null, + 'CA', + '90489', + 'default' + ) + ) + ), + new SelectedItem( + new ItemId('4545321', null, 'II99825') + ), + ))->addItem( + ItemOut::create( + 10, + 2, + new ItemId('5555'), + ItemDetail::create( + Description::createWithShortName('Excelsior Desk Chair', null, 'en'), + 'EA', + new MoneyWrapper('EUR', 76320), + [ + new Classification('UNSPSC', 'ean1234'), + ] + ), + new \DateTime('2023-01-23T16:00:06-01:00'), + ) + )->addItem( + ItemOut::create( + 20, + 1, + new ItemId('6666'), + ItemDetail::create( + Description::createWithShortName('22Excelsior Desk Chair', null, 'en'), + 'EA', + new MoneyWrapper('EUR', 76420), + [ + new Classification('UNSPSC', 'ean1230'), + ] + ), + new \DateTime('2023-01-23T16:00:06-01:00'), + ) + ); - $punchoutSetupRequest->addExtrinsic( - new Extrinsic('UserEmail', 'john-doe@domain.com') - ); + $punchoutSetupRequest->addExtrinsic( + new Extrinsic('UserEmail', 'john-doe@domain.com') + ); - $cxml = Builder::create('Workchairs cXML Application', 'en-US', $this) - ->from($from) - ->to($to) - ->sender($sender) - ->payload($punchoutSetupRequest) - ->build('test') - ; + $cxml = Builder::create('Workchairs cXML Application', 'en-US', $this) + ->from($from) + ->to($to) + ->sender($sender) + ->payload($punchoutSetupRequest) + ->build('test') + ; - $this->assertEquals('PunchOutSetupRequest_933695160890', (string) $cxml); + $this->assertEquals('PunchOutSetupRequest_933695160890', (string) $cxml); - $xml = Serializer::create()->serialize($cxml); + $xml = Serializer::create()->serialize($cxml); - $this->dtdValidator->validateAgainstDtd($xml); + $this->dtdValidator->validateAgainstDtd($xml); - $this->assertXmlStringEqualsXmlFile(__DIR__.'/../../metadata/cxml/samples/PunchOutSetupRequest.xml', $xml); - } + $this->assertXmlStringEqualsXmlFile(__DIR__.'/../../metadata/cxml/samples/PunchOutSetupRequest.xml', $xml); + } - public function newPayloadIdentity(): PayloadIdentity - { - return new PayloadIdentity( - '933695160890', - new \DateTime('2023-01-23T16:00:06-01:00') - ); - } + public function newPayloadIdentity(): PayloadIdentity + { + return new PayloadIdentity( + '933695160890', + new \DateTime('2023-01-23T16:00:06-01:00') + ); + } } diff --git a/tests/CXmlTest/Model/PunchoutOrderMessageTest.php b/tests/CXmlTest/Model/PunchoutOrderMessageTest.php index 8cac1d7..8e7304c 100644 --- a/tests/CXmlTest/Model/PunchoutOrderMessageTest.php +++ b/tests/CXmlTest/Model/PunchoutOrderMessageTest.php @@ -24,80 +24,80 @@ */ class PunchoutOrderMessageTest extends TestCase implements PayloadIdentityFactoryInterface { - private DtdValidator $dtdValidator; + private DtdValidator $dtdValidator; - protected function setUp(): void - { - $this->dtdValidator = new DtdValidator(__DIR__.'/../../metadata/cxml/dtd/1.2.053/'); - } + protected function setUp(): void + { + $this->dtdValidator = new DtdValidator(__DIR__.'/../../metadata/cxml/dtd/1.2.053/'); + } - public function testMinimumExample(): void - { - $from = new Credential( - 'DUNS', - '83528721', - ); - $to = new Credential( - 'DUNS', - '65652314', - ); - $sender = new Credential( - 'workchairs.com', - 'website 1', - ); + public function testMinimumExample(): void + { + $from = new Credential( + 'DUNS', + '83528721', + ); + $to = new Credential( + 'DUNS', + '65652314', + ); + $sender = new Credential( + 'workchairs.com', + 'website 1', + ); - $punchoutOrderMessage = PunchOutOrderMessage::create( - '1CX3L4843PPZO', - new PunchOutOrderMessageHeader(new MoneyWrapper('USD', 76320)), - )->addPunchoutOrderMessageItem( - ItemIn::create( - 3, - new ItemId('5555', null, 'KD5555'), - ItemDetail::create( - Description::createWithShortName('Excelsior Desk Chair', null, 'en'), - 'EA', - new MoneyWrapper('USD', 76320), - [ - new Classification('UNSPSC', 'ean1234'), - ] - ) - ) - )->addPunchoutOrderMessageItem( - ItemIn::create( - 5, - new ItemId('666', null, 'KD666'), - ItemDetail::create( - Description::createWithShortName('22Excelsior Desk Chair', null, 'en'), - 'EA', - new MoneyWrapper('USD', 76320), - [ - new Classification('UNSPSC', 'ean1234'), - ] - ) - ) - ); + $punchoutOrderMessage = PunchOutOrderMessage::create( + '1CX3L4843PPZO', + new PunchOutOrderMessageHeader(new MoneyWrapper('USD', 76320)), + )->addPunchoutOrderMessageItem( + ItemIn::create( + 3, + new ItemId('5555', null, 'KD5555'), + ItemDetail::create( + Description::createWithShortName('Excelsior Desk Chair', null, 'en'), + 'EA', + new MoneyWrapper('USD', 76320), + [ + new Classification('UNSPSC', 'ean1234'), + ] + ) + ) + )->addPunchoutOrderMessageItem( + ItemIn::create( + 5, + new ItemId('666', null, 'KD666'), + ItemDetail::create( + Description::createWithShortName('22Excelsior Desk Chair', null, 'en'), + 'EA', + new MoneyWrapper('USD', 76320), + [ + new Classification('UNSPSC', 'ean1234'), + ] + ) + ) + ); - $cxml = Builder::create('Workchairs cXML Application', 'en-US', $this) - ->from($from) - ->to($to) - ->sender($sender) - ->payload($punchoutOrderMessage) - ->build() - ; + $cxml = Builder::create('Workchairs cXML Application', 'en-US', $this) + ->from($from) + ->to($to) + ->sender($sender) + ->payload($punchoutOrderMessage) + ->build() + ; - $this->assertEquals('PunchOutOrderMessage_933695160894', (string) $cxml); + $this->assertEquals('PunchOutOrderMessage_933695160894', (string) $cxml); - $xml = Serializer::create()->serialize($cxml); - $this->dtdValidator->validateAgainstDtd($xml); + $xml = Serializer::create()->serialize($cxml); + $this->dtdValidator->validateAgainstDtd($xml); - $this->assertXmlStringEqualsXmlFile('tests/metadata/cxml/samples/PunchoutOrderMessage.xml', $xml); - } + $this->assertXmlStringEqualsXmlFile('tests/metadata/cxml/samples/PunchoutOrderMessage.xml', $xml); + } - public function newPayloadIdentity(): PayloadIdentity - { - return new PayloadIdentity( - '933695160894', - new \DateTime('2021-01-08T23:00:06-08:00') - ); - } + public function newPayloadIdentity(): PayloadIdentity + { + return new PayloadIdentity( + '933695160894', + new \DateTime('2021-01-08T23:00:06-08:00') + ); + } } diff --git a/tests/CXmlTest/Model/SerializerTest.php b/tests/CXmlTest/Model/SerializerTest.php index 8126e51..e6fa413 100644 --- a/tests/CXmlTest/Model/SerializerTest.php +++ b/tests/CXmlTest/Model/SerializerTest.php @@ -27,43 +27,43 @@ */ class SerializerTest extends TestCase { - public function testSerializeSimpleRequest(): void - { - $from = new Party( - new Credential('AribaNetworkUserId', 'admin@acme.com') - ); - $to = new Party( - new Credential('DUNS', '012345678') - ); - $sender = new Party( - new Credential('AribaNetworkUserId', 'sysadmin@buyer.com', 'abracadabra'), - 'Network Hub 1.1' - ); - $request = new Request( - new PunchOutSetupRequest( - 'nomnom', - 'https://browserFormPost', - 'https://supplierSetup' - ) - ); - - $header = new Header( - $from, - $to, - $sender - ); - - $msg = CXml::forRequest( - new PayloadIdentity('payload-id', new \DateTime('2000-01-01')), - $request, - $header - ); - - $actualXml = Serializer::create()->serialize($msg); - - // XML copied from cXML Reference Guide - $expectedXml = - ' + public function testSerializeSimpleRequest(): void + { + $from = new Party( + new Credential('AribaNetworkUserId', 'admin@acme.com') + ); + $to = new Party( + new Credential('DUNS', '012345678') + ); + $sender = new Party( + new Credential('AribaNetworkUserId', 'sysadmin@buyer.com', 'abracadabra'), + 'Network Hub 1.1' + ); + $request = new Request( + new PunchOutSetupRequest( + 'nomnom', + 'https://browserFormPost', + 'https://supplierSetup' + ) + ); + + $header = new Header( + $from, + $to, + $sender + ); + + $msg = CXml::forRequest( + new PayloadIdentity('payload-id', new \DateTime('2000-01-01')), + $request, + $header + ); + + $actualXml = Serializer::create()->serialize($msg); + + // XML copied from cXML Reference Guide + $expectedXml = + '
@@ -97,45 +97,45 @@ public function testSerializeSimpleRequest(): void '; - $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); - } - - public function testSerializeSimpleMessage(): void - { - $from = new Party( - new Credential('AribaNetworkUserId', 'admin@acme.com') - ); - $to = new Party( - new Credential('DUNS', '012345678') - ); - $sender = new Party( - new Credential('AribaNetworkUserId', 'sysadmin@buyer.com', 'abracadabra'), - 'Network Hub 1.1' - ); - $message = new Message( - PunchOutOrderMessage::create( - '34234234ADFSDF234234', - new PunchOutOrderMessageHeader(new MoneyWrapper('USD', 76320)) - ) - ); - - $header = new Header( - $from, - $to, - $sender - ); - - $msg = CXml::forMessage( - new PayloadIdentity('payload-id', new \DateTime('2000-01-01')), - $message, - $header - ); - - $actualXml = Serializer::create()->serialize($msg); - - // XML *NOT* copied from cXML Reference Guide - $expectedXml = - ' + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); + } + + public function testSerializeSimpleMessage(): void + { + $from = new Party( + new Credential('AribaNetworkUserId', 'admin@acme.com') + ); + $to = new Party( + new Credential('DUNS', '012345678') + ); + $sender = new Party( + new Credential('AribaNetworkUserId', 'sysadmin@buyer.com', 'abracadabra'), + 'Network Hub 1.1' + ); + $message = new Message( + PunchOutOrderMessage::create( + '34234234ADFSDF234234', + new PunchOutOrderMessageHeader(new MoneyWrapper('USD', 76320)) + ) + ); + + $header = new Header( + $from, + $to, + $sender + ); + + $msg = CXml::forMessage( + new PayloadIdentity('payload-id', new \DateTime('2000-01-01')), + $message, + $header + ); + + $actualXml = Serializer::create()->serialize($msg); + + // XML *NOT* copied from cXML Reference Guide + $expectedXml = + '
@@ -168,87 +168,87 @@ public function testSerializeSimpleMessage(): void '; - $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); - } - - public function testSerializeSimpleResponse(): void - { - $msg = CXml::forResponse( - new PayloadIdentity( - '978979621537--4882920031100014936@206.251.25.169', - new \DateTime('2001-01-08T10:47:01-08:00') - ), - new Response( - new Status(200, 'OK', 'Ping Response CXml'), - null - ) - ); - - $actualXml = Serializer::create()->serialize($msg); - - // XML copied from cXML Reference Guide - $expectedXml = - ' + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); + } + + public function testSerializeSimpleResponse(): void + { + $msg = CXml::forResponse( + new PayloadIdentity( + '978979621537--4882920031100014936@206.251.25.169', + new \DateTime('2001-01-08T10:47:01-08:00') + ), + new Response( + new Status(200, 'OK', 'Ping Response CXml'), + null + ) + ); + + $actualXml = Serializer::create()->serialize($msg); + + // XML copied from cXML Reference Guide + $expectedXml = + ' Ping Response CXml '; - $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); - } + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); + } - public function testDeserialize(): void - { - $xml = - ' + public function testDeserialize(): void + { + $xml = + ' Ping Response CXml '; - $serializer = Serializer::create(); - $cXml = $serializer->deserialize($xml); + $serializer = Serializer::create(); + $cXml = $serializer->deserialize($xml); - $resultingXml = $serializer->serialize($cXml); + $resultingXml = $serializer->serialize($cXml); - $this->assertXmlStringEqualsXmlString($xml, $resultingXml); - } + $this->assertXmlStringEqualsXmlString($xml, $resultingXml); + } - /** - * even though the cXML definition defines the timestamp value to be in ISO-8601 format there are some providers that - * also uses the milliseconds value (i.e. JAGGAER). - */ - public function testDeserializeWithMilliseconds(): void - { - $xmlIn = - ' + /** + * even though the cXML definition defines the timestamp value to be in ISO-8601 format there are some providers that + * also uses the milliseconds value (i.e. JAGGAER). + */ + public function testDeserializeWithMilliseconds(): void + { + $xmlIn = + ' Ping Response CXml '; - $serializer = Serializer::create(); - $cXml = $serializer->deserialize($xmlIn); + $serializer = Serializer::create(); + $cXml = $serializer->deserialize($xmlIn); - $actual = $serializer->serialize($cXml); + $actual = $serializer->serialize($cXml); - $xmlOut = - ' + $xmlOut = + ' Ping Response CXml '; - $this->assertXmlStringEqualsXmlString($xmlOut, $actual); - } + $this->assertXmlStringEqualsXmlString($xmlOut, $actual); + } - public function testDeserializeWithDateTimeForDate(): void - { - $xmlIn = - ' + public function testDeserializeWithDateTimeForDate(): void + { + $xmlIn = + '
@@ -265,27 +265,27 @@ public function testDeserializeWithDateTimeForDate(): void '; - $serializer = Serializer::create(); - $cXml = $serializer->deserialize($xmlIn); + $serializer = Serializer::create(); + $cXml = $serializer->deserialize($xmlIn); - /** @var OrderRequest $orderRequest */ - $orderRequest = $cXml->getRequest()->getPayload(); + /** @var OrderRequest $orderRequest */ + $orderRequest = $cXml->getRequest()->getPayload(); - $this->assertEquals('2023-02-25 02:30:00', $orderRequest->getItems()[0]->getRequestedDeliveryDate()->format('Y-m-d H:i:s')); - $this->assertInstanceOf(\DateTime::class, $orderRequest->getItems()[0]->getRequestedDeliveryDate()); + $this->assertEquals('2023-02-25 02:30:00', $orderRequest->getItems()[0]->getRequestedDeliveryDate()->format('Y-m-d H:i:s')); + $this->assertInstanceOf(\DateTime::class, $orderRequest->getItems()[0]->getRequestedDeliveryDate()); - $this->assertEquals('2023-02-26', $orderRequest->getItems()[1]->getRequestedDeliveryDate()->format('Y-m-d')); - $this->assertInstanceOf(Date::class, $orderRequest->getItems()[1]->getRequestedDeliveryDate()); + $this->assertEquals('2023-02-26', $orderRequest->getItems()[1]->getRequestedDeliveryDate()->format('Y-m-d')); + $this->assertInstanceOf(Date::class, $orderRequest->getItems()[1]->getRequestedDeliveryDate()); - $this->assertNull($orderRequest->getItems()[2]->getRequestedDeliveryDate()); - } + $this->assertNull($orderRequest->getItems()[2]->getRequestedDeliveryDate()); + } - public function testDeserializeInvalidDate(): void - { - $this->expectException(\RuntimeException::class); + public function testDeserializeInvalidDate(): void + { + $this->expectException(\RuntimeException::class); - $xmlIn = - ' + $xmlIn = + '
@@ -298,49 +298,49 @@ public function testDeserializeInvalidDate(): void '; - $serializer = Serializer::create(); - $serializer->deserialize($xmlIn); - } - - public function testSerializeDateOnly(): void - { - $from = new Party( - new Credential('AribaNetworkUserId', 'admin@acme.com') - ); - $to = new Party( - new Credential('DUNS', '012345678') - ); - $sender = new Party( - new Credential('AribaNetworkUserId', 'sysadmin@buyer.com', 'abracadabra'), - 'Network Hub 1.1' - ); - - $orderDate = new Date('2000-01-01'); - - $orderRequest = - OrderRequestBuilder::create('order-id', $orderDate, 'EUR') - ->billTo('name') - ->build() - ; - - $header = new Header( - $from, - $to, - $sender - ); - - $msg = CXml::forRequest( - new PayloadIdentity('payload-id', new \DateTime('2000-01-01')), - new Request( - $orderRequest - ), - $header - ); - - $actualXml = Serializer::create()->serialize($msg); - - $expectedXml = - ' + $serializer = Serializer::create(); + $serializer->deserialize($xmlIn); + } + + public function testSerializeDateOnly(): void + { + $from = new Party( + new Credential('AribaNetworkUserId', 'admin@acme.com') + ); + $to = new Party( + new Credential('DUNS', '012345678') + ); + $sender = new Party( + new Credential('AribaNetworkUserId', 'sysadmin@buyer.com', 'abracadabra'), + 'Network Hub 1.1' + ); + + $orderDate = new Date('2000-01-01'); + + $orderRequest = + OrderRequestBuilder::create('order-id', $orderDate, 'EUR') + ->billTo('name') + ->build() + ; + + $header = new Header( + $from, + $to, + $sender + ); + + $msg = CXml::forRequest( + new PayloadIdentity('payload-id', new \DateTime('2000-01-01')), + new Request( + $orderRequest + ), + $header + ); + + $actualXml = Serializer::create()->serialize($msg); + + $expectedXml = + '
@@ -377,6 +377,6 @@ public function testSerializeDateOnly(): void '; - $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); - } + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); + } } diff --git a/tests/CXmlTest/Model/ShipNoticeRequestTest.php b/tests/CXmlTest/Model/ShipNoticeRequestTest.php index 830a9bf..1eeba99 100644 --- a/tests/CXmlTest/Model/ShipNoticeRequestTest.php +++ b/tests/CXmlTest/Model/ShipNoticeRequestTest.php @@ -21,59 +21,59 @@ */ class ShipNoticeRequestTest extends TestCase implements PayloadIdentityFactoryInterface { - public function testMinimumExample(): void - { - $from = new Credential( - 'NetworkId', - 'AN00000123' - ); - $to = new Credential( - 'NetworkId', - 'AN00000456' - ); - $sender = new Credential( - 'NetworkId', - 'AN00000123', - 'abracadabra' - ); + public function testMinimumExample(): void + { + $from = new Credential( + 'NetworkId', + 'AN00000123' + ); + $to = new Credential( + 'NetworkId', + 'AN00000456' + ); + $sender = new Credential( + 'NetworkId', + 'AN00000123', + 'abracadabra' + ); - $statusUpdateRequest = ShipNoticeRequest::create( - ShipNoticeHeader::create( - 'S2-123', - new \DateTime('2000-10-14T18:39:09-08:00'), - new \DateTime('2000-10-14T08:30:19-08:00'), - new \DateTime('2000-10-18T09:00:00-08:00'), - ) - ->addComment('Got it all into one shipment.', null, 'en-CA') - ) - ->addShipControl( - ShipControl::create(CarrierIdentifier::fromScacCode('FDE'), new ShipmentIdentifier('8202 8261 1194')) - ->addCarrierIdentifier('companyName', 'Federal Express') - ) - ->addShipNoticePortion( - new ShipNoticePortion('32232995@hub.acme.com', 'DO1234') - ) - ; + $statusUpdateRequest = ShipNoticeRequest::create( + ShipNoticeHeader::create( + 'S2-123', + new \DateTime('2000-10-14T18:39:09-08:00'), + new \DateTime('2000-10-14T08:30:19-08:00'), + new \DateTime('2000-10-18T09:00:00-08:00'), + ) + ->addComment('Got it all into one shipment.', null, 'en-CA') + ) + ->addShipControl( + ShipControl::create(CarrierIdentifier::fromScacCode('FDE'), new ShipmentIdentifier('8202 8261 1194')) + ->addCarrierIdentifier('companyName', 'Federal Express') + ) + ->addShipNoticePortion( + new ShipNoticePortion('32232995@hub.acme.com', 'DO1234') + ) + ; - $cxml = Builder::create('Supplier’s Super Order Processor', 'en-US', $this) - ->from($from) - ->to($to) - ->sender($sender) - ->payload($statusUpdateRequest) - ->build() - ; + $cxml = Builder::create('Supplier’s Super Order Processor', 'en-US', $this) + ->from($from) + ->to($to) + ->sender($sender) + ->payload($statusUpdateRequest) + ->build() + ; - $this->assertEquals('ShipNoticeRequest_0c30050@supplierorg.com', (string) $cxml); + $this->assertEquals('ShipNoticeRequest_0c30050@supplierorg.com', (string) $cxml); - $xml = Serializer::create()->serialize($cxml); - $this->assertXmlStringEqualsXmlFile('tests/metadata/cxml/samples/ShipNoticeRequest.xml', $xml); - } + $xml = Serializer::create()->serialize($cxml); + $this->assertXmlStringEqualsXmlFile('tests/metadata/cxml/samples/ShipNoticeRequest.xml', $xml); + } - public function newPayloadIdentity(): PayloadIdentity - { - return new PayloadIdentity( - '0c30050@supplierorg.com', - new \DateTime('2021-01-08T23:00:06-08:00') - ); - } + public function newPayloadIdentity(): PayloadIdentity + { + return new PayloadIdentity( + '0c30050@supplierorg.com', + new \DateTime('2021-01-08T23:00:06-08:00') + ); + } } diff --git a/tests/CXmlTest/Model/StatusUpdateRequestTest.php b/tests/CXmlTest/Model/StatusUpdateRequestTest.php index aa8cffa..7c5c13e 100644 --- a/tests/CXmlTest/Model/StatusUpdateRequestTest.php +++ b/tests/CXmlTest/Model/StatusUpdateRequestTest.php @@ -17,46 +17,46 @@ */ class StatusUpdateRequestTest extends TestCase implements PayloadIdentityFactoryInterface { - public function testMinimumExample(): void - { - $from = new Credential( - 'NetworkId', - 'AN00000123' - ); - $to = new Credential( - 'NetworkId', - 'AN00000456' - ); - $sender = new Credential( - 'NetworkId', - 'AN00000123', - 'abracadabra' - ); - - $statusUpdateRequest = new StatusUpdateRequest( - new Status(200, 'OK', 'Forwarded to supplier', 'en-US'), - '0c300508b7863dcclb_14999' - ); - - $cxml = Builder::create('Supplier’s Super Order Processor', 'en-US', $this) - ->from($from) - ->to($to) - ->sender($sender) - ->payload($statusUpdateRequest) - ->build() - ; - - $this->assertEquals('StatusUpdateRequest_0c30050@supplierorg.com', (string) $cxml); - - $xml = Serializer::create()->serialize($cxml); - $this->assertXmlStringEqualsXmlFile('tests/metadata/cxml/samples/StatusUpdateRequest.xml', $xml); - } - - public function newPayloadIdentity(): PayloadIdentity - { - return new PayloadIdentity( - '0c30050@supplierorg.com', - new \DateTime('2021-01-08T23:00:06-08:00') - ); - } + public function testMinimumExample(): void + { + $from = new Credential( + 'NetworkId', + 'AN00000123' + ); + $to = new Credential( + 'NetworkId', + 'AN00000456' + ); + $sender = new Credential( + 'NetworkId', + 'AN00000123', + 'abracadabra' + ); + + $statusUpdateRequest = new StatusUpdateRequest( + new Status(200, 'OK', 'Forwarded to supplier', 'en-US'), + '0c300508b7863dcclb_14999' + ); + + $cxml = Builder::create('Supplier’s Super Order Processor', 'en-US', $this) + ->from($from) + ->to($to) + ->sender($sender) + ->payload($statusUpdateRequest) + ->build() + ; + + $this->assertEquals('StatusUpdateRequest_0c30050@supplierorg.com', (string) $cxml); + + $xml = Serializer::create()->serialize($cxml); + $this->assertXmlStringEqualsXmlFile('tests/metadata/cxml/samples/StatusUpdateRequest.xml', $xml); + } + + public function newPayloadIdentity(): PayloadIdentity + { + return new PayloadIdentity( + '0c30050@supplierorg.com', + new \DateTime('2021-01-08T23:00:06-08:00') + ); + } } diff --git a/tests/CXmlTest/Payload/DefaultPayloadIdentityFactoryTest.php b/tests/CXmlTest/Payload/DefaultPayloadIdentityFactoryTest.php index 9c7f6c6..1de4b80 100644 --- a/tests/CXmlTest/Payload/DefaultPayloadIdentityFactoryTest.php +++ b/tests/CXmlTest/Payload/DefaultPayloadIdentityFactoryTest.php @@ -11,14 +11,14 @@ */ class DefaultPayloadIdentityFactoryTest extends TestCase { - public function testGenerateNewPayloadId(): void - { - $pif = new DefaultPayloadIdentityFactory(function () { - // 2022-04-22 08:00:00.400000 +00:00 - return \DateTime::createFromFormat('U.v', '1650614400.400'); - }); - $actualIdentity = $pif->newPayloadIdentity(); + public function testGenerateNewPayloadId(): void + { + $pif = new DefaultPayloadIdentityFactory(function () { + // 2022-04-22 08:00:00.400000 +00:00 + return \DateTime::createFromFormat('U.v', '1650614400.400'); + }); + $actualIdentity = $pif->newPayloadIdentity(); - $this->assertStringStartsWith('1650614400.400', $actualIdentity->getPayloadId()); - } + $this->assertStringStartsWith('1650614400.400', $actualIdentity->getPayloadId()); + } } diff --git a/tests/CXmlTest/Validation/MessageValidatorTest.php b/tests/CXmlTest/Validation/MessageValidatorTest.php index 55a9b96..571b830 100644 --- a/tests/CXmlTest/Validation/MessageValidatorTest.php +++ b/tests/CXmlTest/Validation/MessageValidatorTest.php @@ -12,34 +12,34 @@ */ class MessageValidatorTest extends TestCase { - private DtdValidator $dtdValidator; + private DtdValidator $dtdValidator; - protected function setUp(): void - { - $this->dtdValidator = new DtdValidator(__DIR__.'/../../metadata/cxml/dtd/1.2.053'); - } + protected function setUp(): void + { + $this->dtdValidator = new DtdValidator(__DIR__.'/../../metadata/cxml/dtd/1.2.053'); + } - public function testValidateSuccess(): void - { - $this->expectNotToPerformAssertions(); + public function testValidateSuccess(): void + { + $this->expectNotToPerformAssertions(); - $xml = \file_get_contents('tests/metadata/cxml/samples/simple-profile-request.xml'); - $this->dtdValidator->validateAgainstDtd($xml); - } + $xml = \file_get_contents('tests/metadata/cxml/samples/simple-profile-request.xml'); + $this->dtdValidator->validateAgainstDtd($xml); + } - public function testValidateMissingRootNode(): void - { - $this->expectException(CXmlInvalidException::class); + public function testValidateMissingRootNode(): void + { + $this->expectException(CXmlInvalidException::class); - $xml = ''; - $this->dtdValidator->validateAgainstDtd($xml); - } + $xml = ''; + $this->dtdValidator->validateAgainstDtd($xml); + } - public function testValidateInvalid(): void - { - $this->expectException(CXmlInvalidException::class); + public function testValidateInvalid(): void + { + $this->expectException(CXmlInvalidException::class); - $xml = ''; - $this->dtdValidator->validateAgainstDtd($xml); - } + $xml = ''; + $this->dtdValidator->validateAgainstDtd($xml); + } }