1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Db\Mssql; |
6
|
|
|
|
7
|
|
|
use Yiisoft\Db\Expression\Expression; |
8
|
|
|
use Yiisoft\Db\Schema\Builder\AbstractColumn; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Provides a convenient way to create column schema for use with {@see Schema} for MSSQL Server. |
12
|
|
|
* |
13
|
|
|
* It has methods for specifying the properties of a column, such as its type, size, default value, and whether it |
14
|
|
|
* is nullable or not. It also provides a method for creating a column schema based on the specified properties. |
15
|
|
|
* |
16
|
|
|
* For example, the following code creates a column schema for an integer column: |
17
|
|
|
* |
18
|
|
|
* ```php |
19
|
|
|
* $column = (new Column(SchemaInterface::TYPE_INTEGER))->notNull()->defaultValue(0); |
20
|
|
|
* ``` |
21
|
|
|
* |
22
|
|
|
* Provides a fluent interface, which means that the methods can be chained together to create a column schema with |
23
|
|
|
* many properties in a single line of code. |
24
|
|
|
*/ |
25
|
|
|
final class Column extends AbstractColumn |
26
|
|
|
{ |
27
|
|
|
private bool $clustered = false; |
28
|
|
|
|
29
|
|
|
/** |
30
|
8 |
|
* @return Expression|string|null The default value of the column. |
31
|
|
|
*/ |
32
|
8 |
|
public function getDefault(): Expression|string|null |
33
|
3 |
|
{ |
34
|
|
|
if ($this->default instanceof Expression) { |
35
|
|
|
return $this->default; |
36
|
7 |
|
} |
37
|
|
|
|
38
|
|
|
return $this->buildDefaultValue(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function clustered(): self |
42
|
|
|
{ |
43
|
|
|
$this->format = '{type}{length}{notnull}{primarykey}{unique}{default}{check}{comment}{append}{clustered}'; |
44
|
|
|
$this->clustered = true; |
45
|
|
|
return $this; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function isClustered(): self |
49
|
|
|
{ |
50
|
|
|
$this->clustered = true; |
51
|
|
|
return $this; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Returns the complete column definition from input format. |
56
|
|
|
* |
57
|
|
|
* @param string $format The format of the definition. |
58
|
|
|
* |
59
|
|
|
* @return string A string containing the complete column definition. |
60
|
|
|
*/ |
61
|
|
|
protected function buildCompleteString(string $format): string |
62
|
|
|
{ |
63
|
|
|
$placeholderValues = [ |
64
|
|
|
'{type}' => $this->type, |
65
|
|
|
'{length}' => $this->buildLengthString(), |
66
|
|
|
'{unsigned}' => $this->buildUnsignedString(), |
67
|
|
|
'{notnull}' => $this->buildNotNullString(), |
68
|
|
|
'{primarykey}' => $this->buildPrimaryKeyString(), |
|
|
|
|
69
|
|
|
'{unique}' => $this->buildUniqueString(), |
70
|
|
|
'{default}' => $this->buildDefaultString(), |
71
|
|
|
'{check}' => $this->buildCheckString(), |
72
|
|
|
'{comment}' => $this->buildCommentString(), |
73
|
|
|
'{append}' => $this->buildAppendString(), |
74
|
|
|
'{clustered}' => $this->buildClustered(), |
75
|
|
|
]; |
76
|
|
|
|
77
|
|
|
return strtr($format, $placeholderValues); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
private function buildClustered(): string |
81
|
|
|
{ |
82
|
|
|
return $this->clustered ? ' CLUSTERED' : ''; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.