TYPO3-Documentation/TYPO3CMS-Book-ExtbaseFluid

Document core TypeInterface

mbrodala opened this issue · 1 comments

The \TYPO3\CMS\Core\Type\TypeInterface is extremely useful in Extbase to encapsulate raw data in model properties.

The basic facts:

  1. When using a custom class (which implements TypeInterface) as property type, the class will get the raw value as constructor argument while mapping
  2. Since TypeInterface dictates implementation of __toString(), the wrapped raw value is converted to string when persisting the model.

By default this is used in Extbase to handle custom Enumeration classes but any arbitrary custom class works just as fine.

An example for using this is loading and storing JSON data. In the database this would be stored as string, a custom TypeInterface class could unserialize and enrich this for usage on runtime. Saving changes is as simple as serializing the runtime value again.

The PR was already merged.