DEPRECATION WARNING

This documentation is not using the current rendering mechanism and will be deleted by December 31st, 2020. The extension maintainer should switch to the new system. Details on how to use the rendering mechanism can be found here.

Services

A service will affect the way a configuration object is built, by applying different behaviours on the object during its conversion.

For instance, one of the most important is the CacheService: it will use the TYPO3 caching framework to store entire configuration objects in cache, and fetch it later, improving performances dramatically.

Services may use parameters, which you can customize to follow your needs (for instance the names of the cache entries for two different configuration object types can differ).


Attaching services to a configuration object

To attach services to a configuration object, you need to implement the public static function getConfigurationObjectServices in the root class of your configuration object. This function must return an instance of ServiceFactory.

Using a ServiceFactory instance, you can add whatever services you need, and even change options for those who can. You can find below the available functions for a ServiceFactory instance:

Function Description
ServiceFactory::getInstance() Returns a new instance of ServiceFactory.
$serviceFactory->attach($className, array $options)
Activates the given service with the given options (optional). The first parameter is the class name of the service.

If you intend to use a service from the core of this extension, please use the SERVICE_* constants of ServiceInterface.

When a service is added, the factory current service pointer is set on the added service (see the function with()).
$serviceFactory->has($className) Returns true if the given service is added to the factory.
$serviceFactory->with($className) Resets the factory current service pointer which can then be used with the function setOption() (see below).
$serviceFactory->setOption($name, $value)
Sets the value of the given option, for the factory current service pointer (last added service or last service given to the function with()).

Options are defined by services themselves, see their documentation to know which options you can use.
$serviceFactory->getOption($name) Returns the current value of the given option, if it is found.

Example:

class MyObject implements ConfigurationObjectInterface
{
    use DefaultConfigurationObjectTrait;

    const CACHE_NAME = 'foo_object';

    /**
     * @return ServiceFactory
     */
    public static function getConfigurationObjectServices()
    {
        return ServiceFactory::getInstance()
            ->attach(ServiceInterface::SERVICE_CACHE)
            ->setOption(CacheService::OPTION_CACHE_NAME, self::CACHE_NAME)
            ->attach(ServiceInterface::SERVICE_PARENTS);
    }
}

Services list

Below is the list of all the services provided by this API:

  • Cache service

    Will automatically manage to save objects in cache, and fetch them later.

  • Parents service

    Will keep a trace between objects and their sub-objects, which will then be able to fetch their parents.

  • Persistence service

    Allows the usage of objects which can be accessed with Extbase PersistenceManager, for instance Category, FrontendUser, and basically any object which implements the interface TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface.

  • Data pre-processor service

    Allows modifying the data used to create an object, just before its creation.

  • Mixed types service

    Allows to dynamically change the type of the object which will be created.

  • Store configuration array service

    Will store the initial array used to create an object.


Creating your own service

To be written. :-)