Handlers and Services
Handlers are storable objects that also implement a
get_typemethod. For example, handlers for the logging service are of the logging type.
Services are meant to be central hubs (i.e., singleton instances) for performing certain actions. It's not mandatory, but we designed all of our services to delegate the responsibility of performing the actions to a handler. For example, a service inheriting the
AbstractHandlerServiceclass always performs the actions with the same handler whereas a service inheriting the
AbstractMultiHandlerServiceclass needs to be instructed which registered handler to use.
Handlers are not meant to be used directly. An object usually has one-or-more registered handlers that it can perform actions with. That's why the
HandlerAwareInterface(and the corresponding trait) and the
MultiHandlerAwareInterface(and the corresponding trait) are very important.
The handlers are also prime candidates for extension action traits. There are 3 traits that the foundations module comes with:
For example, a multi-handler-aware-service implementing the
OutputtableInterfaceand using the
OutputHandlersTraitmentioned above will automagically call the
outputmethod of all its registered handlers also implementing the
OutputtableInterfacewhen the service's own
outputmethod is called. Pretty neat, huh?