PluginProbe
User Access Manager / trunk
User Access Manager vtrunk
2.3.20 2.3.19 2.3.18 2.3.17 2.3.16 2.3.15 2.3.14 2.3.13 trunk 0.6 0.6.1 0.6.2 0.7 0.7 Beta 0.7.0.1 0.8 0.8.0.1 0.8.0.2 0.9 0.9.1 0.9.1.1 0.9.1.2 0.9.1.3 0.9.1.4 1.0 All 136 releases
user-access-manager / src / Setup / Database / Column.php

Column.php in User Access Manager trunk, at src/Setup/Database/Column.php

70 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace UserAccessManager\Setup\Database;
6
7 class Column
8 {
9 public function __construct(
10 private string $name,
11 private string $type,
12 private bool $isNull = false,
13 private mixed $default = null,
14 private bool $isKey = false,
15 private bool $isAutoIncrement = false
16 ) {
17 }
18
19 public function getName(): string
20 {
21 return $this->name;
22 }
23
24 public function getType(): string
25 {
26 return $this->type;
27 }
28
29 public function getDefault(): int|string|null
30 {
31 return $this->default;
32 }
33
34 public function isNull(): bool
35 {
36 return $this->isNull;
37 }
38
39 public function isKey(): bool
40 {
41 return $this->isKey;
42 }
43
44 public function isAutoIncrement(): bool
45 {
46 return $this->isAutoIncrement;
47 }
48
49 public function __toString(): string
50 {
51 $nullConstraint = ($this->isNull) ? 'NULL' : 'NOT NULL';
52 // MySQL reports a declared INT as INT(11); normalise so schema comparison sees no difference.
53 $type = $this->type === 'INT(11)' ? 'INT' : $this->type;
54 $column = "`$this->name` $type $nullConstraint";
55
56 if ($this->default === null && $this->isNull) {
57 $column .= ' DEFAULT NULL';
58 } elseif ($this->default !== null) {
59 $defaultValue = is_numeric($this->default) === false ? "'$this->default'" : $this->default;
60 $column .= " DEFAULT $defaultValue";
61 }
62
63 if ($this->isAutoIncrement) {
64 $column .= ' AUTO_INCREMENT';
65 }
66
67 return $column;
68 }
69 }
70