ILIAS  trunk Revision v11.0_alpha-1761-g6dbbfa7b760
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
Container.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
23 use ILIAS\UI\Component as C;
30 
34 abstract class Container implements C\Input\Container\Container
35 {
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 
48  public function __construct(NameSource $name_source)
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  {
121  return $this->dedicated_name;
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 }
Describes how Input-Elements want to interact with posted data.
Definition: InputData.php:29
This implements commonalities between all forms.
Definition: Container.php:34
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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
A transformation is a function from one datatype to another.
This describes commonalities between all inputs.
Definition: Input.php:46
extractRequestData(ServerRequestInterface $request)
Returns the extracted data from the given server request.
Describes a source for input names.
Definition: NameSource.php:26
__construct(NameSource $name_source)
For the implementation of NameSource.
Definition: Container.php:48