Skip to content

Commit

Permalink
Issue #62: Refactor withXml().
Browse files Browse the repository at this point in the history
  • Loading branch information
ademarco committed Nov 3, 2017
1 parent 89defad commit 9a33d63
Show file tree
Hide file tree
Showing 23 changed files with 67 additions and 135 deletions.
16 changes: 16 additions & 0 deletions src/Messages/AbstractMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,20 @@ public function setMessageId($messageId)
{
$this->messageId = $messageId;
}

/**
* {@inheritdoc}
*/
public function withXml($xml)
{
$this->setRaw($xml);
$parser = $this->getParser();
$parser->addXmlContent($xml);

$xml = $parser->getOuterContent('POETRY/request/demandeId');
$this->getIdentifier()->withXml($xml);
$this->setMessageId($parser->getAttribute('POETRY/request', 'id'));

return $this;
}
}
26 changes: 26 additions & 0 deletions src/Messages/ComponentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,36 @@ public function getAttributes();
* Construct component from given array.
*
* @param array $properties
*
* @return $this
*/
public function withArray(array $properties);

/**
* Set message or component internal properties given its XML representation.
*
* @param string $xml
*
* @return $this
*/
public function withXml($xml);

/**
* Get raw XML.
*
* @return string
*/
public function getRaw();

/**
* Set raw XML.
*
* @param string $raw
*
* @return $this
*/
public function setRaw($raw);

/**
* @param \Symfony\Component\Validator\Mapping\ClassMetadata $metadata
*/
Expand Down
19 changes: 2 additions & 17 deletions src/Messages/Components/AbstractComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,12 @@ public function getAttributes()
}

/**
* Set a message or a component internal properties given its XML representation.
*
* @param string $xml
* XML string.
*
* @return \EC\Poetry\Messages\MessageInterface|\EC\Poetry\Messages\ComponentInterface
* {@inheritdoc}
*/
public function withXml($xml)
{
$this->setRaw($xml);

return $this->parseXml($xml);
return $this;
}

