19declare(strict_types=1);
41 foreach ($this->fields as $field) {
48 if (!is_object(
$data)) {
49 return fn() => yield
"Expected an object.";
52 $repr = new \StdClass();
55 foreach ($this->fields as $field) {
56 $name = $field->getName();
60 if (method_exists(
$data, $method)) {
62 $value =
$data->$method();
68 if (property_exists(
$data, $property)) {
70 $value =
$data->$property;
76 $errors[] = fn() => yield
"Object does not have property \"$name\".";
80 $value = $field->getType()->getPrimitiveRepresentation($value);
81 if ($value instanceof \Closure) {
84 $repr->$name = $value;
90 return $this->mergeErrors($errors);
101 yield
"get" . ucfirst($name);
102 yield
"get_" . $name;
103 yield
"get" . $camel_cased;
104 yield
"get_" . $snake_cased;
105 yield
"is" . ucfirst($name);
107 yield
"is" . $camel_cased;
108 yield
"is_" . $snake_cased;
114 yield ucfirst($name);
122 return preg_replace_callback(
"/_(\w)/", fn($v) => strtoupper($v[1]), $name);
127 return preg_replace_callback(
"/[A-Z]/", fn($v) =>
"_" . strtolower($v[0]), $name);
possiblePropertyNames(string $name)
possibleMethodNames(string $name)
__construct(Text\SimpleDocumentMarkdown $description, Field ... $fields)
getPrimitiveRepresentation(mixed $data)
Each of the types that can be described has a canonical representation created from primitive PHP typ...
This describes some datastructure in terms of standard data structures such as primitives,...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc