1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the MilioooMessageBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) Michiel boeckaert <[email protected]> |
7
|
|
|
* This source file is subject to the MIT license that is bundled |
8
|
|
|
* with this source code in the file LICENSE. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Miliooo\Messaging\Form\FormModelProcessor; |
12
|
|
|
|
13
|
|
|
use Miliooo\Messaging\Form\FormModel\NewThreadInterface; |
14
|
|
|
use Miliooo\Messaging\Builder\Message\NewThreadBuilder; |
15
|
|
|
use Miliooo\Messaging\Manager\NewMessageManagerInterface; |
16
|
|
|
use Miliooo\Messaging\Builder\Model\ThreadBuilderModel; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Processes a single thread. |
20
|
|
|
* |
21
|
|
|
* This processor processes a single thread by storing it to the database. |
22
|
|
|
* By single thread we mean that only one thread object gets created, it can have |
23
|
|
|
* multiple recipients. |
24
|
|
|
* |
25
|
|
|
* @author Michiel Boeckaert <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
class NewSingleThreadDefaultProcessor implements NewThreadFormProcessorInterface |
28
|
|
|
{ |
29
|
|
|
protected $newThreadBuilder; |
30
|
|
|
protected $newMessageManager; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Constructor. |
34
|
|
|
* |
35
|
|
|
* @param NewThreadBuilder $newThreadBuilder A new thread builder instance |
36
|
|
|
* @param NewMessageManagerInterface $newMessageManager A new message manager instance |
37
|
|
|
*/ |
38
|
|
|
public function __construct(NewThreadBuilder $newThreadBuilder, NewMessageManagerInterface $newMessageManager) |
39
|
|
|
{ |
40
|
|
|
$this->newThreadBuilder = $newThreadBuilder; |
41
|
|
|
$this->newMessageManager = $newMessageManager; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* {@inheritdoc} |
46
|
|
|
*/ |
47
|
|
|
public function process(NewThreadInterface $formModel) |
48
|
|
|
{ |
49
|
|
|
$threadBuilderModel = new ThreadBuilderModel($formModel); |
50
|
|
|
$thread = $this->newThreadBuilder->build($threadBuilderModel); |
51
|
|
|
$message = $thread->getLastMessage(); |
52
|
|
|
$this->newMessageManager->saveNewThread($message); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|