ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
GrindingInputAccess.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
29
37{
38 private function __construct()
39 {
40 }
41
45 public static function named(FormInput $description, string $activity_class): FormInput
46 {
47 if (!$description instanceof InputInternal) {
48 throw new \LogicException(
49 $activity_class . '::getInputDescription() must return a FormInput built from the ' .
50 'UI framework (i.e. one that also implements ' . InputInternal::class . ') to be ' .
51 'grindable by maybePerformAs() - see the GrindsFormInput trait for why.'
52 );
53 }
54
55 return $description->withNameFrom(new FormInputNameSource());
56 }
57
59 public static function withRawValues(FormInput $named, array $flat_raw_values): FormInput
60 {
61 self::assertInternal($named, 'withInput()');
62
63 return $named->withInput(new ArrayInputData($flat_raw_values));
64 }
65
66 public static function content(FormInput $with_input): Result
67 {
68 self::assertInternal($with_input, 'getContent()');
69
70 return $with_input->getContent();
71 }
72
73 public static function nameOf(Input $input): ?string
74 {
75 return $input instanceof InputInternal ? $input->getName() : null;
76 }
77
78 public static function errorOf(Input $input): ?string
79 {
80 return $input instanceof InputInternal ? $input->getError() : null;
81 }
82
83 public static function isNameable(Input $input): bool
84 {
85 return $input instanceof InputInternal;
86 }
87
88 public static function requireNameable(Input $input, string $exception_message): void
89 {
90 if (!$input instanceof InputInternal) {
91 throw new \LogicException($exception_message);
92 }
93 }
94
96 public static function dedicatedNameOf(Input $input): ?string
97 {
98 return $input instanceof \ILIAS\UI\Implementation\Component\Input\Input
99 ? $input->getDedicatedName()
100 : null;
101 }
102
104 private static function assertInternal(FormInput $input, string $needed_for): void
105 {
106 if (!$input instanceof InputInternal) {
107 throw new \LogicException(
108 'Expected a FormInput also implementing ' . InputInternal::class . ' (needed for ' .
109 $needed_for . '), got: ' . get_debug_type($input)
110 );
111 }
112 }
113}
Sole point of coupling to ILIAS\UI\Implementation\Component\Input\*: the public FormInput interfaces ...
static requireNameable(Input $input, string $exception_message)
static withRawValues(FormInput $named, array $flat_raw_values)
static named(FormInput $description, string $activity_class)
Assigns HTML input names throughout $description's tree; required before collecting raw data.
static dedicatedNameOf(Input $input)
Only available on the concrete implementation base class, not on the public Input interface.
static assertInternal(FormInput $input, string $needed_for)
@phpstan-assert InputInternal $input
FormInputNameSource is responsible for generating continuous form input names.
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Result.php:29
This describes inputs that can be used in forms.
Definition: FormInput.php:33
This describes commonalities between all inputs.
Definition: Input.php:47
Describes the interface of inputs that is used for internal processing of data from the client.