|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
// phpcs:disable |
|
3
|
|
|
namespace TemplateNamespace\Entity\Relations\TemplateEntity\Traits\HasRequiredTemplateEntities; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Common\Inflector\Inflector; |
|
6
|
|
|
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder; |
|
7
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException; |
|
8
|
|
|
use ReflectionException; |
|
9
|
|
|
use TemplateNamespace\Entities\TemplateEntity as TemplateEntity; |
|
10
|
|
|
use TemplateNamespace\Entity\Relations\TemplateEntity\Traits\HasRequiredTemplateEntitiesAbstract; |
|
11
|
|
|
use TemplateNamespace\Entity\Relations\TemplateEntity\Traits\ReciprocatesTemplateEntity; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Trait HasRequiredTemplateEntitiesInverseManyToMany |
|
15
|
|
|
* |
|
16
|
|
|
* The inverse side of a Many to Many relationship between the Current Entity |
|
17
|
|
|
* And TemplateEntity |
|
18
|
|
|
* |
|
19
|
|
|
* @see https://www.doctrine-project.org/projects/doctrine-orm/en/latest/reference/association-mapping.html#owning-and-inverse-side-on-a-manytomany-association |
|
20
|
|
|
* |
|
21
|
|
|
* @package TemplateNamespace\Entity\Relations\TemplateEntity\Traits\HasRequiredTemplateEntities |
|
22
|
|
|
*/ |
|
23
|
|
|
// phpcs:enable |
|
24
|
|
|
trait HasRequiredTemplateEntitiesInverseManyToMany |
|
25
|
|
|
{ |
|
26
|
|
|
use HasRequiredTemplateEntitiesAbstract; |
|
27
|
|
|
|
|
28
|
|
|
use ReciprocatesTemplateEntity; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param ClassMetadataBuilder $builder |
|
32
|
|
|
* |
|
33
|
|
|
* @throws DoctrineStaticMetaException |
|
34
|
|
|
* @throws ReflectionException |
|
35
|
|
|
* @SuppressWarnings(PHPMD.StaticAccess) |
|
36
|
|
|
*/ |
|
37
|
|
|
public static function metaForTemplateEntities( |
|
38
|
|
|
ClassMetadataBuilder $builder |
|
39
|
|
|
): void { |
|
40
|
|
|
$manyToManyBuilder = $builder->createManyToMany( |
|
41
|
|
|
TemplateEntity::getDoctrineStaticMeta()->getPlural(), |
|
42
|
|
|
TemplateEntity::class |
|
43
|
|
|
); |
|
44
|
|
|
$manyToManyBuilder->mappedBy(self::getDoctrineStaticMeta()->getPlural()); |
|
45
|
|
|
$fromTableName = Inflector::tableize(TemplateEntity::getDoctrineStaticMeta()->getPlural()); |
|
46
|
|
|
$toTableName = Inflector::tableize(self::getDoctrineStaticMeta()->getPlural()); |
|
47
|
|
|
$manyToManyBuilder->setJoinTable($fromTableName . '_to_' . $toTableName); |
|
48
|
|
|
$manyToManyBuilder->addJoinColumn( |
|
49
|
|
|
Inflector::tableize(self::getDoctrineStaticMeta()->getSingular() . '_' . static::PROP_ID), |
|
|
|
|
|
|
50
|
|
|
static::PROP_ID, |
|
51
|
|
|
true |
|
52
|
|
|
); |
|
53
|
|
|
$manyToManyBuilder->addInverseJoinColumn( |
|
54
|
|
|
Inflector::tableize( |
|
55
|
|
|
TemplateEntity::getDoctrineStaticMeta()->getSingular() |
|
56
|
|
|
) . '_' . TemplateEntity::PROP_ID, |
|
57
|
|
|
TemplateEntity::PROP_ID, |
|
58
|
|
|
true |
|
59
|
|
|
); |
|
60
|
|
|
$manyToManyBuilder->fetchExtraLazy(); |
|
61
|
|
|
$manyToManyBuilder->build(); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|