diff --git a/src/Messages/AbstractMessage.php b/src/Messages/AbstractMessage.php index 60fd96f..51d0f0b 100644 --- a/src/Messages/AbstractMessage.php +++ b/src/Messages/AbstractMessage.php @@ -6,6 +6,7 @@ use EC\Poetry\Messages\Traits\ArrayAccessTrait; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Constraints as Assert; +use EC\Poetry\Messages\Traits\ParserAwareTrait; /** * Class AbstractMessage @@ -15,6 +16,7 @@ abstract class AbstractMessage implements MessageInterface { use ArrayAccessTrait; + use ParserAwareTrait; const COMMUNICATION_SYNCHRONOUS = 'synchrone'; const COMMUNICATION_ASYNCHRONOUS = 'asynchrone'; diff --git a/src/Messages/ComponentInterface.php b/src/Messages/ComponentInterface.php index 7531575..1f006ba 100644 --- a/src/Messages/ComponentInterface.php +++ b/src/Messages/ComponentInterface.php @@ -9,7 +9,7 @@ * * @package EC\Poetry\Messages */ -interface ComponentInterface extends \ArrayAccess +interface ComponentInterface extends ParserAwareInterface, \ArrayAccess { /** * Get template name. diff --git a/src/Messages/Components/AbstractComponent.php b/src/Messages/Components/AbstractComponent.php index 36f1e2e..5d4ea4f 100644 --- a/src/Messages/Components/AbstractComponent.php +++ b/src/Messages/Components/AbstractComponent.php @@ -5,14 +5,13 @@ use EC\Poetry\Messages\ComponentInterface; use EC\Poetry\Messages\Traits\ArrayAccessTrait; use EC\Poetry\Messages\Traits\ParserAwareTrait; -use EC\Poetry\Messages\ParserAwareInterface; /** * Class AbstractComponent * * @package EC\Poetry\Messages\Components */ -abstract class AbstractComponent implements ComponentInterface, ParserAwareInterface +abstract class AbstractComponent implements ComponentInterface { use ArrayAccessTrait; use ParserAwareTrait; @@ -36,7 +35,7 @@ public function getAttributes() * * @return \EC\Poetry\Messages\MessageInterface|\EC\Poetry\Messages\ComponentInterface */ - public function fromXml($xml) + public function withXml($xml) { $this->setRaw($xml); diff --git a/src/Messages/Components/Source.php b/src/Messages/Components/Source.php index 2282d0c..10947c5 100644 --- a/src/Messages/Components/Source.php +++ b/src/Messages/Components/Source.php @@ -314,7 +314,7 @@ private function parseSourceLanguage(Parser $parser) $parser->eachComponent("documentSource/documentSourceLang", function (Parser $language) { $this->withSourceLanguage() ->setParser($this->getParser()) - ->fromXml($language->outerHtml()); + ->withXml($language->outerHtml()); }, $this); } diff --git a/src/Messages/Notifications/AbstractNotification.php b/src/Messages/Notifications/AbstractNotification.php index f0521fd..cc3ddfe 100644 --- a/src/Messages/Notifications/AbstractNotification.php +++ b/src/Messages/Notifications/AbstractNotification.php @@ -4,7 +4,6 @@ use EC\Poetry\Events\ParseNotificationEvent; use EC\Poetry\Messages\AbstractMessage; -use EC\Poetry\Messages\Traits\ParserAwareTrait; use EC\Poetry\Messages\ParserAwareInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -15,7 +14,6 @@ */ abstract class AbstractNotification extends AbstractMessage implements ParserAwareInterface, EventSubscriberInterface { - use ParserAwareTrait; /** * {@inheritdoc} @@ -42,7 +40,7 @@ abstract public function onParseNotification(ParseNotificationEvent $event); * * @return \EC\Poetry\Messages\MessageInterface|\EC\Poetry\Messages\ComponentInterface */ - public function fromXml($xml) + public function withXml($xml) { $this->setRaw($xml); diff --git a/src/Messages/Notifications/StatusUpdated.php b/src/Messages/Notifications/StatusUpdated.php index 0ced8a9..5e8fbfd 100644 --- a/src/Messages/Notifications/StatusUpdated.php +++ b/src/Messages/Notifications/StatusUpdated.php @@ -34,7 +34,7 @@ public function onParseNotification(ParseNotificationEvent $event) $parser = $this->getParser(); $parser->addXmlContent($event->getXml()); if ('status' === $parser->getAttribute('POETRY/request', 'type')) { - $this->fromXml($event->getXml()); + $this->withXml($event->getXml()); $event->setEvent(new StatusUpdatedEvent($this)); $event->stopPropagation(); } @@ -49,20 +49,20 @@ protected function parseXml($xml) $parser->addXmlContent($xml); $xml = $parser->getOuterContent('POETRY/request/demandeId'); - $this->getIdentifier()->fromXml($xml); + $this->getIdentifier()->withXml($xml); $this->setMessageId($parser->getAttribute('POETRY/request', 'id')); $parser->eachComponent("POETRY/request/status", function (Parser $component) { $this->withStatus() ->setParser($this->getParser()) - ->fromXml($component->outerHtml()); + ->withXml($component->outerHtml()); }, $this); $parser->eachComponent("POETRY/request/attributions", function (Parser $component) { $this->withTarget() ->setParser($this->getParser()) - ->fromXml($component->outerHtml()); + ->withXml($component->outerHtml()); }, $this); return $this; diff --git a/src/Messages/Notifications/TranslationReceived.php b/src/Messages/Notifications/TranslationReceived.php index e73b4f8..5ef0583 100644 --- a/src/Messages/Notifications/TranslationReceived.php +++ b/src/Messages/Notifications/TranslationReceived.php @@ -32,7 +32,7 @@ public function onParseNotification(ParseNotificationEvent $event) $parser = $this->getParser(); $parser->addXmlContent($event->getXml()); if ('translation' === $parser->getAttribute('POETRY/request', 'type')) { - $this->fromXml($event->getXml()); + $this->withXml($event->getXml()); $event->setEvent(new TranslationReceivedEvent($this)); $event->stopPropagation(); } @@ -47,14 +47,14 @@ protected function parseXml($xml) $parser->addXmlContent($xml); $xml = $parser->getOuterContent('POETRY/request/demandeId'); - $this->getIdentifier()->fromXml($xml); + $this->getIdentifier()->withXml($xml); $this->setMessageId($parser->getAttribute('POETRY/request', 'id')); $parser->eachComponent("POETRY/request/attributions", function (Parser $component) { $this->withTarget() ->setParser($this->getParser()) - ->fromXml($component->outerHtml()); + ->withXml($component->outerHtml()); }, $this); return $this; diff --git a/src/Messages/Requests/AbstractRequest.php b/src/Messages/Requests/AbstractRequest.php index 465f5f6..a9f877e 100644 --- a/src/Messages/Requests/AbstractRequest.php +++ b/src/Messages/Requests/AbstractRequest.php @@ -5,7 +5,6 @@ use EC\Poetry\Messages\AbstractMessage; use EC\Poetry\Messages\Components\Identifier; use EC\Poetry\Messages\ParserAwareInterface; -use EC\Poetry\Messages\Traits\ParserAwareTrait; use EC\Poetry\Services\Settings; /** @@ -15,8 +14,6 @@ */ abstract class AbstractRequest extends AbstractMessage implements ParserAwareInterface { - use ParserAwareTrait; - const REQUEST_NEW = 'new'; const REQUEST_POST = 'post'; const REQUEST_NEW_POST = 'newPost'; @@ -64,7 +61,7 @@ abstract public function getType(); * * @return \EC\Poetry\Messages\MessageInterface|\EC\Poetry\Messages\ComponentInterface */ - public function fromXml($xml) + public function withXml($xml) { $this->setRaw($xml); diff --git a/src/Messages/Responses/AbstractResponse.php b/src/Messages/Responses/AbstractResponse.php index 3ce545e..c836e45 100644 --- a/src/Messages/Responses/AbstractResponse.php +++ b/src/Messages/Responses/AbstractResponse.php @@ -4,7 +4,6 @@ use EC\Poetry\Events\ParseResponseEvent; use EC\Poetry\Messages\AbstractMessage; -use EC\Poetry\Messages\Traits\ParserAwareTrait; /** * Class AbstractResponse. @@ -13,7 +12,6 @@ */ abstract class AbstractResponse extends AbstractMessage implements ResponseInterface { - use ParserAwareTrait; /** * {@inheritdoc} @@ -40,7 +38,7 @@ abstract public function onParseResponse(ParseResponseEvent $event); * * @return \EC\Poetry\Messages\MessageInterface|\EC\Poetry\Messages\ComponentInterface */ - public function fromXml($xml) + public function withXml($xml) { $this->setRaw($xml); diff --git a/src/Messages/Responses/ResponseInterface.php b/src/Messages/Responses/ResponseInterface.php index 6092bd7..1639577 100644 --- a/src/Messages/Responses/ResponseInterface.php +++ b/src/Messages/Responses/ResponseInterface.php @@ -2,7 +2,6 @@ namespace EC\Poetry\Messages\Responses; -use EC\Poetry\Messages\ParserAwareInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** @@ -10,7 +9,7 @@ * * @package EC\Poetry\Messages\Responses */ -interface ResponseInterface extends ParserAwareInterface, EventSubscriberInterface +interface ResponseInterface extends EventSubscriberInterface { } diff --git a/src/Messages/Responses/Status.php b/src/Messages/Responses/Status.php index 6253ea0..851439b 100644 --- a/src/Messages/Responses/Status.php +++ b/src/Messages/Responses/Status.php @@ -33,7 +33,7 @@ public function onParseResponse(ParseResponseEvent $event) $parser = $this->getParser(); $parser->addXmlContent($event->getXml()); if ($parser->getContent('POETRY/request/status') !== null) { - $event->setMessage($this->fromXml($event->getXml())); + $event->setMessage($this->withXml($event->getXml())); $event->stopPropagation(); } } @@ -47,14 +47,14 @@ protected function parseXml($xml) $parser->addXmlContent($xml); $xml = $parser->getOuterContent('POETRY/request/demandeId'); - $this->getIdentifier()->fromXml($xml); + $this->getIdentifier()->withXml($xml); $this->setMessageId($parser->getAttribute('POETRY/request', 'id')); $parser->eachComponent("POETRY/request/status", function (Parser $component) { $this->withStatus() ->setParser($this->getParser()) - ->fromXml($component->outerHtml()); + ->withXml($component->outerHtml()); }, $this); return $this; diff --git a/tests/src/Messages/Components/ContactTest.php b/tests/src/Messages/Components/ContactTest.php index 47d2492..a877a72 100644 --- a/tests/src/Messages/Components/ContactTest.php +++ b/tests/src/Messages/Components/ContactTest.php @@ -51,7 +51,7 @@ public function testValidation() public function testParsing($xml, $type, $nickname, $email) { /** @var \EC\Poetry\Messages\Components\Contact $component */ - $component = $this->getContainer()->get('component.contact')->fromXml($xml); + $component = $this->getContainer()->get('component.contact')->withXml($xml); expect($component->getType())->to->equal($type); expect($component->getNickname())->to->equal($nickname); diff --git a/tests/src/Messages/Components/DetailsTest.php b/tests/src/Messages/Components/DetailsTest.php index a7e61a5..206259b 100644 --- a/tests/src/Messages/Components/DetailsTest.php +++ b/tests/src/Messages/Components/DetailsTest.php @@ -44,7 +44,7 @@ public function testValidation() public function testParsing($xml, $fixtures) { /** @var \EC\Poetry\Messages\Components\Details $component */ - $component = $this->getContainer()->get('component.details')->fromXml($xml); + $component = $this->getContainer()->get('component.details')->withXml($xml); foreach ($fixtures as $method => $value) { expect($component->$method())->to->equal($value); diff --git a/tests/src/Messages/Components/IdentifierTest.php b/tests/src/Messages/Components/IdentifierTest.php index d4e5b4f..617df51 100644 --- a/tests/src/Messages/Components/IdentifierTest.php +++ b/tests/src/Messages/Components/IdentifierTest.php @@ -55,7 +55,7 @@ public function testValidation() public function testParsing($xml, $code, $year, $number, $version, $part, $product) { /** @var \EC\Poetry\Messages\Components\Identifier $component */ - $component = $this->getContainer()->get('component.identifier')->fromXml($xml); + $component = $this->getContainer()->get('component.identifier')->withXml($xml); expect($component->getCode())->to->equal($code); expect($component->getYear())->to->equal($year); diff --git a/tests/src/Messages/Components/ReferenceDocumentTest.php b/tests/src/Messages/Components/ReferenceDocumentTest.php index 444a184..f550dc2 100644 --- a/tests/src/Messages/Components/ReferenceDocumentTest.php +++ b/tests/src/Messages/Components/ReferenceDocumentTest.php @@ -50,7 +50,7 @@ public function testValidation() public function testParsing($xml, $fixtures) { /** @var \EC\Poetry\Messages\Components\ReferenceDocument $component */ - $component = $this->getContainer()->get('component.reference_document')->fromXml($xml); + $component = $this->getContainer()->get('component.reference_document')->withXml($xml); foreach ($fixtures as $method => $value) { expect($component->$method())->to->equal($value); } diff --git a/tests/src/Messages/Components/ReturnAddressTest.php b/tests/src/Messages/Components/ReturnAddressTest.php index ce0db4c..bc9d1c3 100644 --- a/tests/src/Messages/Components/ReturnAddressTest.php +++ b/tests/src/Messages/Components/ReturnAddressTest.php @@ -47,7 +47,7 @@ public function testValidation() public function testParsing($xml, $fixtures) { /** @var \EC\Poetry\Messages\Components\ReturnAddress $component */ - $component = $this->getContainer()->get('component.return_address')->fromXml($xml); + $component = $this->getContainer()->get('component.return_address')->withXml($xml); foreach ($fixtures as $method => $value) { expect($component->$method())->to->equal($value); diff --git a/tests/src/Messages/Components/SourceTest.php b/tests/src/Messages/Components/SourceTest.php index da4910a..93a15b7 100644 --- a/tests/src/Messages/Components/SourceTest.php +++ b/tests/src/Messages/Components/SourceTest.php @@ -53,7 +53,7 @@ public function testValidation() public function testParsing($xml, $expected) { /** @var \EC\Poetry\Messages\Components\Source $component */ - $component = $this->getContainer()->get('component.source')->fromXml($xml); + $component = $this->getContainer()->get('component.source')->withXml($xml); foreach ($expected as $getComponent => $properties) { if ($this->isComponentCollection($properties)) { diff --git a/tests/src/Messages/Components/StatusTest.php b/tests/src/Messages/Components/StatusTest.php index 8c33af7..7b10832 100644 --- a/tests/src/Messages/Components/StatusTest.php +++ b/tests/src/Messages/Components/StatusTest.php @@ -48,7 +48,7 @@ public function testValidation() public function testParsing($xml, $date, $time, $message, $code, $type) { /** @var \EC\Poetry\Messages\Components\Status $component */ - $component = $this->getContainer()->get('component.status')->fromXml($xml); + $component = $this->getContainer()->get('component.status')->withXml($xml); expect($component->getDate())->to->equal($date); expect($component->getTime())->to->equal($time); diff --git a/tests/src/Messages/Components/TargetTest.php b/tests/src/Messages/Components/TargetTest.php index aceffe0..0fbbe37 100644 --- a/tests/src/Messages/Components/TargetTest.php +++ b/tests/src/Messages/Components/TargetTest.php @@ -64,7 +64,7 @@ public function testValidation() public function testParsing($xml, $targetProperties, $addressProperties, $contactProperties) { /** @var \EC\Poetry\Messages\Components\Target $target */ - $target = $this->getContainer()->get('component.target')->fromXml($xml); + $target = $this->getContainer()->get('component.target')->withXml($xml); foreach ($targetProperties as $method => $value) { expect($target->$method())->to->equal($value); diff --git a/tests/src/Messages/Notifications/StatusUpdatedTest.php b/tests/src/Messages/Notifications/StatusUpdatedTest.php index be7119e..ecebbb6 100644 --- a/tests/src/Messages/Notifications/StatusUpdatedTest.php +++ b/tests/src/Messages/Notifications/StatusUpdatedTest.php @@ -74,7 +74,7 @@ public function testRender() public function testParsing($xml, $identifier, $statuses, $targets) { /** @var \EC\Poetry\Messages\Notifications\StatusUpdated $message */ - $message = $this->getContainer()->get('notification.status_updated')->fromXml($xml); + $message = $this->getContainer()->get('notification.status_updated')->withXml($xml); foreach ($identifier as $method => $expected) { expect($message->getIdentifier()->{$method}())->to->equal($expected); diff --git a/tests/src/Messages/Notifications/TranslationReceivedTest.php b/tests/src/Messages/Notifications/TranslationReceivedTest.php index 9407c9e..2b3a0ea 100644 --- a/tests/src/Messages/Notifications/TranslationReceivedTest.php +++ b/tests/src/Messages/Notifications/TranslationReceivedTest.php @@ -54,7 +54,7 @@ public function testRender() public function testParsing($xml, $identifier, $targets) { /** @var \EC\Poetry\Messages\Notifications\TranslationReceived $message */ - $message = $this->getContainer()->get('notification.translation_received')->fromXml($xml); + $message = $this->getContainer()->get('notification.translation_received')->withXml($xml); foreach ($identifier as $method => $expected) { expect($message->getIdentifier()->{$method}())->to->equal($expected); diff --git a/tests/src/Messages/Responses/StatusTest.php b/tests/src/Messages/Responses/StatusTest.php index 4076456..40cbbd0 100644 --- a/tests/src/Messages/Responses/StatusTest.php +++ b/tests/src/Messages/Responses/StatusTest.php @@ -29,7 +29,7 @@ class StatusTest extends AbstractTest public function testParsing($xml, $identifier, $statuses) { /** @var \EC\Poetry\Messages\Responses\Status $message */ - $message = $this->getContainer()->get('response.status')->fromXml($xml); + $message = $this->getContainer()->get('response.status')->withXml($xml); foreach ($identifier as $method => $expected) { expect($message->getIdentifier()->{$method}())->to->equal($expected); @@ -52,7 +52,7 @@ public function testParsing($xml, $identifier, $statuses) public function testValidation($xml, array $expectations) { /** @var \EC\Poetry\Messages\Responses\Status $message */ - $message = $this->getContainer()->get('response.status')->fromXml($xml); + $message = $this->getContainer()->get('response.status')->withXml($xml); foreach ($expectations as $method => $result) { if (is_array($result) && is_numeric(key($result))) { foreach ($result as $key => $values) { diff --git a/tests/src/NotificationHandlerTest.php b/tests/src/NotificationHandlerTest.php index bff3dd7..39f1e45 100644 --- a/tests/src/NotificationHandlerTest.php +++ b/tests/src/NotificationHandlerTest.php @@ -56,7 +56,7 @@ public function testFunctionCallback() $message = $this->getFixture('messages/notifications/status-updated.xml'); $response = $this->notifyServer('/notification', 'username', 'password', $message); /** @var \EC\Poetry\Messages\Responses\Status $status */ - $status = $this->getContainer()->get('response.status')->fromXml($response); + $status = $this->getContainer()->get('response.status')->withXml($response); expect($status->getMessageId())->to->be->equal('1069698'); date_default_timezone_set('Europe/Brussels'); expect($status->getStatuses()[0]->getDate())->to->be->equal(date('d/m/Y')); @@ -69,7 +69,7 @@ public function testFunctionCallback() $message = $this->getFixture('messages/notifications/status-updated-nok.xml'); $response = $this->notifyServer('/notification', 'username', 'password', $message); /** @var \EC\Poetry\Messages\Responses\Status $status */ - $status = $this->getContainer()->get('response.status')->fromXml($response); + $status = $this->getContainer()->get('response.status')->withXml($response); expect($status->getStatuses()[0]->getMessage())->to->be->equal('identifier.year: This value should be greater than 2000.'); expect($status->getStatuses()[0]->getCode())->to->be->equal('-1'); @@ -77,7 +77,7 @@ public function testFunctionCallback() $message = $this->getFixture('messages/notifications/status-updated.xml'); $response = $this->notifyServer('/notification', 'wrong-username', 'wrong-password', $message); /** @var \EC\Poetry\Messages\Responses\Status $status */ - $status = $this->getContainer()->get('response.status')->fromXml($response); + $status = $this->getContainer()->get('response.status')->withXml($response); expect($status->getStatuses()[0]->getMessage())->to->be->equal('Poetry service cannot authenticate on notification callback: username or password not valid.'); expect($status->getStatuses()[0]->getCode())->to->be->equal('-1'); }