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
FieldBuilder.php
121 lines
| 1 | <?php |
| 2 | declare (strict_types=1); |
| 3 | namespace MailPoetVendor\Doctrine\ORM\Mapping\Builder; |
| 4 | if (!defined('ABSPATH')) exit; |
| 5 | use function constant; |
| 6 | class FieldBuilder |
| 7 | { |
| 8 | private $builder; |
| 9 | private $mapping; |
| 10 | private $version; |
| 11 | private $generatedValue; |
| 12 | private $sequenceDef; |
| 13 | private $customIdGenerator; |
| 14 | public function __construct(ClassMetadataBuilder $builder, array $mapping) |
| 15 | { |
| 16 | $this->builder = $builder; |
| 17 | $this->mapping = $mapping; |
| 18 | } |
| 19 | public function length($length) |
| 20 | { |
| 21 | $this->mapping['length'] = $length; |
| 22 | return $this; |
| 23 | } |
| 24 | public function nullable($flag = \true) |
| 25 | { |
| 26 | $this->mapping['nullable'] = (bool) $flag; |
| 27 | return $this; |
| 28 | } |
| 29 | public function unique($flag = \true) |
| 30 | { |
| 31 | $this->mapping['unique'] = (bool) $flag; |
| 32 | return $this; |
| 33 | } |
| 34 | public function columnName($name) |
| 35 | { |
| 36 | $this->mapping['columnName'] = $name; |
| 37 | return $this; |
| 38 | } |
| 39 | public function precision($p) |
| 40 | { |
| 41 | $this->mapping['precision'] = $p; |
| 42 | return $this; |
| 43 | } |
| 44 | public function insertable(bool $flag = \true) : self |
| 45 | { |
| 46 | if (!$flag) { |
| 47 | $this->mapping['notInsertable'] = \true; |
| 48 | } |
| 49 | return $this; |
| 50 | } |
| 51 | public function updatable(bool $flag = \true) : self |
| 52 | { |
| 53 | if (!$flag) { |
| 54 | $this->mapping['notUpdatable'] = \true; |
| 55 | } |
| 56 | return $this; |
| 57 | } |
| 58 | public function scale($s) |
| 59 | { |
| 60 | $this->mapping['scale'] = $s; |
| 61 | return $this; |
| 62 | } |
| 63 | public function isPrimaryKey() |
| 64 | { |
| 65 | return $this->makePrimaryKey(); |
| 66 | } |
| 67 | public function makePrimaryKey() |
| 68 | { |
| 69 | $this->mapping['id'] = \true; |
| 70 | return $this; |
| 71 | } |
| 72 | public function option($name, $value) |
| 73 | { |
| 74 | $this->mapping['options'][$name] = $value; |
| 75 | return $this; |
| 76 | } |
| 77 | public function generatedValue($strategy = 'AUTO') |
| 78 | { |
| 79 | $this->generatedValue = $strategy; |
| 80 | return $this; |
| 81 | } |
| 82 | public function isVersionField() |
| 83 | { |
| 84 | $this->version = \true; |
| 85 | return $this; |
| 86 | } |
| 87 | public function setSequenceGenerator($sequenceName, $allocationSize = 1, $initialValue = 1) |
| 88 | { |
| 89 | $this->sequenceDef = ['sequenceName' => $sequenceName, 'allocationSize' => $allocationSize, 'initialValue' => $initialValue]; |
| 90 | return $this; |
| 91 | } |
| 92 | public function columnDefinition($def) |
| 93 | { |
| 94 | $this->mapping['columnDefinition'] = $def; |
| 95 | return $this; |
| 96 | } |
| 97 | public function setCustomIdGenerator($customIdGenerator) |
| 98 | { |
| 99 | $this->customIdGenerator = (string) $customIdGenerator; |
| 100 | return $this; |
| 101 | } |
| 102 | public function build() |
| 103 | { |
| 104 | $cm = $this->builder->getClassMetadata(); |
| 105 | if ($this->generatedValue) { |
| 106 | $cm->setIdGeneratorType(constant('MailPoetVendor\\Doctrine\\ORM\\Mapping\\ClassMetadata::GENERATOR_TYPE_' . $this->generatedValue)); |
| 107 | } |
| 108 | if ($this->version) { |
| 109 | $cm->setVersionMapping($this->mapping); |
| 110 | } |
| 111 | $cm->mapField($this->mapping); |
| 112 | if ($this->sequenceDef) { |
| 113 | $cm->setSequenceGeneratorDefinition($this->sequenceDef); |
| 114 | } |
| 115 | if ($this->customIdGenerator) { |
| 116 | $cm->setCustomGeneratorDefinition(['class' => $this->customIdGenerator]); |
| 117 | } |
| 118 | return $this->builder; |
| 119 | } |
| 120 | } |
| 121 |