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
ClassMetadataBuilder.php
186 lines
| 1 | <?php |
| 2 | declare (strict_types=1); |
| 3 | namespace MailPoetVendor\Doctrine\ORM\Mapping\Builder; |
| 4 | if (!defined('ABSPATH')) exit; |
| 5 | use BackedEnum; |
| 6 | use MailPoetVendor\Doctrine\Deprecations\Deprecation; |
| 7 | use MailPoetVendor\Doctrine\ORM\Mapping\ClassMetadata; |
| 8 | use MailPoetVendor\Doctrine\ORM\Mapping\ClassMetadataInfo; |
| 9 | use function get_class; |
| 10 | class ClassMetadataBuilder |
| 11 | { |
| 12 | private $cm; |
| 13 | public function __construct(ClassMetadataInfo $cm) |
| 14 | { |
| 15 | if (!$cm instanceof ClassMetadata) { |
| 16 | Deprecation::trigger('doctrine/orm', 'https://github.com/doctrine/orm/pull/249', 'Passing an instance of %s to %s is deprecated, please pass a ClassMetadata instance instead.', get_class($cm), __METHOD__, ClassMetadata::class); |
| 17 | } |
| 18 | $this->cm = $cm; |
| 19 | } |
| 20 | public function getClassMetadata() |
| 21 | { |
| 22 | return $this->cm; |
| 23 | } |
| 24 | public function setMappedSuperClass() |
| 25 | { |
| 26 | $this->cm->isMappedSuperclass = \true; |
| 27 | $this->cm->isEmbeddedClass = \false; |
| 28 | return $this; |
| 29 | } |
| 30 | public function setEmbeddable() |
| 31 | { |
| 32 | $this->cm->isEmbeddedClass = \true; |
| 33 | $this->cm->isMappedSuperclass = \false; |
| 34 | return $this; |
| 35 | } |
| 36 | public function addEmbedded($fieldName, $class, $columnPrefix = null) |
| 37 | { |
| 38 | $this->cm->mapEmbedded(['fieldName' => $fieldName, 'class' => $class, 'columnPrefix' => $columnPrefix]); |
| 39 | return $this; |
| 40 | } |
| 41 | public function setCustomRepositoryClass($repositoryClassName) |
| 42 | { |
| 43 | $this->cm->setCustomRepositoryClass($repositoryClassName); |
| 44 | return $this; |
| 45 | } |
| 46 | public function setReadOnly() |
| 47 | { |
| 48 | $this->cm->markReadOnly(); |
| 49 | return $this; |
| 50 | } |
| 51 | public function setTable($name) |
| 52 | { |
| 53 | $this->cm->setPrimaryTable(['name' => $name]); |
| 54 | return $this; |
| 55 | } |
| 56 | public function addIndex(array $columns, $name) |
| 57 | { |
| 58 | if (!isset($this->cm->table['indexes'])) { |
| 59 | $this->cm->table['indexes'] = []; |
| 60 | } |
| 61 | $this->cm->table['indexes'][$name] = ['columns' => $columns]; |
| 62 | return $this; |
| 63 | } |
| 64 | public function addUniqueConstraint(array $columns, $name) |
| 65 | { |
| 66 | if (!isset($this->cm->table['uniqueConstraints'])) { |
| 67 | $this->cm->table['uniqueConstraints'] = []; |
| 68 | } |
| 69 | $this->cm->table['uniqueConstraints'][$name] = ['columns' => $columns]; |
| 70 | return $this; |
| 71 | } |
| 72 | public function addNamedQuery($name, $dqlQuery) |
| 73 | { |
| 74 | $this->cm->addNamedQuery(['name' => $name, 'query' => $dqlQuery]); |
| 75 | return $this; |
| 76 | } |
| 77 | public function setJoinedTableInheritance() |
| 78 | { |
| 79 | $this->cm->setInheritanceType(ClassMetadata::INHERITANCE_TYPE_JOINED); |
| 80 | return $this; |
| 81 | } |
| 82 | public function setSingleTableInheritance() |
| 83 | { |
| 84 | $this->cm->setInheritanceType(ClassMetadata::INHERITANCE_TYPE_SINGLE_TABLE); |
| 85 | return $this; |
| 86 | } |
| 87 | public function setDiscriminatorColumn($name, $type = 'string', $length = 255, ?string $columnDefinition = null, ?string $enumType = null, array $options = []) |
| 88 | { |
| 89 | $this->cm->setDiscriminatorColumn(['name' => $name, 'type' => $type, 'length' => $length, 'columnDefinition' => $columnDefinition, 'enumType' => $enumType, 'options' => $options]); |
| 90 | return $this; |
| 91 | } |
| 92 | public function addDiscriminatorMapClass($name, $class) |
| 93 | { |
| 94 | $this->cm->addDiscriminatorMapClass($name, $class); |
| 95 | return $this; |
| 96 | } |
| 97 | public function setChangeTrackingPolicyDeferredExplicit() |
| 98 | { |
| 99 | $this->cm->setChangeTrackingPolicy(ClassMetadata::CHANGETRACKING_DEFERRED_EXPLICIT); |
| 100 | return $this; |
| 101 | } |
| 102 | public function setChangeTrackingPolicyNotify() |
| 103 | { |
| 104 | $this->cm->setChangeTrackingPolicy(ClassMetadata::CHANGETRACKING_NOTIFY); |
| 105 | return $this; |
| 106 | } |
| 107 | public function addLifecycleEvent($methodName, $event) |
| 108 | { |
| 109 | $this->cm->addLifecycleCallback($methodName, $event); |
| 110 | return $this; |
| 111 | } |
| 112 | public function addField($name, $type, array $mapping = []) |
| 113 | { |
| 114 | $mapping['fieldName'] = $name; |
| 115 | $mapping['type'] = $type; |
| 116 | $this->cm->mapField($mapping); |
| 117 | return $this; |
| 118 | } |
| 119 | public function createField($name, $type) |
| 120 | { |
| 121 | return new FieldBuilder($this, ['fieldName' => $name, 'type' => $type]); |
| 122 | } |
| 123 | public function createEmbedded($fieldName, $class) |
| 124 | { |
| 125 | return new EmbeddedBuilder($this, ['fieldName' => $fieldName, 'class' => $class, 'columnPrefix' => null]); |
| 126 | } |
| 127 | public function addManyToOne($name, $targetEntity, $inversedBy = null) |
| 128 | { |
| 129 | $builder = $this->createManyToOne($name, $targetEntity); |
| 130 | if ($inversedBy) { |
| 131 | $builder->inversedBy($inversedBy); |
| 132 | } |
| 133 | return $builder->build(); |
| 134 | } |
| 135 | public function createManyToOne($name, $targetEntity) |
| 136 | { |
| 137 | return new AssociationBuilder($this, ['fieldName' => $name, 'targetEntity' => $targetEntity], ClassMetadata::MANY_TO_ONE); |
| 138 | } |
| 139 | public function createOneToOne($name, $targetEntity) |
| 140 | { |
| 141 | return new AssociationBuilder($this, ['fieldName' => $name, 'targetEntity' => $targetEntity], ClassMetadata::ONE_TO_ONE); |
| 142 | } |
| 143 | public function addInverseOneToOne($name, $targetEntity, $mappedBy) |
| 144 | { |
| 145 | $builder = $this->createOneToOne($name, $targetEntity); |
| 146 | $builder->mappedBy($mappedBy); |
| 147 | return $builder->build(); |
| 148 | } |
| 149 | public function addOwningOneToOne($name, $targetEntity, $inversedBy = null) |
| 150 | { |
| 151 | $builder = $this->createOneToOne($name, $targetEntity); |
| 152 | if ($inversedBy) { |
| 153 | $builder->inversedBy($inversedBy); |
| 154 | } |
| 155 | return $builder->build(); |
| 156 | } |
| 157 | public function createManyToMany($name, $targetEntity) |
| 158 | { |
| 159 | return new ManyToManyAssociationBuilder($this, ['fieldName' => $name, 'targetEntity' => $targetEntity], ClassMetadata::MANY_TO_MANY); |
| 160 | } |
| 161 | public function addOwningManyToMany($name, $targetEntity, $inversedBy = null) |
| 162 | { |
| 163 | $builder = $this->createManyToMany($name, $targetEntity); |
| 164 | if ($inversedBy) { |
| 165 | $builder->inversedBy($inversedBy); |
| 166 | } |
| 167 | return $builder->build(); |
| 168 | } |
| 169 | public function addInverseManyToMany($name, $targetEntity, $mappedBy) |
| 170 | { |
| 171 | $builder = $this->createManyToMany($name, $targetEntity); |
| 172 | $builder->mappedBy($mappedBy); |
| 173 | return $builder->build(); |
| 174 | } |
| 175 | public function createOneToMany($name, $targetEntity) |
| 176 | { |
| 177 | return new OneToManyAssociationBuilder($this, ['fieldName' => $name, 'targetEntity' => $targetEntity], ClassMetadata::ONE_TO_MANY); |
| 178 | } |
| 179 | public function addOneToMany($name, $targetEntity, $mappedBy) |
| 180 | { |
| 181 | $builder = $this->createOneToMany($name, $targetEntity); |
| 182 | $builder->mappedBy($mappedBy); |
| 183 | return $builder->build(); |
| 184 | } |
| 185 | } |
| 186 |