forked from FriendsOfSymfony/FOSCommentBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDefaultThreadCreator.php
62 lines (54 loc) · 1.5 KB
/
DefaultThreadCreator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/**
* This file is part of the FOSCommentBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace FOS\CommentBundle\Creator;
use FOS\CommentBundle\Model\ThreadInterface;
use FOS\CommentBundle\Model\ThreadManagerInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* Responsible for the creation and persistence of Thread objects.
*
* @author Thibault Duplessis <[email protected]
*/
class DefaultThreadCreator implements ThreadCreatorInterface
{
/**
* @var Request
*/
protected $request;
/**
* @var ThreadManagerInterface
*/
protected $threadManager;
/**
* Constructor.
*
* @param Request $request
* @param ThreadManagerInterface $threadManager
*/
public function __construct(Request $request, ThreadManagerInterface $threadManager)
{
$this->request = $request;
$this->threadManager = $threadManager;
}
/**
* Creates and persists a thread with the specified identifier.
*
* @param mixed $identifier
* @return ThreadInterface
*/
public function create($identifier)
{
$thread = $this->threadManager->createThread();
$thread->setIdentifier($identifier);
$thread->setPermalink($this->request->getUri());
$this->threadManager->addThread($thread);
return $thread;
}
}