Browse Source

added translation interface and interface checker into ObjectTranslator

everzet 13 years ago
parent
commit
f56915ed56

+ 8 - 0
lib/Gedmo/Translator/ObjectTranslator.php

@@ -36,6 +36,14 @@ class ObjectTranslator
         $this->class        = $class;
         $this->coll         = $coll;
 
+        $translationClass = new \ReflectionClass($class);
+        if (!$translationClass->implementsInterface('Gedmo\Translator\TranslationInterface')) {
+            throw new \InvalidArgumentException(sprintf(
+                'Translation class should implement Gedmo\Translator\TranslationInterface, "%s" given',
+                $class
+            ));
+        }
+
         $translatableClass = new \ReflectionObject($translatable);
         foreach ($properties as $property) {
             $translatableProperty = $translatableClass->getProperty($property);

+ 1 - 1
lib/Gedmo/Translator/Translation.php

@@ -2,7 +2,7 @@
 
 namespace Gedmo\Translator;
 
-abstract class Translation
+abstract class Translation implements TranslationInterface
 {
     protected $translatable;
     protected $locale;

+ 63 - 0
lib/Gedmo/Translator/TranslationInterface.php

@@ -0,0 +1,63 @@
+<?php
+
+namespace Gedmo\Translator;
+
+interface TranslationInterface
+{
+    /**
+     * Set translatable
+     *
+     * @param string $translatable
+     */
+    function setTranslatable($translatable);
+
+    /**
+     * Get translatable
+     *
+     * @return string $translatable
+     */
+    function getTranslatable();
+
+    /**
+     * Set locale
+     *
+     * @param string $locale
+     */
+    function setLocale($locale);
+
+    /**
+     * Get locale
+     *
+     * @return string $locale
+     */
+    function getLocale();
+
+    /**
+     * Set property
+     *
+     * @param string $field
+     */
+    function setProperty($property);
+
+    /**
+     * Get property
+     *
+     * @return string $field
+     */
+    function getProperty();
+
+    /**
+     * Set value
+     *
+     * @param text $value
+     * @return AbstractTranslation
+     */
+    function setValue($value);
+
+    /**
+     * Get value
+     *
+     * @return text $value
+     */
+    function getValue();
+}