-
Notifications
You must be signed in to change notification settings - Fork 2
Closed
Milestone
Description
class Model {
protected static function properties() {
return [
(new ModelProperty('firstName')) // default type is 'string'
->type('string'),
->requiredOnSave() // can be made without, but cannot be saved without (as opposed to required())
->validationRule(), // use the Validation library???
(new ModelProperty('lastName'))
->type('string')
->default('Jones'),
(new ModelProperty('weight'))
->type('int', 'float') // variadic, assumes union type
->default('Jones')
->cast(function($value, $property) { return (float) $value }),
(new UpdatedAtProperty()), // Supports ModelProperty subclasses 🤯
'email' => ['string', 'foo@example.com']
];
}
}
Notes:
- This is merged with
$properties
parsed into the$propertiesCollection
static property once - The final shape is the key is the property name and the value is a
ModelProperty
- For explicit
ModelProperty
instances the key is taken from the instance - For short-hand properties they're parsed into a
ModelProperty
- Also introduce a
ModelPropertiesCollection
class to get things such as "required properties"
Metadata
Metadata
Assignees
Labels
No labels