Skip to content

Commit 5a0a79c

Browse files
committed
[TASK] Make Configuration default for ConfigurationInterface
It's a good practice to define interfaces and provide a default implementation making xclass strategies, stubbing or mocking in tests and similar techniques easier. Default implementation, if provided, should be configured in the DI configuration as alias for the interface, not done for the `ConfigurationInterface` on the default implementation `Configuration`. TYPO3 `SingeltonInterface` stems from old times before DI has been introduced to TYPO3 and has been used to mark classes as `shared` (only instanciated onces) within `GeneralUtilitiy`, something is the default behaviour for services in DI as long as not configured otherwise. Having `ConfigurationInterface` and `Configuration` DI aware makes the `SingeltonInterface` obsolete. Services implementing `SingletonInterface` are automatically configured as `public: true` by a TYPO3 DI compiler pass and needs to be set manually when removing the interface from a service. This change ... * Remove `SingletonInterface` from `Configurtion` in favour of default `shared: true` of the DI. * Use Symfony `AsAlias` php attribute on `Configuration` to mark it as the default `ConfigurationInterface` service, addtional setting the service as `public: true` to allow retrieval using `GeneralUtility::makeInstance()`. That prepares towards retrieving services by DI either as constructor or `inject*` methods in the future.
1 parent ec6923d commit 5a0a79c

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Classes/Configuration.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44

55
namespace WebVision\Deepltranslate\Core;
66

7+
use Symfony\Component\DependencyInjection\Attribute\AsAlias;
78
use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationExtensionNotConfiguredException;
89
use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationPathDoesNotExistException;
910
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
10-
use TYPO3\CMS\Core\SingletonInterface;
1111
use TYPO3\CMS\Core\Utility\GeneralUtility;
1212

13-
final class Configuration implements ConfigurationInterface, SingletonInterface
13+
#[AsAlias(id: ConfigurationInterface::class, public: true)]
14+
final class Configuration implements ConfigurationInterface
1415
{
1516
private string $apiKey = '';
1617

0 commit comments

Comments
 (0)