You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Let's say I want to create a data object for default opening hours for a week for a store (e.g. on Monday open 11:00 close 19:00).
What is the recommended / best practice way to do that?
I can create a data object for a day:
class OpeninghoursDayData extends Data
{
public function __construct(
public int $dayOfWeek,
public string $open,
public string $close,
// other properties for that day
) {}
}
and a week:
class OpeninghoursWeekData extends Data
{
public function __construct(
#[DataCollectionOf(OpeninghoursDayData::class)]
public DataCollection $days
) {}
}
But how do I ensure I get all 7 days and no duplicate days?
I.e. this should fail because a) one day is repeated, b) not all days are provided.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Let's say I want to create a data object for default opening hours for a week for a store (e.g. on Monday open 11:00 close 19:00).
What is the recommended / best practice way to do that?
I can create a data object for a day:
and a week:
But how do I ensure I get all 7 days and no duplicate days?
I.e. this should fail because a) one day is repeated, b) not all days are provided.
Or is there another approach that makes more sense?
Beta Was this translation helpful? Give feedback.
All reactions