Subscribers
A subscriber is a class that listens to one or more events during the serialization or deserialization process. These events can include pre-serialization, post-serialization, pre-deserialization, and post-deserialization. Subscribers are used to customize the serialization/deserialization process. For example, you might use a subscriber to change the serialized representation of certain types of objects, or to perform some custom logic before an object is serialized.
Here is a list of build in T3API subscribers.
AbstractEntitySubscriber
This subscriber listens to the POST_SERIALIZE and PRE_DESERIALIZE events. In the case
of the POST_SERIALIZE event, it adds additional properties (defined in $GLOBALS
)
and IRI to the serialized object if the object is an instance of AbstractDomainObject.
In the case of the PRE_DESERIALIZE event, it changes the type to a custom one to enable
data handling with a serializer handler.
CurrentFeUserSubscriber
This subscriber listens to the PRE_SERIALIZE and PRE_DESERIALIZE events. In the case of the PRE_SERIALIZE event, it changes the type to a custom one if the type is equal to CurrentFeUserHandler::TYPE. In the case of the PRE_DESERIALIZE event, it adds the FE user identifier to the data. This identifier is later used by CurrentFeUserHandler to get FeUser object. It allows to securely attach info about FeUser to incoming data. Look for more info at at current user endpoint use case.
FileReferenceSubscriber
This subscriber listens to the PRE_SERIALIZE and PRE_DESERIALIZE events. In both cases, it changes the type to a custom one to enable data handling with a serializer handler if the type is a subclass of AbstractFileFolder.
GenerateMetadataSubscriber
This subscriber listens to the PRE_SERIALIZE and PRE_DESERIALIZE events.
In both cases, it generates yml serializer metadata and cache it in var/
.
Data from var/
is later used to serialize/deserialize by JSM serializer.
ResourceTypeSubscriber
This subscriber listens to the POST_SERIALIZE event. It adds the resource type (@type
)
to the serialized object if the object is an instance of AbstractDomainObject.
Examples of types: Source
, Source
. Adding
@type
is not activated by default as it can take a lot of space in the response.
To activate it add in your local extension :file:`ext_localconf.php.
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3api']['serializerSubscribers'][] = \SourceBroker\T3api\Serializer\Subscriber\ResourceTypeSubscriber::class;
ThrowableSubscriber
This subscriber listens to the POST_SERIALIZE event. It adds a description and debug to the serialized object if the object is an instance of Throwable.