[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorConfigColumnSchema 4 extends PhabricatorConfigStorageSchema { 5 6 private $characterSet; 7 private $collation; 8 private $columnType; 9 private $dataType; 10 private $nullable; 11 private $autoIncrement; 12 13 public function setAutoIncrement($auto_increment) { 14 $this->autoIncrement = $auto_increment; 15 return $this; 16 } 17 18 public function getAutoIncrement() { 19 return $this->autoIncrement; 20 } 21 22 public function setNullable($nullable) { 23 $this->nullable = $nullable; 24 return $this; 25 } 26 27 public function getNullable() { 28 return $this->nullable; 29 } 30 31 public function setColumnType($column_type) { 32 $this->columnType = $column_type; 33 return $this; 34 } 35 36 public function getColumnType() { 37 return $this->columnType; 38 } 39 40 protected function getSubschemata() { 41 return array(); 42 } 43 44 public function setDataType($data_type) { 45 $this->dataType = $data_type; 46 return $this; 47 } 48 49 public function getDataType() { 50 return $this->dataType; 51 } 52 53 public function setCollation($collation) { 54 $this->collation = $collation; 55 return $this; 56 } 57 58 public function getCollation() { 59 return $this->collation; 60 } 61 62 public function setCharacterSet($character_set) { 63 $this->characterSet = $character_set; 64 return $this; 65 } 66 67 public function getCharacterSet() { 68 return $this->characterSet; 69 } 70 71 public function getKeyByteLength($prefix = null) { 72 $type = $this->getColumnType(); 73 74 $matches = null; 75 if (preg_match('/^(?:var)?char\((\d+)\)$/', $type, $matches)) { 76 // For utf8mb4, each character requires 4 bytes. 77 $size = (int)$matches[1]; 78 if ($prefix && $prefix < $size) { 79 $size = $prefix; 80 } 81 return $size * 4; 82 } 83 84 $matches = null; 85 if (preg_match('/^(?:var)?binary\((\d+)\)$/', $type, $matches)) { 86 // binary()/varbinary() store fixed-length binary data, so their size 87 // is always the column size. 88 $size = (int)$matches[1]; 89 if ($prefix && $prefix < $size) { 90 $size = $prefix; 91 } 92 return $size; 93 } 94 95 // The "long..." types are arbitrarily long, so just use a big number to 96 // get the point across. In practice, these should always index only a 97 // prefix. 98 if ($type == 'longtext') { 99 $size = (1 << 16); 100 if ($prefix && $prefix < $size) { 101 $size = $prefix; 102 } 103 return $size * 4; 104 } 105 106 if ($type == 'longblob') { 107 $size = (1 << 16); 108 if ($prefix && $prefix < $size) { 109 $size = $prefix; 110 } 111 return $size * 1; 112 } 113 114 switch ($type) { 115 case 'int(10) unsigned': 116 return 4; 117 } 118 119 // TODO: Build this out to catch overlong indexes. 120 121 return 0; 122 } 123 124 public function compareToSimilarSchema( 125 PhabricatorConfigStorageSchema $expect) { 126 127 $issues = array(); 128 129 $type_unknown = PhabricatorConfigSchemaSpec::DATATYPE_UNKNOWN; 130 if ($expect->getColumnType() == $type_unknown) { 131 $issues[] = self::ISSUE_UNKNOWN; 132 } else { 133 if ($this->getCharacterSet() != $expect->getCharacterSet()) { 134 $issues[] = self::ISSUE_CHARSET; 135 } 136 137 if ($this->getCollation() != $expect->getCollation()) { 138 $issues[] = self::ISSUE_COLLATION; 139 } 140 141 if ($this->getColumnType() != $expect->getColumnType()) { 142 $issues[] = self::ISSUE_COLUMNTYPE; 143 } 144 145 if ($this->getNullable() !== $expect->getNullable()) { 146 $issues[] = self::ISSUE_NULLABLE; 147 } 148 149 if ($this->getAutoIncrement() !== $expect->getAutoIncrement()) { 150 $issues[] = self::ISSUE_AUTOINCREMENT; 151 } 152 } 153 154 return $issues; 155 } 156 157 public function newEmptyClone() { 158 $clone = clone $this; 159 return $clone; 160 } 161 162 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |