ILIAS  release_8 Revision v8.24
Container.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
28use Psr\Http\Message\ServerRequestInterface;
29
33abstract class Container implements C\Input\Container\Container
34{
35 use CI\ComponentHelper;
36
39 protected ?string $error = null;
40 protected ?string $dedicated_name = null;
41 protected CI\Input\NameSource $name_source;
42
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 {
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 implements commonalities between all forms.
Definition: Container.php:34
__construct(NameSource $name_source)
For the implementation of NameSource.
Definition: Container.php:46
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:132
error(string $a_errmsg)
A transformation is a function from one datatype to another.
This describes commonalities between all inputs.
Definition: Input.php:49
Describes how Input-Elements want to interact with posted data.
Definition: InputData.php:30
Describes a source for input names.
Definition: NameSource.php:27
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...