-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigurationTrait.php
More file actions
114 lines (90 loc) · 2.33 KB
/
Copy pathConfigurationTrait.php
File metadata and controls
114 lines (90 loc) · 2.33 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?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 Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\OneToOne;
use Nette\Utils\Json;
trait ConfigurationTrait
{
use UpdatedBy, UpdatedAt;
#[Column(name: '`key`', nullable: false)]
protected string $key;
#[Column(name: 'name', nullable: false)]
protected string $name;
#[Column(name: '`type`', nullable: false, options: ["default" => ConfigurationTypeEnum::TYPE_PLAINTEXT])]
protected ConfigurationTypeEnum $type = ConfigurationTypeEnum::TYPE_PLAINTEXT;
#[Column(name: '`value`', type: Types::TEXT, nullable: true)]
protected ?string $value = null;
#[OneToOne(targetEntity: 'File', cascade: ['persist'], orphanRemoval: true)]
#[JoinColumn(nullable: true)]
protected ?File $file;
#[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 getName(): string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
public function getType(): ConfigurationTypeEnum
{
return $this->type;
}
public function setType(ConfigurationTypeEnum $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;
}
public function getFile(): ?File
{
return $this->file;
}
public function setFile(?File $file): static
{
$this->file = $file;
return $this;
}
}