/**
* Parse a XML string into a set of properties.
*
* @param string $xml
* XML string.
*
* @return \EC\Poetry\Messages\MessageInterface|\EC\Poetry\Messages\ComponentInterface
*/
abstract protected function parseXml($xml);
}
2 changes: 1 addition & 1 deletion src/Messages/Components/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function setEmail($email)
/**
* {@inheritdoc}
*/
protected function parseXml($xml)
public function withXml($xml)
{
$parser = $this->getParser();
$parser->addXmlContent($xml);
Expand Down
2 changes: 1 addition & 1 deletion src/Messages/Components/Details.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ public function setReferenceFilesRemark($referenceFilesRemark)
/**
* {@inheritdoc}
*/
protected function parseXml($xml)
public function withXml($xml)
{
$parser = $this->getParser();
$parser->addXmlContent($xml);
Expand Down
2 changes: 1 addition & 1 deletion src/Messages/Components/Identifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public function getGroupSequence()
/**
* {@inheritdoc}
*/
protected function parseXml($xml)
public function withXml($xml)
{
$parser = $this->getParser();
$parser->addXmlContent($xml);
Expand Down
2 changes: 1 addition & 1 deletion src/Messages/Components/ReferenceDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public function setFile($file)
/**
* {@inheritdoc}
*/
protected function parseXml($xml)
public function withXml($xml)
{
$parser = $this->getParser();
$parser->addXmlContent($xml);
Expand Down
2 changes: 1 addition & 1 deletion src/Messages/Components/ReturnAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public function setRemark($remark)
/**
* {@inheritdoc}
*/
protected function parseXml($xml)
public function withXml($xml)
{
$parser = $this->getParser();
$parser->addXmlContent($xml);
Expand Down
2 changes: 1 addition & 1 deletion src/Messages/Components/Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ public function setFile($file)
/**
* {@inheritdoc}
*/
protected function parseXml($xml)
public function withXml($xml)
{
$parser = $this->getParser();
$parser->addXmlContent($xml);
Expand Down
2 changes: 1 addition & 1 deletion src/Messages/Components/SourceLanguage.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function setPages($pages)
/**
* {@inheritdoc}
*/
protected function parseXml($xml)
public function withXml($xml)
{
$parser = $this->getParser();
$parser->addXmlContent($xml);
Expand Down
2 changes: 1 addition & 1 deletion src/Messages/Components/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public function setMessage($message)
/**
* {@inheritdoc}
*/
protected function parseXml($xml)
public function withXml($xml)
{
$parser = $this->getParser();
$parser->addXmlContent($xml);
Expand Down
2 changes: 1 addition & 1 deletion src/Messages/Components/Target.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public function withReturnAddress()
/**
* {@inheritdoc}
*/
protected function parseXml($xml)
public function withXml($xml)
{
$parser = $this->getParser();
$parser->addXmlContent($xml);
Expand Down
1 change: 0 additions & 1 deletion src/Messages/Components/TargetReturnAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/
class TargetReturnAddress extends ReturnAddress
{

/**
* {@inheritdoc}
*/
Expand Down
2 changes: 0 additions & 2 deletions src/Messages/MessageAwareInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace EC\Poetry\Messages;

use EC\Poetry\Messages\MessageInterface;

/**
* Interface MessageAwareInterface
*
Expand Down
29 changes: 0 additions & 29 deletions src/Messages/Notifications/AbstractNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
*/
abstract class AbstractNotification extends AbstractMessage implements ParserAwareInterface, EventSubscriberInterface
{

/**
* {@inheritdoc}
*/
Expand All @@ -31,32 +30,4 @@ public static function getSubscribedEvents()
* @return mixed
*/
abstract public function onParseNotification(ParseNotificationEvent $event);

/**
* Set a message or a component internal properties given its XML representation.
*
* @param string $xml
* XML string.
*
* @return \EC\Poetry\Messages\MessageInterface|\EC\Poetry\Messages\ComponentInterface
*/
public function withXml($xml)
{
$this->setRaw($xml);

return $this->parseXml($xml);
}

/**
* Parse a XML string into a set of properties.
*
* @param string $xml
* XML string.
*
* @return \EC\Poetry\Messages\MessageInterface|\EC\Poetry\Messages\ComponentInterface
*/
protected function parseXml($xml)
{
return $this;
}
}
9 changes: 3 additions & 6 deletions src/Messages/Notifications/StatusUpdated.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,13 @@ public function onParseNotification(ParseNotificationEvent $event)
/**
* {@inheritdoc}
*/
protected function parseXml($xml)
public function withXml($xml)
{
parent::withXml($xml);

$parser = $this->getParser();
$parser->addXmlContent($xml);

$xml = $parser->getOuterContent('POETRY/request/demandeId');
$this->getIdentifier()->withXml($xml);

$this->setMessageId($parser->getAttribute('POETRY/request', 'id'));

$parser->eachComponent("POETRY/request/status", function (Parser $component) {
$this->withStatus()
->setParser($this->getParser())
Expand Down
9 changes: 3 additions & 6 deletions src/Messages/Notifications/TranslationReceived.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,13 @@ public function onParseNotification(ParseNotificationEvent $event)
/**
* {@inheritdoc}
*/
protected function parseXml($xml)
public function withXml($xml)
{
parent::withXml($xml);

$parser = $this->getParser();
$parser->addXmlContent($xml);

$xml = $parser->getOuterContent('POETRY/request/demandeId');
$this->getIdentifier()->withXml($xml);

$this->setMessageId($parser->getAttribute('POETRY/request', 'id'));

$parser->eachComponent("POETRY/request/attributions", function (Parser $component) {
$this->withTarget()
->setParser($this->getParser())
Expand Down
2 changes: 0 additions & 2 deletions src/Messages/ParserAwareInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ interface ParserAwareInterface
* Get Parser property.
*
* @return \EC\Poetry\Services\Parser
* Property value.
*/
public function getParser();

/**
* Set Parser property.
*
* @param \EC\Poetry\Services\Parser $parser
* Property value.
*
* @return $this
*/
Expand Down
28 changes: 0 additions & 28 deletions src/Messages/Requests/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,32 +52,4 @@ public function getTemplate()
* @return string
*/
abstract public function getType();

/**
* Set a message or a component internal properties given its XML representation.
*
* @param string $xml
* XML string.
*
* @return \EC\Poetry\Messages\MessageInterface|\EC\Poetry\Messages\ComponentInterface
*/
public function withXml($xml)
{
$this->setRaw($xml);

return $this->parseXml($xml);
}

/**
* Parse a XML string into a set of properties.
*
* @param string $xml
* XML string.
*
* @return \EC\Poetry\Messages\MessageInterface|\EC\Poetry\Messages\ComponentInterface
*/
protected function parseXml($xml)
{
return $this;
}
}
1 change: 1 addition & 0 deletions src/Messages/Requests/CreateTranslationRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use EC\Poetry\Messages\Traits\WithReturnAddressTrait;
use EC\Poetry\Messages\Traits\WithSourceTrait;
use EC\Poetry\Messages\Traits\WithTargetsTrait;
use EC\Poetry\Services\Parser;
use EC\Poetry\Services\Settings;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Constraints as Assert;
Expand Down
29 changes: 0 additions & 29 deletions src/Messages/Responses/AbstractResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/
abstract class AbstractResponse extends AbstractMessage implements ResponseInterface
{

/**
* {@inheritdoc}
*/
Expand All @@ -29,32 +28,4 @@ public static function getSubscribedEvents()
* @param \EC\Poetry\Events\ParseResponseEvent $event
*/
abstract public function onParseResponse(ParseResponseEvent $event);

/**
* Set a message or a component internal properties given its XML representation.
*
* @param string $xml
* XML string.
*
* @return \EC\Poetry\Messages\MessageInterface|\EC\Poetry\Messages\ComponentInterface
*/
public function withXml($xml)
{
$this->setRaw($xml);

return $this->parseXml($xml);
}

/**
* Parse a XML string into a set of properties.
*
* @param string $xml
* XML string.
*
* @return \EC\Poetry\Messages\MessageInterface|\EC\Poetry\Messages\ComponentInterface
*/
protected function parseXml($xml)
{
return $this;
}
}
9 changes: 3 additions & 6 deletions src/Messages/Responses/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,13 @@ public function onParseResponse(ParseResponseEvent $event)
/**
* {@inheritdoc}
*/
protected function parseXml($xml)
public function withXml($xml)
{
parent::withXml($xml);

$parser = $this->getParser();
$parser->addXmlContent($xml);

$xml = $parser->getOuterContent('POETRY/request/demandeId');
$this->getIdentifier()->withXml($xml);

$this->setMessageId($parser->getAttribute('POETRY/request', 'id'));

$parser->eachComponent("POETRY/request/status", function (Parser $component) {
$this->withStatus()
->setParser($this->getParser())
Expand Down
4 changes: 4 additions & 0 deletions src/Messages/Traits/ParserAwareTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ public function getRaw()

/**
* @param string $raw
*
* @return $this
*/
public function setRaw($raw)
{
$this->raw = $raw;

return $this;
}

/**
Expand Down

0 comments on commit 9a33d63

Please sign in to comment.