1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/* |
3
|
|
|
* This file is part of FlexPHP. |
4
|
|
|
* |
5
|
|
|
* (c) Freddie Gar <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
namespace FlexPHP\Database; |
11
|
|
|
|
12
|
|
|
use FlexPHP\Schema\SchemaAttributeInterface; |
13
|
|
|
|
14
|
|
|
final class Column implements ColumnInterface |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var SchemaAttributeInterface |
18
|
|
|
*/ |
19
|
|
|
private $schemaAttribute; |
20
|
|
|
|
21
|
7 |
|
public function __construct(SchemaAttributeInterface $schemaAttribute) |
22
|
|
|
{ |
23
|
7 |
|
$this->schemaAttribute = $schemaAttribute; |
24
|
7 |
|
} |
25
|
|
|
|
26
|
6 |
|
public function getName(): string |
27
|
|
|
{ |
28
|
6 |
|
return $this->schemaAttribute->name(); |
29
|
|
|
} |
30
|
|
|
|
31
|
6 |
|
public function getType(): string |
32
|
|
|
{ |
33
|
6 |
|
return $this->schemaAttribute->dataType(); |
34
|
|
|
} |
35
|
|
|
|
36
|
6 |
|
public function isPrimaryKey(): bool |
37
|
|
|
{ |
38
|
6 |
|
return $this->schemaAttribute->isPk(); |
39
|
|
|
} |
40
|
|
|
|
41
|
6 |
|
public function isForeingKey(): bool |
42
|
|
|
{ |
43
|
6 |
|
return $this->schemaAttribute->isFk(); |
44
|
|
|
} |
45
|
|
|
|
46
|
6 |
|
public function getOptions(): array |
47
|
|
|
{ |
48
|
|
|
return [ |
49
|
6 |
|
'length' => $this->schemaAttribute->maxLength(), |
50
|
6 |
|
'notnull' => $this->schemaAttribute->isRequired(), |
51
|
6 |
|
'autoincrement' => $this->schemaAttribute->isAi(), |
52
|
6 |
|
'comment' => $this->schemaAttribute->name(), |
53
|
|
|
// 'precision' => $this->schemaAttribute->name(), |
54
|
|
|
// 'scale' => $this->schemaAttribute->name(), |
55
|
|
|
// 'unsigned' => $this->schemaAttribute->name(), |
56
|
|
|
// 'fixed' => $this->schemaAttribute->name(), |
57
|
|
|
// 'default' => $this->schemaAttribute->name(), |
58
|
|
|
]; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|