Skip to content

Commit 13e45a9

Browse files
Pitounecdaguerre
Pitoune
authored andcommitted
Update callback event name
1 parent 9fad862 commit 13e45a9

12 files changed

+85
-43
lines changed

lib/Textmaster/CallbackHandler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ private function getEvent(array $data)
107107
}
108108

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

113113
$name = sprintf('textmaster.%s.%s', $type, $data['status']);

lib/Textmaster/Event/CallbackEvent.php

+15
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,30 @@
1515

1616
class CallbackEvent extends GenericEvent
1717
{
18+
/**
19+
* @var string
20+
*/
1821
private $eventName;
1922

23+
/**
24+
* Constructor.
25+
*
26+
* @param string $eventName
27+
* @param array $subject
28+
* @param mixed $data
29+
*/
2030
public function __construct($eventName, $subject, $data)
2131
{
2232
parent::__construct($subject, $data);
2333

2434
$this->eventName = $eventName;
2535
}
2636

37+
/**
38+
* Get name.
39+
*
40+
* @return string
41+
*/
2742
public function getName()
2843
{
2944
return $this->eventName;

lib/Textmaster/Model/Document.php

-8
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,6 @@ public function getSourceContent()
203203
return $this->formatTranslatedContent();
204204
}
205205

206-
/**
207-
* {@inheritdoc}
208-
*/
209-
public function getTranslatedContent()
210-
{
211-
return $this->getSourceContent();
212-
}
213-
214206
/**
215207
* {@inheritdoc}
216208
*/

lib/Textmaster/Model/DocumentInterface.php

-9
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,6 @@ public function getType();
128128
*/
129129
public function getSourceContent();
130130

131-
/**
132-
* Get translated content.
133-
*
134-
* @deprecated since version 0.2.7, to be removed in 0.3. Use getSourceContent().
135-
*
136-
* @return string|array
137-
*/
138-
public function getTranslatedContent();
139-
140131
/**
141132
* Get word count.
142133
*

lib/Textmaster/Translator/Adapter/AbstractAdapter.php

+11-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function supports($subject)
3434
/**
3535
* {@inheritdoc}
3636
*/
37-
public function create($subject, array $properties, DocumentInterface $document)
37+
public function push($subject, array $properties, DocumentInterface $document)
3838
{
3939
$this->failIfDoesNotSupport($subject);
4040
$project = $document->getProject();
@@ -86,6 +86,16 @@ public function compare(DocumentInterface $document)
8686
* {@inheritdoc}
8787
*/
8888
public function complete(DocumentInterface $document, $satisfaction = null, $message = null)
89+
{
90+
$document->complete($satisfaction, $message);
91+
92+
return $document;
93+
}
94+
95+
/**
96+
* {@inheritdoc}
97+
*/
98+
public function pull(DocumentInterface $document)
8999
{
90100
$subject = $this->getSubjectFromDocument($document);
91101
$this->failIfDoesNotSupport($subject);
@@ -98,8 +108,6 @@ public function complete(DocumentInterface $document, $satisfaction = null, $mes
98108

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

101-
$document->complete($satisfaction, $message);
102-
103111
return $subject;
104112
}
105113

lib/Textmaster/Translator/Adapter/AbstractDoctrineAdapter.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ public function __construct(ManagerRegistry $registry)
3636
/**
3737
* {@inheritdoc}
3838
*/
39-
public function complete(DocumentInterface $document, $satisfaction = null, $message = null)
39+
public function pull(DocumentInterface $document)
4040
{
41-
$subject = parent::complete($document, $satisfaction, $message);
41+
$subject = parent::pull($document);
4242

4343
$this->persist($subject);
4444

lib/Textmaster/Translator/Adapter/AdapterInterface.php

+15-4
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,22 @@ interface AdapterInterface
1818
/**
1919
* Whether the adapter supports the given subject.
2020
*
21+
* @param mixed $subject
22+
*
2123
* @return bool
2224
*/
2325
public function supports($subject);
2426

2527
/**
26-
* Launch a translation.
28+
* Push document to textmaster.
2729
*
2830
* @param mixed $subject
2931
* @param array $properties
3032
* @param DocumentInterface $document
3133
*
3234
* @return DocumentInterface
3335
*/
34-
public function create($subject, array $properties, DocumentInterface $document);
36+
public function push($subject, array $properties, DocumentInterface $document);
3537

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

4547
/**
46-
* Complete a translation.
48+
* Complete a document.
4749
*
4850
* @param DocumentInterface $document
4951
* @param string $satisfaction
5052
* @param string $message
5153
*
52-
* @return mixed
54+
* @return DocumentInterface
5355
*/
5456
public function complete(DocumentInterface $document, $satisfaction = null, $message = null);
5557

58+
/**
59+
* Pull document from textmaster.
60+
*
61+
* @param DocumentInterface $document
62+
*
63+
* @return mixed The subject passed on creation.
64+
*/
65+
public function pull(DocumentInterface $document);
66+
5667
/**
5768
* Get subject from document.
5869
*

lib/Textmaster/Translator/Translator.php

+18-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function __construct(
5454
/**
5555
* {@inheritdoc}
5656
*/
57-
public function create($subject, $documentOrParams = null, $save = true)
57+
public function push($subject, $documentOrParams = null, $save = true)
5858
{
5959
$document = $documentOrParams;
6060

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

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

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

114+
/**
115+
* {@inheritdoc}
116+
*/
117+
public function pull(DocumentInterface $document)
118+
{
119+
foreach ($this->adapters as $adapter) {
120+
try {
121+
return $adapter->pull($document);
122+
} catch (UnexpectedTypeException $e) {
123+
continue;
124+
}
125+
}
126+
127+
throw new InvalidArgumentException(sprintf('No adapter found for document "%s".', $document->getId()));
128+
}
129+
114130
/**
115131
* {@inheritdoc}
116132
*/

lib/Textmaster/Translator/TranslatorInterface.php

+13-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
interface TranslatorInterface
1717
{
1818
/**
19-
* Launch a translation.
19+
* Push document to textmaster.
2020
*
2121
* @param mixed $subject
2222
* @param mixed|DocumentInterface $documentOrParams Either pass a document instance
@@ -25,7 +25,7 @@ interface TranslatorInterface
2525
*
2626
* @return DocumentInterface
2727
*/
28-
public function create($subject, $documentOrParams = null, $save = true);
28+
public function push($subject, $documentOrParams = null, $save = true);
2929

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

3939
/**
40-
* Complete a translation.
40+
* Complete a document.
4141
*
4242
* @param DocumentInterface $document
4343
* @param string $satisfaction
4444
* @param string $message
4545
*
46-
* @return mixed The subject passed on creation.
46+
* @return DocumentInterface
4747
*/
4848
public function complete(DocumentInterface $document, $satisfaction = null, $message = null);
4949

50+
/**
51+
* Pull document from textmaster.
52+
*
53+
* @param DocumentInterface $document
54+
*
55+
* @return mixed The subject passed on creation.
56+
*/
57+
public function pull(DocumentInterface $document);
58+
5059
/**
5160
* Get subject from document.
5261
*

test/Textmaster/Unit/Translator/Adapter/GedmoTranslatableAdapterTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function shouldCreateSameLocale()
5252
->willReturn('en');
5353

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

5858
/**
@@ -95,6 +95,6 @@ public function shouldCreateDifferentLocale()
9595
->method('refresh');
9696

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

test/Textmaster/Unit/Translator/Adapter/SyliusTranslatableAdapterTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function shouldCreate()
7272
->willReturn(1);
7373

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

7878
/**
@@ -125,7 +125,7 @@ public function shouldComplete()
125125
->willReturn(ProjectInterface::ACTIVITY_TRANSLATION);
126126

127127
$adapter = new SyliusTranslatableAdapter($managerRegistryMock);
128-
$subject = $adapter->complete($documentMock);
128+
$subject = $adapter->pull($documentMock);
129129

130130
$this->assertSame($translatableMock, $subject);
131131
$this->assertSame('my translation', $translationMock->getName());

test/Textmaster/Unit/Translator/TranslatorTest.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ public function shouldCreate()
3737
->willReturn(true);
3838

3939
$adapterMock->expects($this->once())
40-
->method('create')
40+
->method('push')
4141
->willReturn($documentMock);
4242

4343
$translator = new Translator($adapters, $mappingProviderMock);
44-
$translator->create($subjectMock, $documentMock);
44+
$translator->push($subjectMock, $documentMock);
4545
}
4646

4747
/**
@@ -70,11 +70,11 @@ public function shouldCreateFromFactory()
7070
->willReturn(true);
7171

7272
$adapterMock->expects($this->once())
73-
->method('create')
73+
->method('push')
7474
->willReturn($documentMock);
7575

7676
$translator = new Translator($adapters, $mappingProviderMock, $documentFactoryMock);
77-
$translator->create($subjectMock);
77+
$translator->push($subjectMock);
7878
}
7979

8080
/**
@@ -192,7 +192,7 @@ public function shouldNotCreate()
192192
->willReturn(false);
193193

194194
$translator = new Translator($adapters, $mappingProviderMock);
195-
$translator->create($subjectMock, $documentMock);
195+
$translator->push($subjectMock, $documentMock);
196196
}
197197

198198
/**
@@ -223,7 +223,7 @@ public function shouldNotCreateFromFactory()
223223
$subjectMock = $this->getMock('Subject');
224224

225225
$translator = new Translator($adapters, $mappingProviderMock);
226-
$translator->create($subjectMock);
226+
$translator->push($subjectMock);
227227
}
228228

229229
/**

0 commit comments

Comments
 (0)