1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the eav package. |
4
|
|
|
* @author Aleksandr Drobotik <[email protected]> |
5
|
|
|
* @copyright 2023 Aleksandr Drobotik |
6
|
|
|
* @license https://opensource.org/license/mit The MIT License |
7
|
|
|
*/ |
8
|
|
|
declare(strict_types=1); |
9
|
|
|
|
10
|
|
|
namespace Drobotik\Eav\Import\Content; |
11
|
|
|
|
12
|
|
|
use Drobotik\Eav\Enum\ATTR_TYPE; |
13
|
|
|
use Drobotik\Eav\Trait\SingletonsTrait; |
14
|
|
|
|
15
|
|
|
class Value |
16
|
|
|
{ |
17
|
|
|
use SingletonsTrait; |
18
|
|
|
|
19
|
|
|
private mixed $value; |
20
|
|
|
private int $attributeKey; |
21
|
|
|
private string $attributeName; |
22
|
|
|
private ?int $entityKey = null; |
23
|
|
|
private int $lineIndex; |
24
|
|
|
|
25
|
|
|
private ATTR_TYPE $type; |
26
|
|
|
|
27
|
1 |
|
public function setType(ATTR_TYPE $type): void |
28
|
|
|
{ |
29
|
1 |
|
$this->type = $type; |
30
|
|
|
} |
31
|
|
|
|
32
|
1 |
|
public function getType() : ATTR_TYPE |
33
|
|
|
{ |
34
|
1 |
|
return $this->type; |
35
|
|
|
} |
36
|
|
|
|
37
|
1 |
|
public function getValue() |
38
|
|
|
{ |
39
|
1 |
|
return $this->value; |
40
|
|
|
} |
41
|
|
|
|
42
|
2 |
|
public function setValue(mixed $value): void |
43
|
|
|
{ |
44
|
2 |
|
$type = $this->getType(); |
45
|
2 |
|
$parser = $this->makeValueParser(); |
46
|
2 |
|
$this->value = $value == '' |
47
|
1 |
|
? '' |
48
|
2 |
|
: $parser->parse($type, $value); |
49
|
|
|
} |
50
|
|
|
|
51
|
1 |
|
public function isEmptyValue(): bool |
52
|
|
|
{ |
53
|
1 |
|
return $this->value == ''; |
54
|
|
|
} |
55
|
|
|
|
56
|
1 |
|
public function getEntityKey() : ?int |
57
|
|
|
{ |
58
|
1 |
|
return $this->entityKey; |
59
|
|
|
} |
60
|
|
|
|
61
|
1 |
|
public function setEntityKey(int $key): void |
62
|
|
|
{ |
63
|
1 |
|
$this->entityKey = $key; |
64
|
|
|
} |
65
|
|
|
|
66
|
1 |
|
public function isEntityKey() : bool |
67
|
|
|
{ |
68
|
1 |
|
return !is_null($this->entityKey); |
69
|
|
|
} |
70
|
|
|
|
71
|
1 |
|
public function setLineIndex(int $index) |
72
|
|
|
{ |
73
|
1 |
|
$this->lineIndex = $index; |
74
|
|
|
} |
75
|
|
|
|
76
|
1 |
|
public function getLineIndex() : int |
77
|
|
|
{ |
78
|
1 |
|
return $this->lineIndex; |
79
|
|
|
} |
80
|
|
|
|
81
|
1 |
|
public function isLineIndex() : bool |
82
|
|
|
{ |
83
|
1 |
|
return isset($this->lineIndex); |
84
|
|
|
} |
85
|
|
|
|
86
|
1 |
|
public function getAttributeKey() : int |
87
|
|
|
{ |
88
|
1 |
|
return $this->attributeKey; |
89
|
|
|
} |
90
|
|
|
|
91
|
1 |
|
public function setAttributeKey(int $key): void |
92
|
|
|
{ |
93
|
1 |
|
$this->attributeKey = $key; |
94
|
|
|
} |
95
|
|
|
|
96
|
1 |
|
public function getAttributeName() : string |
97
|
|
|
{ |
98
|
1 |
|
return $this->attributeName; |
99
|
|
|
} |
100
|
|
|
|
101
|
1 |
|
public function setAttributeName(string $name): void |
102
|
|
|
{ |
103
|
1 |
|
$this->attributeName = $name; |
104
|
|
|
} |
105
|
|
|
} |