Writing own property classes

From Sunhill Framework Documentation
Revision as of 15:41, 17 September 2024 by Klaus (talk | contribs) (Completed documentation (for now))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

When writing an own property class first check if you could use one of the Types or Semantics.

Human readable format / storage format

Internally the storage only uses php basic types. These are not always in a pretty format for the human eye. So there are some methods to prettify the output.

formatForHumans(mixed $input): mixed

Takes the raw data from storage and outputs a friendly format for the human eye.

formatForStorage(mixed $input): mixed

Sometimes the internal storage format is different from that the values are assigned to the property. So every data is passed through this method before passing to the storage.

formatFromStorage(mixed $input): mixed

Sometimes the internal storage format is different from that the values are assigned to the property. So every data is passed through this method before passing from the storage.

formatFromInput(mixed $input): mixed

Sometimes a property can take different data types. The data is passed through this method to unify it to a datatype that can be processed further.

InfoMarket interaction

requestTerminalItem(string $name)

Sometimes a property has a pseudo element that can be accessed. So all unknown requests are passed through this method.

passItemRequest(string $name,array $path)

If a property has sub elements, this method passed a request to one of those sub elements.

Value validation

isValid(mixed $input): bool

Checks if the given input is valid for this property.

handleNullValue()

Is called whenever null is assigned as value for this property.

Information

::setupInfos()

Is a static method of this property that is called whenever an information is requested. It can be overwritten by a property to return certain informations.

parent::setupInfos() should be called as first intruction.

::addInfo(string $key, $value, bool $translatable = false)

Is called out of setupInfos to add a single information atom. $key is the name of this information atom $value is the value of this information atom $translatable indicated if the information value should be passed through __() function when requested.