Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Commit

Permalink
[CLEANUP] Refactor some services
Browse files Browse the repository at this point in the history
  • Loading branch information
romm committed Mar 2, 2017
1 parent 6494c33 commit f70ec7e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
1 change: 1 addition & 0 deletions Classes/Configuration/Settings/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Settings extends AbstractFormzConfiguration

/**
* @var string
* @validate Romm.ConfigurationObject:ClassImplements(interface=TYPO3\CMS\Core\Cache\Backend\BackendInterface)
*/
protected $defaultBackendCache = FileBackend::class;

Expand Down
21 changes: 10 additions & 11 deletions Classes/Service/CacheService.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
namespace Romm\Formz\Service;

use Romm\Formz\Core\Core;
use Romm\Formz\Exceptions\ClassNotFoundException;
use Romm\Formz\Service\Traits\ExtendedFacadeInstanceTrait;
use TYPO3\CMS\Core\Cache\Backend\AbstractBackend;
use TYPO3\CMS\Core\Cache\Backend\BackendInterface;
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
use TYPO3\CMS\Core\SingletonInterface;
Expand Down Expand Up @@ -49,9 +51,14 @@ public function getBackendCache()
{
$backendCache = $this->typoScriptService->getExtensionConfigurationFromPath('settings.defaultBackendCache');

if (false === class_exists($backendCache)
&& false === in_array(AbstractBackend::class, class_parents($backendCache))
) {
if (false === class_exists($backendCache)) {
throw new ClassNotFoundException(
'The cache class name given in configuration "config.tx_formz.settings.defaultBackendCache" was not found (current value: "' . (string)$backendCache . '")',
1488475103
);
}

if (false === in_array(BackendInterface::class, class_implements($backendCache))) {
throw new \Exception(
'The cache class name given in configuration "config.tx_formz.settings.defaultBackendCache" must inherit "' . AbstractBackend::class . '" (current value: "' . (string)$backendCache . '")',
1459251263
Expand Down Expand Up @@ -80,14 +87,6 @@ public function getCacheInstance()
return $this->cacheInstance;
}

/**
* @param FrontendInterface $cacheInstance
*/
public function setCacheInstance(FrontendInterface $cacheInstance)
{
$this->cacheInstance = $cacheInstance;
}

/**
* Generic cache identifier creation for usages in the extension.
*
Expand Down
2 changes: 1 addition & 1 deletion Tests/Unit/FormzUnitTestUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ private function injectTransientMemoryCacheInFormzCore()
$cacheFactory = new CacheFactory('foo', new CacheManager);
$cacheInstance = $cacheFactory->create('foo', VariableFrontend::class, TransientMemoryBackend::class);

CacheService::get()->setCacheInstance($cacheInstance);
$this->inject(CacheService::get(), 'cacheInstance', $cacheInstance);
}

/**
Expand Down

0 comments on commit f70ec7e

Please sign in to comment.