|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the AsmTranslationLoaderBundle package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Marc Aschmann <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Asm\TranslationLoaderBundle\Model; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Base {@link TranslationManagerInterface} implementation (can be extended by |
|
18
|
|
|
* concrete implementations). |
|
19
|
|
|
* |
|
20
|
|
|
* @author Christian Flothmann <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
abstract class TranslationManager implements TranslationManagerInterface |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* Class implementing the {@link TranslationInterface} managed by this manager |
|
26
|
|
|
* |
|
27
|
|
|
* @var string |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $class; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var EventDispatcherInterface |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $eventDispatcher; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param string $class Class name of managed {@link TranslationInterface} objects |
|
38
|
|
|
* @param EventDispatcherInterface $eventDispatcher Event dispatcher used to propagate new, modified |
|
39
|
|
|
* and removed translations |
|
40
|
|
|
*/ |
|
41
|
10 |
|
public function __construct($class, EventDispatcherInterface $eventDispatcher) |
|
42
|
|
|
{ |
|
43
|
10 |
|
$this->class = $class; |
|
44
|
10 |
|
$this->eventDispatcher = $eventDispatcher; |
|
45
|
10 |
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* {@inheritdoc} |
|
49
|
|
|
*/ |
|
50
|
1 |
|
public function createTranslation() |
|
51
|
|
|
{ |
|
52
|
|
|
/** @var TranslationInterface $translation */ |
|
53
|
1 |
|
$translation = new $this->class(); |
|
54
|
1 |
|
$translation->setDateCreated(new \DateTime()); |
|
55
|
|
|
|
|
56
|
1 |
|
return $translation; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* {@inheritdoc} |
|
61
|
|
|
*/ |
|
62
|
1 |
|
public function findAllTranslations() |
|
63
|
|
|
{ |
|
64
|
1 |
|
return $this->findTranslationsBy(array()); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* {@inheritdoc} |
|
69
|
|
|
*/ |
|
70
|
1 |
|
public function findTranslationsByLocaleAndDomain($locale, $domain = 'messages') |
|
71
|
|
|
{ |
|
72
|
1 |
|
return $this->findTranslationsBy(array( |
|
73
|
1 |
|
'transLocale' => $locale, |
|
74
|
1 |
|
'messageDomain' => $domain, |
|
75
|
1 |
|
)); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|