PluginProbe
User Access Manager / 2.1.6
User Access Manager v2.1.6
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 2.1.6, at src/Setup/Database/Column.php

152 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Column.php
4 *
5 * The Column class file.
6 *
7 * PHP versions 5
8 *
9 * @author Alexander Schneider <alexanderschneider85@gmail.com>
10 * @copyright 2008-2017 Alexander Schneider
11 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2
12 * @version SVN: $id$
13 * @link http://wordpress.org/extend/plugins/user-access-manager/
14 */
15 namespace UserAccessManager\Setup\Database;
16
17 /**
18 * Class Column
19 *
20 * @package UserAccessManager\Setup\Database
21 */
22 class Column
23 {
24 /**
25 * @var string
26 */
27 private $name;
28
29 /**
30 * @var string
31 */
32 private $type;
33
34 /**
35 * @var int|string
36 */
37 private $default = null;
38
39 /**
40 * @var bool
41 */
42 private $isNull;
43
44 /**
45 * @var bool
46 */
47 private $isKey;
48
49 /**
50 * @var bool
51 */
52 private $isAutoIncrement;
53
54 /**
55 * Column constructor.
56 *
57 * @param string $name
58 * @param string $type
59 * @param bool $isNull
60 * @param mixed $default
61 * @param bool $isKey
62 * @param bool $isAutoIncrement
63 */
64 public function __construct(
65 $name,
66 $type,
67 $isNull = false,
68 $default = null,
69 $isKey = false,
70 $isAutoIncrement = false
71 ) {
72 $this->name = $name;
73 $this->type = $type;
74 $this->isNull = $isNull;
75 $this->default = $default;
76 $this->isKey = $isKey;
77 $this->isAutoIncrement = $isAutoIncrement;
78 }
79
80 /**
81 * @return string
82 */
83 public function getName()
84 {
85 return $this->name;
86 }
87
88 /**
89 * @return string
90 */
91 public function getType()
92 {
93 return $this->type;
94 }
95
96 /**
97 * @return int|string
98 */
99 public function getDefault()
100 {
101 return $this->default;
102 }
103
104 /**
105 * @return bool
106 */
107 public function isNull()
108 {
109 return $this->isNull;
110 }
111
112 /**
113 * @return bool
114 */
115 public function isKey()
116 {
117 return $this->isKey;
118 }
119
120 /**
121 * @return bool
122 */
123 public function isAutoIncrement()
124 {
125 return $this->isAutoIncrement;
126 }
127
128 /**
129 * Returns a mysql column string.
130 *
131 * @return string
132 */
133 public function __toString()
134 {
135 $nullConstraint = ($this->isNull) ? 'NULL' : 'NOT NULL';
136 $column = "`{$this->name}` {$this->type} {$nullConstraint}";
137
138 if ($this->default === null && $this->isNull) {
139 $column .= ' DEFAULT NULL';
140 } elseif ($this->default !== null) {
141 $defaultValue = is_numeric($this->default) === false ? "'{$this->default}'" : $this->default;
142 $column .= " DEFAULT {$defaultValue}";
143 }
144
145 if ($this->isAutoIncrement) {
146 $column .= ' AUTO_INCREMENT';
147 }
148
149 return $column;
150 }
151 }
152