Skip to content

FEATURE: Add additional data-types array, float, dateTime - #17

Open
c4ll-m3-j4ck wants to merge 3 commits into
neos:feature/extensible-metadata-propertiesfrom
c4ll-m3-j4ck:feature/extensible-metadata-properties
Open

FEATURE: Add additional data-types array, float, dateTime#17
c4ll-m3-j4ck wants to merge 3 commits into
neos:feature/extensible-metadata-propertiesfrom
c4ll-m3-j4ck:feature/extensible-metadata-properties

Conversation

@c4ll-m3-j4ck

Copy link
Copy Markdown

This adds additional possible data-types and the required internal mapping for these types.

All properties are cast to string when persisted, some internal typing has been removed to allow for future additional typings to be added.

Splits the logical value carried by a metadata property from its stored
string representation: MetaDataPropertyType stays the single source of
truth for which concrete type each case accepts/returns, so callers type
it as mixed instead of a repeated string|int|bool union that would
otherwise need to grow at every call site whenever a type is added.

@bwaidelich bwaidelich left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! Just a few minor questions/concerns

public MetaDataPropertyType $type,
public bool $globalScope,
public ?MetaDataPropertyUiDefinition $ui = null,
public ?array $options = null,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are these? Can we add some @paramannotation with type + description

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this related and used by the new code at all?

return match (true) {
is_bool($coerced) => $coerced ? '1' : '0',
is_array($coerced) => json_encode($coerced, JSON_THROW_ON_ERROR),
$coerced instanceof DateTimeInterface => $coerced->format(DATE_ATOM),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we agree that DATE_ATOM is the right way to represent datetime always?

* @throws InvalidArgumentException if the value cannot be interpreted as this type
*/
public function coerceForStorage(string|int|bool $value): string
public function coerceForStorage(mixed $value): string

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't string|int|bool|float|array|DateTimeInterface still better here?

case integer;
case boolean;
case float;
case array;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really need to support arrays? if so I think that we should limit it to array<string|int|bool|float>

Comment on lines +31 to +33
public mixed $value,
public mixed $ownValue,
public mixed $inheritedValue,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mixed is the broadest type that we can use. I would prefer union so that consumers can match over all cases, e.g. if they need to serialize these

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants