ILIAS
release_7 Revision v7.30-3-g800a261c036
|
Transformations in this group transform data to primitive types to establish a baseline for more complex transformation. More...
Public Member Functions | |
__construct (\ILIAS\Data\Factory $dataFactory) | |
int () | |
Get a kind transformation to an int . More... | |
float () | |
Get a kind transformation to a float . More... | |
string () | |
Get a kind transformation to a string . More... | |
bool () | |
Get a kind transformation to a bool . More... | |
dateTime () | |
Get a kind transformation to a DateTimeImmutable . More... | |
listOf (Transformation $transformation) | |
Get a kind transformation to a list. More... | |
dictOf (Transformation $transformation) | |
Get a kind transformation to a dictionary. More... | |
tupleOf (array $transformation) | |
Get a kind transformation to a tuple. More... | |
recordOf (array $transformations) | |
Get a kind transformation to a record. More... | |
null () | |
Get a kind transformation to null. More... | |
Private Attributes | |
$dataFactory | |
Transformations in this group transform data to primitive types to establish a baseline for more complex transformation.
They use Postels Law of robustness and thus will be useful when communicating with other systems. Look into the single transformations for more information about the exact behaviour.
They don't try to mimic PHPs type cast, but instead follow more sophisticated rules devised in a series of workshops with interested developers from the community. Thanks Michael Jansen, Fabian Schmid, Alex Killing, Stephan Winiker, Timon Amstutz and Nils Haagen.
ILIAS\Refinery\KindlyTo\Group::__construct | ( | \ILIAS\Data\Factory | $dataFactory | ) |
ILIAS\Refinery\KindlyTo\Group::bool | ( | ) |
Get a kind transformation to a bool
.
This supports:
All other data will be discarded. We could have decided to use a much more liberal approach by e.g. interpreting "existence of data" as true and absence of data as false. However, these transformations here are not meant to interpret incoming data as desired at all costs, but instead try to be forgiving regarding various quirks in encoding when different systems talk to each other. There seem to be some more or less sane ways to encode bools, but writing "some data" to represent true, or an empty list to represent is something else. Also, being more liberal introduces a various odd places in the mapping. If, e.g., we'd map a null to false, an empty list to false as well, would we map [null] to false or to true? Why? All this problems seem to introduce more problems than they solve, so we decided to not be very liberal here.
ILIAS\Refinery\KindlyTo\Group::dateTime | ( | ) |
Get a kind transformation to a DateTimeImmutable
.
This supports:
All other data will be discarded.
ILIAS\Refinery\KindlyTo\Group::dictOf | ( | Transformation | $transformation | ) |
ILIAS\Refinery\KindlyTo\Group::float | ( | ) |
Get a kind transformation to a float
.
This supports:
All other data will be discarded.
ILIAS\Refinery\KindlyTo\Group::int | ( | ) |
Get a kind transformation to an int
.
This supports:
All other data will be discarded.
ILIAS\Refinery\KindlyTo\Group::listOf | ( | Transformation | $transformation | ) |
ILIAS\Refinery\KindlyTo\Group::null | ( | ) |
Get a kind transformation to null.
Transforms an empty string to null; e.g.in the case of optional numeric inputs, an empty string is being relayed to the server: This is rather the absence of input than an invalid number.
ILIAS\Refinery\KindlyTo\Group::recordOf | ( | array | $transformations | ) |
Get a kind transformation to a record.
This supports all data represented as PHP array. This will accept array with more fields than expected, but drop the extra fields.
array<string,Transformation> | $transformations |
ILIAS\Refinery\KindlyTo\Group::string | ( | ) |
Get a kind transformation to a string
.
This supports:
Regarding the usage of __toString: Transformations in this group are not meant to provide ways to reliably serialize data. For these type of transformations, two new groups serializeTo
and serializeFrom
would be a better fit and could deal with intricacies of various serialization formats way better. Instead, these transformations try to offer a forgiving way to treat incoming data. So by using kindlyTo()->string(), I tell the Refinery that I expect a certain piece of data to be some string, and expect that the Refinery tries to produce one. A transformation to string is a lossy transformation most of the time anyway, if we don't talk about e.g. serialization formats. So we don't loose much if we, e.g., transform an array to "Array".
ILIAS\Refinery\KindlyTo\Group::tupleOf | ( | array | $transformation | ) |
Get a kind transformation to a tuple.
This supports all data represented as PHP array, which will be used via array_values($V). Non-arrays will be wrapped in one. This will accept array with more fields than expected, but drop the extra fields.
Transformation[] | $transformation |
|
private |
Definition at line 37 of file Group.php.
Referenced by ILIAS\Refinery\KindlyTo\Group\__construct().