Skip to content

Commit

Permalink
Revert "Use doctrine attributes alongside annotations"
Browse files Browse the repository at this point in the history
This reverts commit adc22d4.
  • Loading branch information
relthyg committed Apr 3, 2024
1 parent a53027f commit fa293ca
Show file tree
Hide file tree
Showing 9 changed files with 264 additions and 121 deletions.
6 changes: 0 additions & 6 deletions src/Entity/BaseTranslation.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
/**
* @ORM\MappedSuperclass
*/
#[ORM\MappedSuperclass]
class BaseTranslation
{
/**
Expand All @@ -26,9 +25,6 @@ class BaseTranslation
*
* @ORM\Column(type="integer")
*/
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
protected $id;

/**
Expand All @@ -37,13 +33,11 @@ class BaseTranslation
* @PolyglotAnnotation\Locale
*/
#[Polyglot\Locale]
#[ORM\Column]
protected $locale;

/**
* @ORM\JoinColumn(name="entity_id", referencedColumnName="id", nullable=false)
*/
#[ORM\JoinColumn(name: 'entity_id', referencedColumnName: 'id', nullable: false)]
protected $entity;

public function getLocale()
Expand Down
49 changes: 34 additions & 15 deletions tests/Functional/CascadePersistTranslationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,33 @@ public function adding_and_persisting_translations(): void
}
}

/**
* @ORM\Entity
*/
#[Polyglot\Locale(primary: 'en_GB')]
#[ORM\Entity]
class CascadePersistTranslationsTest_Entity
{

#[ORM\Column(type: 'integer')]
#[ORM\Id]
#[ORM\GeneratedValue]
/**
* @ORM\Column(type="integer")
*
* @ORM\Id
*
* @ORM\GeneratedValue
*/
private ?int $id = null;

/**
* (!) There is *not* cascade="persist" configuration here.
*
* @ORM\OneToMany(targetEntity="CascadePersistTranslationsTest_Translation", mappedBy="entity")
*/
#[Polyglot\TranslationCollection]
#[ORM\OneToMany(targetEntity: \CascadePersistTranslationsTest_Translation::class, mappedBy: 'entity')]
protected Collection $translations;

/**
* @ORM\Column(type="string")
*/
#[Polyglot\Translatable]
#[ORM\Column(type: 'string')]
protected string|TranslatableInterface $text;

public function __construct()
Expand All @@ -77,22 +85,33 @@ public function addTranslation(string $locale, mixed $text): void
}
}

#[ORM\Entity]
/**
* @ORM\Entity
*/
class CascadePersistTranslationsTest_Translation
{

#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*/
private ?int $id = null;

/**
* @ORM\Column
*/
#[Polyglot\Locale]
#[ORM\Column]
private string $locale;

#[ORM\ManyToOne(targetEntity: \CascadePersistTranslationsTest_Entity::class, inversedBy: 'translations')]
/**
* @ORM\ManyToOne(targetEntity="CascadePersistTranslationsTest_Entity", inversedBy="translations")
*/
private CascadePersistTranslationsTest_Entity $entity;

#[ORM\Column]
/**
* @ORM\Column
*/
private string $text;
}
99 changes: 69 additions & 30 deletions tests/Functional/EntityInheritanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,28 +101,39 @@ public function testUpdateTranslations(): void
}
}


/**
* @ORM\Entity()
*
* @ORM\InheritanceType(value="SINGLE_TABLE")
*
* @ORM\DiscriminatorMap({"base"="EntityInheritance_BaseEntityClass", "child"="EntityInheritance_ChildEntityClass"})
*
* @ORM\DiscriminatorColumn(name="discriminator", type="string")
*/
#[Polyglot\Locale(primary: 'en_GB')]
#[ORM\Entity]
#[ORM\InheritanceType(value: 'SINGLE_TABLE')]
#[ORM\DiscriminatorMap(['base' => 'EntityInheritance_BaseEntityClass', 'child' => 'EntityInheritance_ChildEntityClass'])]
#[ORM\DiscriminatorColumn(name: 'discriminator', type: 'string')]
class EntityInheritance_BaseEntityClass
{

#[ORM\Column(type: 'integer')]
#[ORM\Id]
#[ORM\GeneratedValue]
/**
* @ORM\Column(type="integer")
*
* @ORM\Id
*
* @ORM\GeneratedValue
*/
private ?int $id = null;

private string $discriminator;

/**
* @ORM\OneToMany(targetEntity="EntityInheritance_BaseEntityClassTranslation", mappedBy="entity")
*/
#[Polyglot\TranslationCollection]
#[ORM\OneToMany(targetEntity: \EntityInheritance_BaseEntityClassTranslation::class, mappedBy: 'entity')]
private Collection $translations;

/**
* @ORM\Column(type="string")
*/
#[Polyglot\Translatable]
#[ORM\Column(type: 'string')]
private TranslatableInterface|string|null $text = null;

public function __construct()
Expand All @@ -146,35 +157,52 @@ public function getText(): TranslatableInterface
}
}

