|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace kalanis\kw_table\form_kw\Fields; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use kalanis\kw_connect\core\Interfaces\IIterableConnector; |
|
7
|
|
|
use kalanis\kw_forms\Form; |
|
8
|
|
|
use kalanis\kw_table\core\Interfaces\Form\IField; |
|
9
|
|
|
use kalanis\kw_table\core\TableException; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class AField |
|
14
|
|
|
* @package kalanis\kw_table\form_kw\Fields |
|
15
|
|
|
*/ |
|
16
|
|
|
abstract class AField implements IField |
|
17
|
|
|
{ |
|
18
|
|
|
protected ?Form $form = null; |
|
19
|
|
|
protected string $alias = ''; |
|
20
|
|
|
/** @var array<string, string> */ |
|
21
|
|
|
protected array $attributes = []; |
|
22
|
|
|
protected ?IIterableConnector $connector = null; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @param array<string, string> $attributes |
|
26
|
|
|
*/ |
|
27
|
23 |
|
public function __construct(array $attributes = []) |
|
28
|
|
|
{ |
|
29
|
23 |
|
$this->setAttributes($attributes); |
|
30
|
23 |
|
} |
|
31
|
|
|
|
|
32
|
16 |
|
public function setForm(Form $form): void |
|
33
|
|
|
{ |
|
34
|
16 |
|
$this->form = $form; |
|
35
|
16 |
|
} |
|
36
|
|
|
|
|
37
|
1 |
|
public function getForm(): ?Form |
|
38
|
|
|
{ |
|
39
|
1 |
|
return $this->form; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @throws TableException |
|
44
|
|
|
* @return Form |
|
45
|
|
|
*/ |
|
46
|
16 |
|
public function getFormInstance(): Form |
|
47
|
|
|
{ |
|
48
|
16 |
|
if (empty($this->form)) { |
|
49
|
1 |
|
throw new TableException('Set the form first!'); |
|
50
|
|
|
} |
|
51
|
15 |
|
return $this->form; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
20 |
|
public function setAlias(string $alias): void |
|
55
|
|
|
{ |
|
56
|
20 |
|
$this->alias = $alias; |
|
57
|
20 |
|
} |
|
58
|
|
|
|
|
59
|
2 |
|
public function getAlias(): string |
|
60
|
|
|
{ |
|
61
|
2 |
|
return $this->alias; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
7 |
|
public function setDataSourceConnector(IIterableConnector $dataSource): void |
|
65
|
|
|
{ |
|
66
|
7 |
|
$this->connector = $dataSource; |
|
67
|
7 |
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @throws TableException |
|
71
|
|
|
* @return IIterableConnector |
|
72
|
|
|
*/ |
|
73
|
2 |
|
public function getDataSourceConnectorInstance(): IIterableConnector |
|
74
|
|
|
{ |
|
75
|
2 |
|
if (empty($this->connector)) { |
|
76
|
1 |
|
throw new TableException('Set the datasource connector first!'); |
|
77
|
|
|
} |
|
78
|
1 |
|
return $this->connector; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
1 |
|
public function addAttribute(string $name, string $value): void |
|
82
|
|
|
{ |
|
83
|
1 |
|
$this->attributes[$name] = $value; |
|
84
|
1 |
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @param array<string, string> $attributes |
|
88
|
|
|
*/ |
|
89
|
23 |
|
public function setAttributes(array $attributes): void |
|
90
|
|
|
{ |
|
91
|
23 |
|
$this->attributes = $attributes + $this->attributes; |
|
92
|
23 |
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|