AssociationBuilder.php
9 months ago
ClassMetadataBuilder.php
9 months ago
EmbeddedBuilder.php
9 months ago
EntityListenerBuilder.php
9 months ago
FieldBuilder.php
9 months ago
ManyToManyAssociationBuilder.php
9 months ago
OneToManyAssociationBuilder.php
9 months ago
index.php
9 months ago
AssociationBuilder.php
106 lines
| 1 | <?php |
| 2 | declare (strict_types=1); |
| 3 | namespace MailPoetVendor\Doctrine\ORM\Mapping\Builder; |
| 4 | if (!defined('ABSPATH')) exit; |
| 5 | use MailPoetVendor\Doctrine\ORM\Mapping\ClassMetadata; |
| 6 | use InvalidArgumentException; |
| 7 | class AssociationBuilder |
| 8 | { |
| 9 | protected $builder; |
| 10 | protected $mapping; |
| 11 | protected $joinColumns; |
| 12 | protected $type; |
| 13 | public function __construct(ClassMetadataBuilder $builder, array $mapping, $type) |
| 14 | { |
| 15 | $this->builder = $builder; |
| 16 | $this->mapping = $mapping; |
| 17 | $this->type = $type; |
| 18 | } |
| 19 | public function mappedBy($fieldName) |
| 20 | { |
| 21 | $this->mapping['mappedBy'] = $fieldName; |
| 22 | return $this; |
| 23 | } |
| 24 | public function inversedBy($fieldName) |
| 25 | { |
| 26 | $this->mapping['inversedBy'] = $fieldName; |
| 27 | return $this; |
| 28 | } |
| 29 | public function cascadeAll() |
| 30 | { |
| 31 | $this->mapping['cascade'] = ['ALL']; |
| 32 | return $this; |
| 33 | } |
| 34 | public function cascadePersist() |
| 35 | { |
| 36 | $this->mapping['cascade'][] = 'persist'; |
| 37 | return $this; |
| 38 | } |
| 39 | public function cascadeRemove() |
| 40 | { |
| 41 | $this->mapping['cascade'][] = 'remove'; |
| 42 | return $this; |
| 43 | } |
| 44 | public function cascadeMerge() |
| 45 | { |
| 46 | $this->mapping['cascade'][] = 'merge'; |
| 47 | return $this; |
| 48 | } |
| 49 | public function cascadeDetach() |
| 50 | { |
| 51 | $this->mapping['cascade'][] = 'detach'; |
| 52 | return $this; |
| 53 | } |
| 54 | public function cascadeRefresh() |
| 55 | { |
| 56 | $this->mapping['cascade'][] = 'refresh'; |
| 57 | return $this; |
| 58 | } |
| 59 | public function fetchExtraLazy() |
| 60 | { |
| 61 | $this->mapping['fetch'] = ClassMetadata::FETCH_EXTRA_LAZY; |
| 62 | return $this; |
| 63 | } |
| 64 | public function fetchEager() |
| 65 | { |
| 66 | $this->mapping['fetch'] = ClassMetadata::FETCH_EAGER; |
| 67 | return $this; |
| 68 | } |
| 69 | public function fetchLazy() |
| 70 | { |
| 71 | $this->mapping['fetch'] = ClassMetadata::FETCH_LAZY; |
| 72 | return $this; |
| 73 | } |
| 74 | public function addJoinColumn($columnName, $referencedColumnName, $nullable = \true, $unique = \false, $onDelete = null, $columnDef = null) |
| 75 | { |
| 76 | $this->joinColumns[] = ['name' => $columnName, 'referencedColumnName' => $referencedColumnName, 'nullable' => $nullable, 'unique' => $unique, 'onDelete' => $onDelete, 'columnDefinition' => $columnDef]; |
| 77 | return $this; |
| 78 | } |
| 79 | public function makePrimaryKey() |
| 80 | { |
| 81 | $this->mapping['id'] = \true; |
| 82 | return $this; |
| 83 | } |
| 84 | public function orphanRemoval() |
| 85 | { |
| 86 | $this->mapping['orphanRemoval'] = \true; |
| 87 | return $this; |
| 88 | } |
| 89 | public function build() |
| 90 | { |
| 91 | $mapping = $this->mapping; |
| 92 | if ($this->joinColumns) { |
| 93 | $mapping['joinColumns'] = $this->joinColumns; |
| 94 | } |
| 95 | $cm = $this->builder->getClassMetadata(); |
| 96 | if ($this->type === ClassMetadata::MANY_TO_ONE) { |
| 97 | $cm->mapManyToOne($mapping); |
| 98 | } elseif ($this->type === ClassMetadata::ONE_TO_ONE) { |
| 99 | $cm->mapOneToOne($mapping); |
| 100 | } else { |
| 101 | throw new InvalidArgumentException('Type should be a ToOne Association here'); |
| 102 | } |
| 103 | return $this->builder; |
| 104 | } |
| 105 | } |
| 106 |