Bläddra i källkod

[translatable] tramnslation repository is useless for personal translations, update readme

gedi 13 år sedan
förälder
incheckning
8c40921ed8

+ 4 - 2
README.md

@@ -17,9 +17,9 @@ objects anyway you prefere and still enjoy all features **Translatable** provide
 - There were **BC** breaks introduced in **master** branch of extensions which is
 based on **doctrine2.3.x** version. If you are not interested in upgrading you can
 safely checkout at **2.2.x** or **2.1.x** [tag](http://github.com/l3pp4rd/DoctrineExtensions/tags).
-To upgrade your source code follow the [upgrade guide](upgrade/2-3-0.md)
+To upgrade your source code follow the [upgrade guide](https://github.com/l3pp4rd/DoctrineExtensions/blob/master/upgrade/2-3-0.md)
 - Library now can map only **MappedSuperclass**es which would avoid generation of **ext_**
-tables which might not be used. Also it provides [convinient methods](lib/Gedmo/DoctrineExtensions.php#L66)
+tables which might not be used. Also it provides [convinient methods](https://github.com/l3pp4rd/DoctrineExtensions/blob/master/lib/Gedmo/DoctrineExtensions.php#L66)
 to hook extension metadata drivers into metadata driver chain.
 - [Example demo application](example/em.php) has a detailed configuration provided, which
 explains and shows how extensions can or should be used with **Doctrine2** ORM. To install
@@ -128,6 +128,8 @@ To setup and run tests follow these steps:
 - run: **phpunit -c tests**
 - optional - run mongodb in background to complete all tests
 
+<a name="example-demo"></a>
+
 ### Running the example:
 
 To setup and run example follow these steps:

+ 14 - 0
lib/Gedmo/Translatable/Document/Repository/TranslationRepository.php

@@ -5,6 +5,9 @@ namespace Gedmo\Translatable\Document\Repository;
 use Gedmo\Translatable\TranslatableListener;
 use Doctrine\ODM\MongoDB\DocumentRepository;
 use Doctrine\ODM\MongoDB\Cursor;
+use Doctrine\ODM\MongoDB\DocumentManager;
+use Doctrine\ODM\MongoDB\UnitOfWork;
+use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
 use Gedmo\Tool\Wrapper\MongoDocumentWrapper;
 use Gedmo\Translatable\Mapping\Event\Adapter\ODM as TranslatableAdapterODM;
 use Doctrine\ODM\MongoDB\Mapping\Types\Type;
@@ -29,6 +32,17 @@ class TranslationRepository extends DocumentRepository
      */
     private $listener;
 
+    /**
+     * {@inheritdoc}
+     */
+    public function __construct(DocumentManager $dm, UnitOfWork $uow, ClassMetadata $class)
+    {
+        if ($class->getReflectionClass()->isSubclassOf('Gedmo\Translatable\Document\MappedSuperclass\AbstractPersonalTranslation')) {
+            throw new \Gedmo\Exception\UnexpectedValueException('This repository is useless for personal translations');
+        }
+        parent::__construct($dm, $uow, $class);
+    }
+
     /**
      * Makes additional translation of $document $field into $locale
      * using $value

+ 13 - 0
lib/Gedmo/Translatable/Entity/Repository/TranslationRepository.php

@@ -5,6 +5,8 @@ namespace Gedmo\Translatable\Entity\Repository;
 use Gedmo\Translatable\TranslatableListener;
 use Doctrine\ORM\EntityRepository;
 use Doctrine\ORM\Query;
+use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\Mapping\ClassMetadata;
 use Gedmo\Tool\Wrapper\EntityWrapper;
 use Gedmo\Translatable\Mapping\Event\Adapter\ORM as TranslatableAdapterORM;
 use Doctrine\DBAL\Types\Type;
@@ -29,6 +31,17 @@ class TranslationRepository extends EntityRepository
      */
     private $listener;
 
+    /**
+     * {@inheritdoc}
+     */
+    public function __construct(EntityManager $em, ClassMetadata $class)
+    {
+        if ($class->getReflectionClass()->isSubclassOf('Gedmo\Translatable\Entity\MappedSuperclass\AbstractPersonalTranslation')) {
+            throw new \Gedmo\Exception\UnexpectedValueException('This repository is useless for personal translations');
+        }
+        parent::__construct($em, $class);
+    }
+
     /**
      * Makes additional translation of $entity $field into $locale
      * using $value

+ 1 - 1
tests/Gedmo/Translatable/Fixture/Personal/PersonalArticleTranslation.php

@@ -6,7 +6,7 @@ use Gedmo\Translatable\Entity\MappedSuperclass\AbstractPersonalTranslation;
 
 /**
  * @ORM\Table(name="article_translations")
- * @ORM\Entity(repositoryClass="Gedmo\Translatable\Entity\Repository\TranslationRepository")
+ * @ORM\Entity
  */
 class PersonalArticleTranslation extends AbstractPersonalTranslation
 {