Introduction

Deprecated since version 11.3: The abstract class \TYPO3\CMS\Core\Service\AbstractService has been deprecated. See Migration.

This document describes the services functionality included in the TYPO3 Core.

Note

The Services API is one of the older core APIs that did not find much traction over the years. The core itself only uses it for frontend and backend user authentication.

Additionally, only a couple of extensions use the Services API, and not much happened to the underlying codebase lately. Extension authors may want to ignore this API for new stuff and implement own factory or service related patterns that may fit needs better.

Important

This chapter is about the Services API provided by the core. Don’t confuse it with casual PHP classes within the directory Classes/Service found in many extensions - they usually do not use the API mentioned here.

Authentication service classes in the Core extend TYPO3\CMS\Core\Service\AbstractAuthenticationService.

In comparison, for additional information on what the Core usually understands as “casual” service class, see the coding guidelines.

The whole Services API works as a registry. Services are registered with a number of parameters, and each service can easily be overridden by another one with improved features or more specific capabilities, for example. This can be achieved without having to change the original code of TYPO3 CMS or of an extension.

Services are simply PHP classes packaged inside an extension. The usual way to instantiate a class in TYPO3 CMS is:

$object = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
   \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class);

Getting a service instance is achieved using a different API. The PHP class is not directly referenced. Instead a service is identified by its type, sub type and exclude service keys:

// use TYPO3\CMS\Core\Utility\GeneralUtility;

$serviceObject = GeneralUtility::makeInstanceService(
   'my_service_type',
   'my_service_subtype',
   ['not_used_service_type1', 'not_used_service_type2']
);

parameters for makeInstanceService:

  • string $serviceType: Type of service (service key)
  • string $serviceSubType (default ‘’): Sub type like file extensions or similar. Defined by the service.
  • array $excludeServiceKeys (default []): List of service keys which should be excluded in the search for a service. Array.

The same service can be provided by different extensions. The service with the highest priority and quality (more on that later) is chosen automatically for you.

Reasons for using the Services API

Deprecated since version 11.3: The abstract class \TYPO3\CMS\Core\Service\AbstractService has been deprecated. See Migration.

The AbstractService has been deprecated and it is planed to also deprecate the other methods of the Service API in the future. The Service API should only be used for frontend and backend user authentication.