-
Notifications
You must be signed in to change notification settings - Fork 122
Expand file tree
/
Copy pathAddCheckConstraint.php
More file actions
65 lines (56 loc) · 1.85 KB
/
AddCheckConstraint.php
File metadata and controls
65 lines (56 loc) · 1.85 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
65
<?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\Table\CheckConstraint;
use Migrations\Db\Table\TableMetadata;
class AddCheckConstraint extends Action
{
/**
* The check constraint to add
*
* @var \Migrations\Db\Table\CheckConstraint
*/
protected CheckConstraint $checkConstraint;
/**
* Constructor
*
* @param \Migrations\Db\Table\TableMetadata $table The table to add the check constraint to
* @param \Migrations\Db\Table\CheckConstraint $checkConstraint The check constraint to add
*/
public function __construct(TableMetadata $table, CheckConstraint $checkConstraint)
{
parent::__construct($table);
$this->checkConstraint = $checkConstraint;
}
/**
* Creates a new AddCheckConstraint object after building the check constraint with
* the passed attributes
*
* @param \Migrations\Db\Table\TableMetadata $table The table object to add the check constraint to
* @param string $expression The check constraint expression (e.g., "age >= 18")
* @param array<string, mixed> $options Options for the check constraint (e.g., 'name')
* @return self
*/
public static function build(
TableMetadata $table,
string $expression,
array $options = [],
): self {
$name = $options['name'] ?? '';
$checkConstraint = new CheckConstraint($name, $expression);
return new AddCheckConstraint($table, $checkConstraint);
}
/**
* Returns the check constraint to be added
*
* @return \Migrations\Db\Table\CheckConstraint
*/
public function getCheckConstraint(): CheckConstraint
{
return $this->checkConstraint;
}
}