-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormView.php
More file actions
110 lines (96 loc) · 2.39 KB
/
Copy pathFormView.php
File metadata and controls
110 lines (96 loc) · 2.39 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
<?php
namespace Quatrevieux\Form\View;
use ArrayAccess;
use BadMethodCallException;
use Countable;
use IteratorAggregate;
use Quatrevieux\Form\FormInterface;
use Quatrevieux\Form\Validator\FieldError;
use Traversable;
use function count;
/**
* Structure for the form view
* Note: Unlike most form components, this class is mutable. So a new instance should be created for each form view.
*
* @implements ArrayAccess<array-key, FieldView|FormView>
* @implements IteratorAggregate<array-key, FieldView|FormView>
*
* @see FormInterface::view() For creating a new instance
*/
final class FormView implements ArrayAccess, IteratorAggregate, Countable
{
public function __construct(
/**
* The DTO class name representing form structure of the current view.
*
* @var class-string
*/
public readonly string $class,
/**
* Form fields indexed by name (or index in case of array)
*
* @var array<string|int, FieldView|FormView>
*/
public readonly array $fields,
/**
* Raw HTTP value
*
* @var mixed[]
*/
public readonly array $value = [],
/**
* Template element view in case of array
*
* @var FormView|FieldView|null
*/
public readonly FormView|FieldView|null $template = null,
/**
* Global form error
*
* @var FieldError|null
*/
public ?FieldError $error = null,
) {}
/**
* {@inheritdoc}
*/
public function offsetExists(mixed $offset): bool
{
return isset($this->fields[$offset]);
}
/**
* {@inheritdoc}
*/
public function offsetGet(mixed $offset): FieldView|FormView
{
return $this->fields[$offset];
}
/**
* {@inheritdoc}
*/
public function offsetSet(mixed $offset, mixed $value): void
{
throw new BadMethodCallException('FormView is read-only');
}
/**
* {@inheritdoc}
*/
public function offsetUnset(mixed $offset): void
{
throw new BadMethodCallException('FormView is read-only');
}
/**
* {@inheritdoc}
*/
public function getIterator(): Traversable
{
yield from $this->fields;
}
/**
* {@inheritdoc}
*/
public function count(): int
{
return count($this->fields);
}
}