Exception
2 years ago
Visitor
9 months ago
AbstractAsset.php
2 years ago
AbstractSchemaManager.php
9 months ago
Column.php
2 years ago
ColumnDiff.php
2 years ago
Comparator.php
2 years ago
Constraint.php
2 years ago
DB2SchemaManager.php
2 years ago
DefaultSchemaManagerFactory.php
2 years ago
ForeignKeyConstraint.php
9 months ago
Identifier.php
2 years ago
Index.php
2 years ago
LegacySchemaManagerFactory.php
2 years ago
MySQLSchemaManager.php
9 months ago
OracleSchemaManager.php
2 years ago
PostgreSQLSchemaManager.php
9 months ago
SQLServerSchemaManager.php
9 months ago
Schema.php
2 years ago
SchemaConfig.php
2 years ago
SchemaDiff.php
2 years ago
SchemaException.php
2 years ago
SchemaManagerFactory.php
2 years ago
Sequence.php
2 years ago
SqliteSchemaManager.php
8 months ago
Table.php
2 years ago
TableDiff.php
2 years ago
UniqueConstraint.php
2 years ago
View.php
2 years ago
Column.php
206 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Doctrine\DBAL\Schema; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use MailPoetVendor\Doctrine\DBAL\Schema\Exception\UnknownColumnOption; |
| 5 | use MailPoetVendor\Doctrine\DBAL\Types\Type; |
| 6 | use MailPoetVendor\Doctrine\Deprecations\Deprecation; |
| 7 | use function array_merge; |
| 8 | use function is_numeric; |
| 9 | use function method_exists; |
| 10 | class Column extends AbstractAsset |
| 11 | { |
| 12 | protected $_type; |
| 13 | protected $_length; |
| 14 | protected $_precision = 10; |
| 15 | protected $_scale = 0; |
| 16 | protected $_unsigned = \false; |
| 17 | protected $_fixed = \false; |
| 18 | protected $_notnull = \true; |
| 19 | protected $_default; |
| 20 | protected $_autoincrement = \false; |
| 21 | protected $_platformOptions = []; |
| 22 | protected $_columnDefinition; |
| 23 | protected $_comment; |
| 24 | protected $_customSchemaOptions = []; |
| 25 | public function __construct($name, Type $type, array $options = []) |
| 26 | { |
| 27 | $this->_setName($name); |
| 28 | $this->setType($type); |
| 29 | $this->setOptions($options); |
| 30 | } |
| 31 | public function setOptions(array $options) |
| 32 | { |
| 33 | foreach ($options as $name => $value) { |
| 34 | $method = 'set' . $name; |
| 35 | if (!method_exists($this, $method)) { |
| 36 | throw UnknownColumnOption::new($name); |
| 37 | } |
| 38 | $this->{$method}($value); |
| 39 | } |
| 40 | return $this; |
| 41 | } |
| 42 | public function setType(Type $type) |
| 43 | { |
| 44 | $this->_type = $type; |
| 45 | return $this; |
| 46 | } |
| 47 | public function setLength($length) |
| 48 | { |
| 49 | if ($length !== null) { |
| 50 | $this->_length = (int) $length; |
| 51 | } else { |
| 52 | $this->_length = null; |
| 53 | } |
| 54 | return $this; |
| 55 | } |
| 56 | public function setPrecision($precision) |
| 57 | { |
| 58 | if (!is_numeric($precision)) { |
| 59 | $precision = 10; |
| 60 | // defaults to 10 when no valid precision is given. |
| 61 | } |
| 62 | $this->_precision = (int) $precision; |
| 63 | return $this; |
| 64 | } |
| 65 | public function setScale($scale) |
| 66 | { |
| 67 | if (!is_numeric($scale)) { |
| 68 | $scale = 0; |
| 69 | } |
| 70 | $this->_scale = (int) $scale; |
| 71 | return $this; |
| 72 | } |
| 73 | public function setUnsigned($unsigned) |
| 74 | { |
| 75 | $this->_unsigned = (bool) $unsigned; |
| 76 | return $this; |
| 77 | } |
| 78 | public function setFixed($fixed) |
| 79 | { |
| 80 | $this->_fixed = (bool) $fixed; |
| 81 | return $this; |
| 82 | } |
| 83 | public function setNotnull($notnull) |
| 84 | { |
| 85 | $this->_notnull = (bool) $notnull; |
| 86 | return $this; |
| 87 | } |
| 88 | public function setDefault($default) |
| 89 | { |
| 90 | $this->_default = $default; |
| 91 | return $this; |
| 92 | } |
| 93 | public function setPlatformOptions(array $platformOptions) |
| 94 | { |
| 95 | $this->_platformOptions = $platformOptions; |
| 96 | return $this; |
| 97 | } |
| 98 | public function setPlatformOption($name, $value) |
| 99 | { |
| 100 | $this->_platformOptions[$name] = $value; |
| 101 | return $this; |
| 102 | } |
| 103 | public function setColumnDefinition($value) |
| 104 | { |
| 105 | $this->_columnDefinition = $value; |
| 106 | return $this; |
| 107 | } |
| 108 | public function getType() |
| 109 | { |
| 110 | return $this->_type; |
| 111 | } |
| 112 | public function getLength() |
| 113 | { |
| 114 | return $this->_length; |
| 115 | } |
| 116 | public function getPrecision() |
| 117 | { |
| 118 | return $this->_precision; |
| 119 | } |
| 120 | public function getScale() |
| 121 | { |
| 122 | return $this->_scale; |
| 123 | } |
| 124 | public function getUnsigned() |
| 125 | { |
| 126 | return $this->_unsigned; |
| 127 | } |
| 128 | public function getFixed() |
| 129 | { |
| 130 | return $this->_fixed; |
| 131 | } |
| 132 | public function getNotnull() |
| 133 | { |
| 134 | return $this->_notnull; |
| 135 | } |
| 136 | public function getDefault() |
| 137 | { |
| 138 | return $this->_default; |
| 139 | } |
| 140 | public function getPlatformOptions() |
| 141 | { |
| 142 | return $this->_platformOptions; |
| 143 | } |
| 144 | public function hasPlatformOption($name) |
| 145 | { |
| 146 | return isset($this->_platformOptions[$name]); |
| 147 | } |
| 148 | public function getPlatformOption($name) |
| 149 | { |
| 150 | return $this->_platformOptions[$name]; |
| 151 | } |
| 152 | public function getColumnDefinition() |
| 153 | { |
| 154 | return $this->_columnDefinition; |
| 155 | } |
| 156 | public function getAutoincrement() |
| 157 | { |
| 158 | return $this->_autoincrement; |
| 159 | } |
| 160 | public function setAutoincrement($flag) |
| 161 | { |
| 162 | $this->_autoincrement = $flag; |
| 163 | return $this; |
| 164 | } |
| 165 | public function setComment($comment) |
| 166 | { |
| 167 | $this->_comment = $comment; |
| 168 | return $this; |
| 169 | } |
| 170 | public function getComment() |
| 171 | { |
| 172 | return $this->_comment; |
| 173 | } |
| 174 | public function setCustomSchemaOption($name, $value) |
| 175 | { |
| 176 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5476', 'Column::setCustomSchemaOption() is deprecated. Use setPlatformOption() instead.'); |
| 177 | $this->_customSchemaOptions[$name] = $value; |
| 178 | return $this; |
| 179 | } |
| 180 | public function hasCustomSchemaOption($name) |
| 181 | { |
| 182 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5476', 'Column::hasCustomSchemaOption() is deprecated. Use hasPlatformOption() instead.'); |
| 183 | return isset($this->_customSchemaOptions[$name]); |
| 184 | } |
| 185 | public function getCustomSchemaOption($name) |
| 186 | { |
| 187 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5476', 'Column::getCustomSchemaOption() is deprecated. Use getPlatformOption() instead.'); |
| 188 | return $this->_customSchemaOptions[$name]; |
| 189 | } |
| 190 | public function setCustomSchemaOptions(array $customSchemaOptions) |
| 191 | { |
| 192 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5476', 'Column::setCustomSchemaOptions() is deprecated. Use setPlatformOptions() instead.'); |
| 193 | $this->_customSchemaOptions = $customSchemaOptions; |
| 194 | return $this; |
| 195 | } |
| 196 | public function getCustomSchemaOptions() |
| 197 | { |
| 198 | Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5476', 'Column::getCustomSchemaOptions() is deprecated. Use getPlatformOptions() instead.'); |
| 199 | return $this->_customSchemaOptions; |
| 200 | } |
| 201 | public function toArray() |
| 202 | { |
| 203 | return array_merge(['name' => $this->_name, 'type' => $this->_type, 'default' => $this->_default, 'notnull' => $this->_notnull, 'length' => $this->_length, 'precision' => $this->_precision, 'scale' => $this->_scale, 'fixed' => $this->_fixed, 'unsigned' => $this->_unsigned, 'autoincrement' => $this->_autoincrement, 'columnDefinition' => $this->_columnDefinition, 'comment' => $this->_comment], $this->_platformOptions, $this->_customSchemaOptions); |
| 204 | } |
| 205 | } |
| 206 |