/
TranslatableMetadataListener.php
62 lines (54 loc) · 1.53 KB
/
TranslatableMetadataListener.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 Symfony CMF package.
*
* (c) 2011-2017 Symfony CMF
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Cmf\Bundle\CoreBundle\Doctrine\Phpcr;
use Doctrine\Common\EventSubscriber;
use Doctrine\Common\Persistence\Event\LoadClassMetadataEventArgs;
use Doctrine\ODM\PHPCR\Mapping\ClassMetadata;
/**
* Metadata listener for when the translations are globally defined.
*
* @author Lukas Kahwe Smith <smith@pooteeweet.org>
*/
class TranslatableMetadataListener implements EventSubscriber
{
/**
* @var string
*/
private $translationStrategy;
/**
* @param string $translationStrategy
*/
public function __construct($translationStrategy)
{
$this->translationStrategy = $translationStrategy;
}
/**
* @return array
*/
public function getSubscribedEvents()
{
return [
'loadClassMetadata',
];
}
/**
* Handle the load class metadata event: set the translation strategy.
*
* @param LoadClassMetadataEventArgs $eventArgs
*/
public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
{
/** @var $meta ClassMetadata */
$meta = $eventArgs->getClassMetadata();
if ($meta->getReflectionClass()->implementsInterface('Symfony\Cmf\Bundle\CoreBundle\Translatable\TranslatableInterface')) {
$meta->setTranslator($this->translationStrategy);
}
}
}