-
Notifications
You must be signed in to change notification settings - Fork 121
Expand file tree
/
Copy pathAddColumn.php
More file actions
64 lines (56 loc) · 1.69 KB
/
Copy pathAddColumn.php
File metadata and controls
64 lines (56 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
declare(strict_types=1);
/**
* MIT License
* For full license information, please view the LICENSE file that was distributed with this source code.
*/
namespace Migrations\Db\Action;
use Migrations\Db\Literal;
use Migrations\Db\Table\Column;
use Migrations\Db\Table\TableMetadata;
class AddColumn extends Action
{
/**
* The column to add
*
* @var \Migrations\Db\Table\Column
*/
protected Column $column;
/**
* Constructor
*
* @param \Migrations\Db\Table\TableMetadata $table The table to add the column to
* @param \Migrations\Db\Table\Column $column The column to add
*/
public function __construct(TableMetadata $table, Column $column)
{
parent::__construct($table);
$this->column = $column;
}
/**
* Returns a new AddColumn object after assembling the given commands
*
* @param \Migrations\Db\Table\TableMetadata $table The table to add the column to
* @param string $columnName The column name
* @param string|\Migrations\Db\Literal $type The column type
* @param array<string, mixed> $options The column options
* @return self
*/
public static function build(TableMetadata $table, string $columnName, string|Literal $type, array $options = []): self
{
$column = new Column();
$column->setName($columnName);
$column->setType($type);
$column->setOptions($options); // map options to column methods
return new AddColumn($table, $column);
}
/**
* Returns the column to be added
*
* @return \Migrations\Db\Table\Column
*/
public function getColumn(): Column
{
return $this->column;
}
}