ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Container.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
28use Psr\Http\Message\ServerRequestInterface;
30
34abstract class Container implements C\Input\Container\Container
35{
36 use CI\ComponentHelper;
37
40 protected ?string $error = null;
41 protected ?string $dedicated_name = null;
42 protected CI\Input\NameSource $name_source;
43 protected ?Result $result = null;
44
49 {
50 $this->name_source = clone $name_source;
51 }
52
56 public function getInputs(): array
57 {
58 return $this->getInputGroup()->getInputs();
59 }
60
64 public function withRequest(ServerRequestInterface $request): self
65 {
66 return $this->withInput(
67 $this->extractRequestData($request)
68 );
69 }
70
71 public function withInput(InputData $input_data): self
72 {
73 $clone = clone $this;
74 $clone->input_group = $this->getInputGroup()->withInput($input_data);
75 $clone->result = $clone->input_group->getContent();
76
77 if (!$clone->result->isok()) {
78 $clone->setError($clone->result->error());
79 }
80
81 return $clone;
82 }
83
87 public function withAdditionalTransformation(Transformation $trafo): self
88 {
89 $clone = clone $this;
90 $clone->input_group = $this->getInputGroup()->withAdditionalTransformation($trafo);
91
92 return $clone;
93 }
94
98 public function getError(): ?string
99 {
100 return $this->error;
101 }
102
103 protected function setError(string $error): void
104 {
105 $this->error = $error;
106 }
107
111 public function getData()
112 {
113 if (null !== $this->result && $this->result->isOK()) {
114 return $this->result->value();
115 }
116 return null;
117 }
118
119 public function getDedicatedName(): ?string
120 {
122 }
123
124 public function withDedicatedName(string $dedicated_name): self
125 {
126 $clone = clone $this;
127 $clone->dedicated_name = $dedicated_name;
128 $clone->input_group = $clone->input_group
129 ->withDedicatedName($dedicated_name)
130 ->withNameFrom($clone->name_source);
131 return $clone;
132 }
133
134 public function getInputGroup(): C\Input\Group
135 {
136 return $this->input_group;
137 }
138
142 protected function setInputGroup(C\Input\Group $input_group): void
143 {
144 $this->input_group = $input_group->withNameFrom($this->name_source);
145 }
146
151 abstract protected function extractRequestData(ServerRequestInterface $request): InputData;
152
153 public function getSubComponents(): array
154 {
155 return $this->getInputs();
156 }
157}
This implements commonalities between all forms.
Definition: Container.php:35
__construct(NameSource $name_source)
For the implementation of NameSource.
Definition: Container.php:48
extractRequestData(ServerRequestInterface $request)
Returns the extracted data from the given server request.
setInputGroup(C\Input\Group $input_group)
This setter should be used in the constructor only, to initialize the group input property.
Definition: Container.php:142
error(string $a_errmsg)
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Result.php:29
A transformation is a function from one datatype to another.
Describes how Input-Elements want to interact with posted data.
Definition: InputData.php:30
This describes commonalities between all inputs.
Definition: Input.php:47
Describes a source for input names.
Definition: NameSource.php:27