|
@@ -6,7 +6,7 @@ use Doctrine\Common\EventSubscriber,
|
|
|
Doctrine\ORM\Events,
|
|
|
Doctrine\ORM\Event\LifecycleEventArgs,
|
|
|
Doctrine\ORM\Event\OnFlushEventArgs,
|
|
|
- Doctrine\ORM\Event\LoadClassMetadataEventArgs,
|
|
|
+ Gedmo\Mapping\MappedEventSubscriber,
|
|
|
Doctrine\ORM\EntityManager,
|
|
|
Doctrine\ORM\Query,
|
|
|
Doctrine\ORM\Mapping\ClassMetadata,
|
|
@@ -32,7 +32,7 @@ use Doctrine\Common\EventSubscriber,
|
|
|
* @link http://www.gediminasm.org
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
|
|
*/
|
|
|
-class TranslationListener implements EventSubscriber
|
|
|
+class TranslationListener extends MappedEventSubscriber implements EventSubscriber
|
|
|
{
|
|
|
/**
|
|
|
* The translation entity class used to store the translations
|
|
@@ -50,22 +50,6 @@ class TranslationListener implements EventSubscriber
|
|
|
*/
|
|
|
protected $_locale = 'en_us';
|
|
|
|
|
|
- /**
|
|
|
- * ExtensionMetadataFactory used to read the extension
|
|
|
- * metadata
|
|
|
- *
|
|
|
- * @var Gedmo\Mapping\ExtensionMetadataFactory
|
|
|
- */
|
|
|
- protected $_extensionMetadataFactory = null;
|
|
|
-
|
|
|
- /**
|
|
|
- * List of metadata configurations for Translatable
|
|
|
- * classes, from annotations
|
|
|
- *
|
|
|
- * @var array
|
|
|
- */
|
|
|
- protected $_configurations = array();
|
|
|
-
|
|
|
/**
|
|
|
* Default locale, this changes behavior
|
|
|
* to not update the original record field if locale
|
|
@@ -101,27 +85,15 @@ class TranslationListener implements EventSubscriber
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Get the configuration for specific entity class
|
|
|
- * if cache driver is present it scans it also
|
|
|
+ /**
|
|
|
+ * Get the namespace of extension event subscriber.
|
|
|
+ * used to load mapping drivers and cache
|
|
|
*
|
|
|
- * @param EntityManager $em
|
|
|
- * @param string $class
|
|
|
- * @return array
|
|
|
+ * @return string
|
|
|
*/
|
|
|
- public function getConfiguration(EntityManager $em, $class) {
|
|
|
- $config = array();
|
|
|
- if (isset($this->_configurations[$class])) {
|
|
|
- $config = $this->_configurations[$class];
|
|
|
- } else {
|
|
|
- $cacheDriver = $em->getMetadataFactory()->getCacheDriver();
|
|
|
- $cacheId = ExtensionMetadataFactory::getCacheId($class, __NAMESPACE__);
|
|
|
- if (($cached = $cacheDriver->fetch($cacheId)) !== false) {
|
|
|
- $this->_configurations[$class] = $cached;
|
|
|
- $config = $cached;
|
|
|
- }
|
|
|
- }
|
|
|
- return $config;
|
|
|
+ protected function _getNamespace()
|
|
|
+ {
|
|
|
+ return __NAMESPACE__;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -191,38 +163,6 @@ class TranslationListener implements EventSubscriber
|
|
|
$this->_defaultLocale = $locale;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Get metadata mapping reader
|
|
|
- *
|
|
|
- * @param EntityManager $em
|
|
|
- * @return Gedmo\Mapping\MetadataReader
|
|
|
- */
|
|
|
- public function getExtensionMetadataFactory(EntityManager $em)
|
|
|
- {
|
|
|
- if (null === $this->_extensionMetadataFactory) {
|
|
|
- $this->_extensionMetadataFactory = new ExtensionMetadataFactory($em, __NAMESPACE__);
|
|
|
- }
|
|
|
- return $this->_extensionMetadataFactory;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Scans the entities for Translatable extension metadata
|
|
|
- *
|
|
|
- * @param LoadClassMetadataEventArgs $eventArgs
|
|
|
- * @throws RuntimeException if metadata driver is invalid
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
|
|
|
- {
|
|
|
- $meta = $eventArgs->getClassMetadata();
|
|
|
- $em = $eventArgs->getEntityManager();
|
|
|
- $factory = $this->getExtensionMetadataFactory($em);
|
|
|
- $config = $factory->getExtensionMetadata($meta);
|
|
|
- if ($config) {
|
|
|
- $this->_configurations[$meta->name] = $config;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Looks for translatable entities being inserted or updated
|
|
|
* for further processing
|