-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigurationTrait.php
More file actions
83 lines (65 loc) · 1.74 KB
/
Copy pathConfigurationTrait.php
File metadata and controls
83 lines (65 loc) · 1.74 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
declare(strict_types=1);
namespace ADT\FancyAdmin\Model\Entities;
use ADT\FancyAdmin\Model\Entities\Enums\ConfigurationType;
use ADT\FancyAdmin\Model\Entities\Enums\ConfigurationTypeEnum;
use ADT\FancyAdmin\Model\Entities\Traits\UpdatedAt;
use ADT\FancyAdmin\Model\Entities\Traits\UpdatedBy;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping\Column;
use Nette\Utils\Json;
trait ConfigurationTrait
{
use UpdatedBy, UpdatedAt;
#[Column(name: '`key`', nullable: false)]
protected string $key;
#[Column(name: '`type`', nullable: false, options: ["default" => ConfigurationTypeEnum::TYPE_PLAINTEXT])]
protected ConfigurationTypeEnum $type = ConfigurationTypeEnum::TYPE_PLAINTEXT;
#[Column(name: '`value`', type: Types::TEXT, nullable: false)]
protected string $value;
#[Column(name: '`options`', type: Types::TEXT, nullable: true)]
protected ?string $options = null;
public function getKey(): string
{
return $this->key;
}
public function setKey(string $key): static
{
$this->key = $key;
return $this;
}
public function getType(): string
{
return $this->type->value;
}
public function setType(ConfigurationType $type): static
{
$this->type = $type;
return $this;
}
public function getValue(): string
{
return $this->value;
}
public function setValue(string $value): static
{
$this->value = $value;
return $this;
}
public function getOptions($asArray = false): array|string|null
{
if (!$this->options) {
return $asArray ? [] : null;
}
return $asArray
? Json::decode($this->options, true)
: $this->options;
}
public function setOptions(array|string|null $options): static
{
$this->options = $options
? (is_array($options) ? Json::encode($options) : $options)
: null;
return $this;
}
}