ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables 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;
29 
33 abstract class Container implements C\Input\Container\Container
34 {
36 
38  protected ?Transformation $transformation = null;
39  protected ?string $error = null;
40  protected ?string $dedicated_name = null;
41  protected CI\Input\NameSource $name_source;
42 
46  public function __construct(NameSource $name_source)
47  {
48  $this->name_source = clone $name_source;
49  }
50 
54  public function getInputs(): array
55  {
56  return $this->getInputGroup()->getInputs();
57  }
58 
62  public function withRequest(ServerRequestInterface $request): self
63  {
64  $post_data = $this->extractRequestData($request);
65 
66  $clone = clone $this;
67  $clone->input_group = $this->getInputGroup()->withInput($post_data);
68 
69  return $clone;
70  }
71 
75  public function withAdditionalTransformation(Transformation $trafo): self
76  {
77  $clone = clone $this;
78  $clone->input_group = $this->getInputGroup()->withAdditionalTransformation($trafo);
79 
80  return $clone;
81  }
82 
86  public function getError(): ?string
87  {
88  return $this->error;
89  }
90 
91  protected function setError(string $error): void
92  {
93  $this->error = $error;
94  }
95 
99  public function getData()
100  {
101  $content = $this->getInputGroup()->getContent();
102  if (!$content->isok()) {
103  $this->setError($content->error());
104  return null;
105  }
106  return $content->value();
107  }
108 
109  public function getDedicatedName(): ?string
110  {
111  return $this->dedicated_name;
112  }
113 
114  public function withDedicatedName(string $dedicated_name): self
115  {
116  $clone = clone $this;
117  $clone->dedicated_name = $dedicated_name;
118  $clone->input_group = $clone->input_group
119  ->withDedicatedName($dedicated_name)
120  ->withNameFrom($clone->name_source);
121  return $clone;
122  }
123 
124  public function getInputGroup(): C\Input\Group
125  {
126  return $this->input_group;
127  }
128 
132  protected function setInputGroup(C\Input\Group $input_group): void
133  {
134  $this->input_group = $input_group->withNameFrom($this->name_source);
135  }
136 
141  abstract protected function extractRequestData(ServerRequestInterface $request): InputData;
142 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This implements commonalities between all forms.
Definition: Container.php:33
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Describes how Input-Elements want to interact with posted data.
Definition: InputData.php:29
setInputGroup(C\Input\Group $input_group)
This setter should be used in the constructor only, to initialize the group input property...
Definition: Container.php:132
A transformation is a function from one datatype to another.
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:46