1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Psi\Component\ContentType; |
6
|
|
|
|
7
|
|
|
use Psi\Component\ContentType\OptionsResolver\FieldOptionsResolver; |
8
|
|
|
|
9
|
|
|
class Field |
10
|
|
|
{ |
11
|
|
|
private $resolved; |
12
|
|
|
private $resolver; |
13
|
|
|
private $options; |
14
|
|
|
private $field; |
15
|
|
|
|
16
|
|
|
public function __construct(FieldInterface $field, array $options) |
17
|
|
|
{ |
18
|
|
|
$this->field = $field; |
19
|
|
|
$this->options = $options; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function getOptions(): array |
23
|
|
|
{ |
24
|
|
|
return $this->resolve('resolve'); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function getFormType(): string |
28
|
|
|
{ |
29
|
|
|
return $this->field->getFormType(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function getFormOptions(): array |
33
|
|
|
{ |
34
|
|
|
return $this->resolve('resolveFormOptions'); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function getViewType(): string |
38
|
|
|
{ |
39
|
|
|
return $this->field->getViewType(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function getViewOptions(): array |
43
|
|
|
{ |
44
|
|
|
return $this->resolve('resolveViewOptions'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function getStorageOptions(): array |
48
|
|
|
{ |
49
|
|
|
return $this->resolve('resolveStorageOptions'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function getStorageType(): string |
53
|
|
|
{ |
54
|
|
|
return $this->field->getStorageType(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function getInnerField() |
58
|
|
|
{ |
59
|
|
|
return $this->field; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
private function getResolver(): FieldOptionsResolver |
63
|
|
|
{ |
64
|
|
|
if ($this->resolver) { |
65
|
|
|
return $this->resolver; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
$this->resolver = new FieldOptionsResolver(); |
69
|
|
|
$this->field->configureOptions($this->resolver); |
70
|
|
|
|
71
|
|
|
return $this->resolver; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
private function resolve(string $methodName) |
75
|
|
|
{ |
76
|
|
|
if (isset($this->resolved[$methodName])) { |
77
|
|
|
return $this->resolved[$methodName]; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
$resolver = $this->getResolver(); |
81
|
|
|
|
82
|
|
|
$this->resolved[$methodName] = $resolver->$methodName($this->options); |
83
|
|
|
|
84
|
|
|
return $this->resolved[$methodName]; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|