b2pweb /
bdf-form
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace Bdf\Form\View; |
||||
| 4 | |||||
| 5 | use Bdf\Form\Choice\ChoiceView; |
||||
| 6 | |||||
| 7 | /** |
||||
| 8 | * Implements @see FieldViewInterface |
||||
| 9 | * |
||||
| 10 | * @psalm-require-implements FieldViewInterface |
||||
| 11 | */ |
||||
| 12 | trait FieldViewTrait |
||||
| 13 | { |
||||
| 14 | use RenderableTrait; |
||||
| 15 | |||||
| 16 | /** |
||||
| 17 | * @var string |
||||
| 18 | */ |
||||
| 19 | private $name; |
||||
| 20 | |||||
| 21 | /** |
||||
| 22 | * @var mixed |
||||
| 23 | */ |
||||
| 24 | private $value; |
||||
| 25 | |||||
| 26 | /** |
||||
| 27 | * @var bool |
||||
| 28 | */ |
||||
| 29 | private $required = false; |
||||
| 30 | |||||
| 31 | /** |
||||
| 32 | * @var array |
||||
| 33 | */ |
||||
| 34 | private $constraints = []; |
||||
| 35 | |||||
| 36 | /** |
||||
| 37 | * @var ChoiceView[]|null |
||||
| 38 | */ |
||||
| 39 | private $choices; |
||||
| 40 | |||||
| 41 | /** |
||||
| 42 | * {@inheritdoc} |
||||
| 43 | */ |
||||
| 44 | 81 | public function name(): string |
|||
| 45 | { |
||||
| 46 | 81 | return $this->name; |
|||
| 47 | } |
||||
| 48 | |||||
| 49 | /** |
||||
| 50 | * {@inheritdoc} |
||||
| 51 | */ |
||||
| 52 | 67 | public function value() |
|||
| 53 | { |
||||
| 54 | 67 | return $this->value; |
|||
| 55 | } |
||||
| 56 | |||||
| 57 | /** |
||||
| 58 | * {@inheritdoc} |
||||
| 59 | */ |
||||
| 60 | 77 | public function required(): bool |
|||
| 61 | { |
||||
| 62 | 77 | return $this->required; |
|||
| 63 | } |
||||
| 64 | |||||
| 65 | /** |
||||
| 66 | * {@inheritdoc} |
||||
| 67 | */ |
||||
| 68 | 66 | public function constraints(): array |
|||
| 69 | { |
||||
| 70 | 66 | return $this->constraints; |
|||
| 71 | } |
||||
| 72 | |||||
| 73 | /** |
||||
| 74 | * {@inheritdoc} |
||||
| 75 | * |
||||
| 76 | * @return array<array-key, ChoiceView>|null |
||||
|
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||||
| 77 | */ |
||||
| 78 | 14 | public function choices(): ?array |
|||
| 79 | { |
||||
| 80 | 14 | return $this->choices; |
|||
| 81 | } |
||||
| 82 | |||||
| 83 | /** |
||||
| 84 | * {@inheritdoc} |
||||
| 85 | */ |
||||
| 86 | 43 | public function render(FieldViewRendererInterface $renderer = null): string |
|||
| 87 | { |
||||
| 88 | 43 | return ($renderer ?? $this->defaultRenderer())->render($this, $this->attributes); |
|||
|
0 ignored issues
–
show
$this of type Bdf\Form\View\FieldViewTrait is incompatible with the type Bdf\Form\View\FieldViewInterface expected by parameter $view of Bdf\Form\View\FieldViewRendererInterface::render().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 89 | } |
||||
| 90 | |||||
| 91 | /** |
||||
| 92 | * Get the default renderer to use for the current view implementation |
||||
| 93 | * |
||||
| 94 | * @return FieldViewRendererInterface |
||||
| 95 | */ |
||||
| 96 | abstract protected function defaultRenderer(): FieldViewRendererInterface; |
||||
| 97 | } |
||||
| 98 |