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.

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 or of an extension.

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

EXT:some_extension/Classes/SomeClass.php
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;

$object = GeneralUtility::makeInstance(ContentObjectRenderer::class);
Copied!

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:

EXT:some_extension/Classes/SomeClass.php
// use TYPO3\CMS\Core\Utility\GeneralUtility;

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

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 planned 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.