Skip to content

Commit

Permalink
Update callback event name
Browse files Browse the repository at this point in the history
  • Loading branch information
Pitoune authored and cdaguerre committed Nov 17, 2016
1 parent 9fad862 commit 13e45a9
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 43 deletions.
2 changes: 1 addition & 1 deletion lib/Textmaster/CallbackHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private function getEvent(array $data)
}

if (!isset($type)) {
throw new InvalidArgumentException(sprintf('Couldnt determine callback type from "%s".', serialize($data)));
throw new InvalidArgumentException(sprintf('Could not determine callback type from "%s".', serialize($data)));
}

$name = sprintf('textmaster.%s.%s', $type, $data['status']);
Expand Down
15 changes: 15 additions & 0 deletions lib/Textmaster/Event/CallbackEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,30 @@

class CallbackEvent extends GenericEvent
{
/**
* @var string
*/
private $eventName;

/**
* Constructor.
*
* @param string $eventName
* @param array $subject
* @param mixed $data
*/
public function __construct($eventName, $subject, $data)
{
parent::__construct($subject, $data);

$this->eventName = $eventName;
}

/**
* Get name.
*
* @return string
*/
public function getName()
{
return $this->eventName;
Expand Down
8 changes: 0 additions & 8 deletions lib/Textmaster/Model/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,6 @@ public function getSourceContent()
return $this->formatTranslatedContent();
}

/**
* {@inheritdoc}
*/
public function getTranslatedContent()
{
return $this->getSourceContent();
}

/**
* {@inheritdoc}
*/
Expand Down
9 changes: 0 additions & 9 deletions lib/Textmaster/Model/DocumentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,6 @@ public function getType();
*/
public function getSourceContent();

/**
* Get translated content.
*
* @deprecated since version 0.2.7, to be removed in 0.3. Use getSourceContent().
*
* @return string|array
*/
public function getTranslatedContent();

/**
* Get word count.
*
Expand Down
14 changes: 11 additions & 3 deletions lib/Textmaster/Translator/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function supports($subject)
/**
* {@inheritdoc}
*/
public function create($subject, array $properties, DocumentInterface $document)
public function push($subject, array $properties, DocumentInterface $document)
{
$this->failIfDoesNotSupport($subject);
$project = $document->getProject();
Expand Down Expand Up @@ -86,6 +86,16 @@ public function compare(DocumentInterface $document)
* {@inheritdoc}
*/
public function complete(DocumentInterface $document, $satisfaction = null, $message = null)
{
$document->complete($satisfaction, $message);

return $document;
}

/**
* {@inheritdoc}
*/
public function pull(DocumentInterface $document)
{
$subject = $this->getSubjectFromDocument($document);
$this->failIfDoesNotSupport($subject);
Expand All @@ -98,8 +108,6 @@ public function complete(DocumentInterface $document, $satisfaction = null, $mes

$this->setProperties($subject, $properties, $language);

$document->complete($satisfaction, $message);

return $subject;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Textmaster/Translator/Adapter/AbstractDoctrineAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public function __construct(ManagerRegistry $registry)
/**
* {@inheritdoc}
*/
public function complete(DocumentInterface $document, $satisfaction = null, $message = null)
public function pull(DocumentInterface $document)
{
$subject = parent::complete($document, $satisfaction, $message);
$subject = parent::pull($document);

$this->persist($subject);

Expand Down
19 changes: 15 additions & 4 deletions lib/Textmaster/Translator/Adapter/AdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,22 @@ interface AdapterInterface
/**
* Whether the adapter supports the given subject.
*
* @param mixed $subject
*
* @return bool
*/
public function supports($subject);

/**
* Launch a translation.
* Push document to textmaster.
*
* @param mixed $subject
* @param array $properties
* @param DocumentInterface $document
*
* @return DocumentInterface
*/
public function create($subject, array $properties, DocumentInterface $document);
public function push($subject, array $properties, DocumentInterface $document);

/**
* Make a comparison between textmaster document and its subject.
Expand All @@ -43,16 +45,25 @@ public function create($subject, array $properties, DocumentInterface $document)
public function compare(DocumentInterface $document);

/**
* Complete a translation.
* Complete a document.
*
* @param DocumentInterface $document
* @param string $satisfaction
* @param string $message
*
* @return mixed
* @return DocumentInterface
*/
public function complete(DocumentInterface $document, $satisfaction = null, $message = null);

/**
* Pull document from textmaster.
*
* @param DocumentInterface $document
*
* @return mixed The subject passed on creation.
*/
public function pull(DocumentInterface $document);

/**
* Get subject from document.
*
Expand Down
20 changes: 18 additions & 2 deletions lib/Textmaster/Translator/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function __construct(
/**
* {@inheritdoc}
*/
public function create($subject, $documentOrParams = null, $save = true)
public function push($subject, $documentOrParams = null, $save = true)
{
$document = $documentOrParams;

Expand All @@ -66,7 +66,7 @@ public function create($subject, $documentOrParams = null, $save = true)

foreach ($this->adapters as $adapter) {
if ($adapter->supports($subject)) {
$document = $adapter->create($subject, $properties, $document);
$document = $adapter->push($subject, $properties, $document);

if ($save) {
$document->save();
Expand Down Expand Up @@ -111,6 +111,22 @@ public function complete(DocumentInterface $document, $satisfaction = null, $mes
throw new InvalidArgumentException(sprintf('No adapter found for document "%s".', $document->getId()));
}

/**
* {@inheritdoc}
*/
public function pull(DocumentInterface $document)
{
foreach ($this->adapters as $adapter) {
try {
return $adapter->pull($document);
} catch (UnexpectedTypeException $e) {
continue;
}
}

throw new InvalidArgumentException(sprintf('No adapter found for document "%s".', $document->getId()));
}

/**
* {@inheritdoc}
*/
Expand Down
17 changes: 13 additions & 4 deletions lib/Textmaster/Translator/TranslatorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
interface TranslatorInterface
{
/**
* Launch a translation.
* Push document to textmaster.
*
* @param mixed $subject
* @param mixed|DocumentInterface $documentOrParams Either pass a document instance
Expand All @@ -25,7 +25,7 @@ interface TranslatorInterface
*
* @return DocumentInterface
*/
public function create($subject, $documentOrParams = null, $save = true);
public function push($subject, $documentOrParams = null, $save = true);

/**
* Make a comparison between textmaster document and its subject.
Expand All @@ -37,16 +37,25 @@ public function create($subject, $documentOrParams = null, $save = true);
public function compare(DocumentInterface $document);

/**
* Complete a translation.
* Complete a document.
*
* @param DocumentInterface $document
* @param string $satisfaction
* @param string $message
*
* @return mixed The subject passed on creation.
* @return DocumentInterface
*/
public function complete(DocumentInterface $document, $satisfaction = null, $message = null);

/**
* Pull document from textmaster.
*
* @param DocumentInterface $document
*
* @return mixed The subject passed on creation.
*/
public function pull(DocumentInterface $document);

/**
* Get subject from document.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function shouldCreateSameLocale()
->willReturn('en');

$adapter = new GedmoTranslatableAdapter($managerRegistryMock, $listenerMock);
$adapter->create($translatableMock, ['name'], $documentMock);
$adapter->push($translatableMock, ['name'], $documentMock);
}

/**
Expand Down Expand Up @@ -95,6 +95,6 @@ public function shouldCreateDifferentLocale()
->method('refresh');

$adapter = new GedmoTranslatableAdapter($managerRegistryMock, $listenerMock);
$adapter->create($translatableMock, ['name'], $documentMock);
$adapter->push($translatableMock, ['name'], $documentMock);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function shouldCreate()
->willReturn(1);

$adapter = new SyliusTranslatableAdapter($managerRegistryMock);
$adapter->create($translatableMock, ['name'], $documentMock);
$adapter->push($translatableMock, ['name'], $documentMock);
}

/**
Expand Down Expand Up @@ -125,7 +125,7 @@ public function shouldComplete()
->willReturn(ProjectInterface::ACTIVITY_TRANSLATION);

$adapter = new SyliusTranslatableAdapter($managerRegistryMock);
$subject = $adapter->complete($documentMock);
$subject = $adapter->pull($documentMock);

$this->assertSame($translatableMock, $subject);
$this->assertSame('my translation', $translationMock->getName());
Expand Down
12 changes: 6 additions & 6 deletions test/Textmaster/Unit/Translator/TranslatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ public function shouldCreate()
->willReturn(true);

$adapterMock->expects($this->once())
->method('create')
->method('push')
->willReturn($documentMock);

$translator = new Translator($adapters, $mappingProviderMock);
$translator->create($subjectMock, $documentMock);
$translator->push($subjectMock, $documentMock);
}

/**
Expand Down Expand Up @@ -70,11 +70,11 @@ public function shouldCreateFromFactory()
->willReturn(true);

$adapterMock->expects($this->once())
->method('create')
->method('push')
->willReturn($documentMock);

$translator = new Translator($adapters, $mappingProviderMock, $documentFactoryMock);
$translator->create($subjectMock);
$translator->push($subjectMock);
}

/**
Expand Down Expand Up @@ -192,7 +192,7 @@ public function shouldNotCreate()
->willReturn(false);

$translator = new Translator($adapters, $mappingProviderMock);
$translator->create($subjectMock, $documentMock);
$translator->push($subjectMock, $documentMock);
}

/**
Expand Down Expand Up @@ -223,7 +223,7 @@ public function shouldNotCreateFromFactory()
$subjectMock = $this->getMock('Subject');

$translator = new Translator($adapters, $mappingProviderMock);
$translator->create($subjectMock);
$translator->push($subjectMock);
}

/**
Expand Down

0 comments on commit 13e45a9

Please sign in to comment.