#[ORM\Entity]
/**
* @ORM\Entity
*/
class EntityInheritance_BaseEntityClassTranslation
{

#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*/
private ?int $id = null;

/**
* @ORM\Column
*/
#[Polyglot\Locale]
#[ORM\Column]
private string $locale;

#[ORM\ManyToOne(targetEntity: \EntityInheritance_BaseEntityClass::class, inversedBy: 'translations')]
/**
* @ORM\ManyToOne(targetEntity="EntityInheritance_BaseEntityClass", inversedBy="translations")
*/
private EntityInheritance_BaseEntityClass $entity;

#[ORM\Column]
/**
* @ORM\Column()
*/
private string $text;
}

#[ORM\Entity]
/**
* @ORM\Entity
*/
class EntityInheritance_ChildEntityClass extends EntityInheritance_BaseEntityClass
{
/**
* @ORM\Column(type="string")
*/
#[Polyglot\Translatable]
#[ORM\Column(type: 'string')]
private TranslatableInterface|string|null $extraText = null;

/**
* @ORM\OneToMany(targetEntity="EntityInheritance_ChildEntityClassTranslation", mappedBy="entity")
*/
#[Polyglot\TranslationCollection]
#[ORM\OneToMany(targetEntity: \EntityInheritance_ChildEntityClassTranslation::class, mappedBy: 'entity')]
private Collection $extraTranslations;

public function __construct()
Expand All @@ -194,22 +222,33 @@ public function getExtraText(): TranslatableInterface
}
}

#[ORM\Entity]
/**
* @ORM\Entity
*/
class EntityInheritance_ChildEntityClassTranslation
{

#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*/
private ?int $id = null;

/**
* @ORM\Column
*/
#[Polyglot\Locale]
#[ORM\Column]
private string $locale;

#[ORM\ManyToOne(targetEntity: \EntityInheritance_ChildEntityClass::class, inversedBy: 'extraTranslations')]
/**
* @ORM\ManyToOne(targetEntity="EntityInheritance_ChildEntityClass", inversedBy="extraTranslations")
*/
private EntityInheritance_ChildEntityClass $entity;

#[ORM\Column]
/**
* @ORM\Column()
*/
private string $extraText;
}
49 changes: 34 additions & 15 deletions tests/Functional/StronglyTypedTranslationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,25 +188,33 @@ public function flush_updated_entity_two_times_does_not_update(): void
}
}

/**
* @ORM\Entity
*/
#[Polyglot\Locale(primary: 'en_GB')]
#[ORM\Entity]
class StronglyTypedTranslationsTest_Entity
{

#[ORM\Column(type: 'integer')]
#[ORM\Id]
#[ORM\GeneratedValue]
/**
* @ORM\Column(type="integer")
*
* @ORM\Id
*
* @ORM\GeneratedValue
*/
public ?int $id = null;

/**
* @ORM\OneToMany(targetEntity="StronglyTypedTranslationsTest_Translation", mappedBy="entity")
*/
#[Polyglot\TranslationCollection]
#[ORM\OneToMany(targetEntity: \StronglyTypedTranslationsTest_Translation::class, mappedBy: 'entity')]
public Collection $translations;

/**
* @var TranslatableInterface<string>
*
* @ORM\Column(type="translatable_string", options={"use_text_column": true})
*/
#[Polyglot\Translatable]
#[ORM\Column(type: 'translatable_string', options: ['use_text_column' => true])]
public TranslatableInterface $text;

public function __construct()
Expand All @@ -216,22 +224,33 @@ public function __construct()
}
}

#[ORM\Entity]
/**
* @ORM\Entity
*/
class StronglyTypedTranslationsTest_Translation
{

#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*/
public ?int $id = null;

/**
* @ORM\Column
*/
#[Polyglot\Locale]
#[ORM\Column]
public string $locale;

#[ORM\ManyToOne(targetEntity: \StronglyTypedTranslationsTest_Entity::class, inversedBy: 'translations')]
/**
* @ORM\ManyToOne(targetEntity="StronglyTypedTranslationsTest_Entity", inversedBy="translations")
*/
public StronglyTypedTranslationsTest_Entity $entity;

#[ORM\Column]
/**
* @ORM\Column
*/
public string $text;
}
Loading

0 comments on commit fa293ca

Please sign in to comment.