diff --git a/application/Espo/Core/Acl/GlobalRestriction.php b/application/Espo/Core/Acl/GlobalRestriction.php index 64b14fbe90..0a976322d7 100644 --- a/application/Espo/Core/Acl/GlobalRestriction.php +++ b/application/Espo/Core/Acl/GlobalRestriction.php @@ -29,7 +29,7 @@ namespace Espo\Core\Acl; -use Espo\Core\Utils\Config; +use Espo\Core\Utils\Config\SystemConfig; use Espo\Core\Utils\DataCache; use Espo\Core\Utils\FieldUtil; use Espo\Core\Utils\Metadata; @@ -91,10 +91,10 @@ class GlobalRestriction private Metadata $metadata, private DataCache $dataCache, private FieldUtil $fieldUtil, - Config $config + SystemConfig $systemConfig, ) { - $useCache = $config->get('useCache'); + $useCache = $systemConfig->useCache(); if ($useCache && $this->dataCache->has($this->cacheKey)) { /** @var stdClass $cachedData */ diff --git a/application/Espo/Core/Acl/Map/Map.php b/application/Espo/Core/Acl/Map/Map.php index cbfb966d88..5f083029bb 100644 --- a/application/Espo/Core/Acl/Map/Map.php +++ b/application/Espo/Core/Acl/Map/Map.php @@ -57,14 +57,14 @@ class Map public function __construct( Table $table, private DataBuilder $dataBuilder, - private Config $config, private DataCache $dataCache, - CacheKeyProvider $cacheKeyProvider + CacheKeyProvider $cacheKeyProvider, + Config\SystemConfig $systemConfig, ) { $this->cacheKey = $cacheKeyProvider->get(); - if ($this->config->get('useCache') && $this->dataCache->has($this->cacheKey)) { + if ($systemConfig->useCache() && $this->dataCache->has($this->cacheKey)) { /** @var stdClass $cachedData */ $cachedData = $this->dataCache->get($this->cacheKey); @@ -72,7 +72,7 @@ class Map } else { $this->data = $this->dataBuilder->build($table); - if ($this->config->get('useCache')) { + if ($systemConfig->useCache()) { $this->dataCache->store($this->cacheKey, $this->data); } } diff --git a/application/Espo/Core/Acl/Table/DefaultTable.php b/application/Espo/Core/Acl/Table/DefaultTable.php index 56a607b77d..4bcd519f54 100644 --- a/application/Espo/Core/Acl/Table/DefaultTable.php +++ b/application/Espo/Core/Acl/Table/DefaultTable.php @@ -29,6 +29,7 @@ namespace Espo\Core\Acl\Table; +use Espo\Core\Utils\Config\SystemConfig; use Espo\Entities\User; use Espo\Core\Acl\FieldData; @@ -37,7 +38,6 @@ use Espo\Core\Acl\Table; use Espo\Core\Utils\Config; use Espo\Core\Utils\DataCache; use Espo\Core\Utils\Metadata; - use stdClass; use RuntimeException; @@ -96,7 +96,7 @@ class DefaultTable implements Table private RoleListProvider $roleListProvider, CacheKeyProvider $cacheKeyProvider, protected User $user, - Config $config, + SystemConfig $systemConfig, protected Metadata $metadata, DataCache $dataCache, ) { @@ -116,7 +116,7 @@ class DefaultTable implements Table $this->cacheKey = $cacheKeyProvider->get(); - if ($config->get('useCache') && $dataCache->has($this->cacheKey)) { + if ($systemConfig->useCache() && $dataCache->has($this->cacheKey)) { /** @var stdClass $cachedData */ $cachedData = $dataCache->get($this->cacheKey); @@ -124,7 +124,7 @@ class DefaultTable implements Table } else { $this->load(); - if ($config->get('useCache')) { + if ($systemConfig->useCache()) { $dataCache->store($this->cacheKey, $this->data); } } diff --git a/application/Espo/Core/Api/Starter.php b/application/Espo/Core/Api/Starter.php index 550409308b..c232130844 100644 --- a/application/Espo/Core/Api/Starter.php +++ b/application/Espo/Core/Api/Starter.php @@ -30,7 +30,7 @@ namespace Espo\Core\Api; use Espo\Core\Api\Route\RouteParamsFetcher; -use Espo\Core\Utils\Config; +use Espo\Core\Utils\Config\SystemConfig; use Espo\Core\Utils\Route as RouteUtil; use Espo\Core\Utils\Log; @@ -54,7 +54,7 @@ class Starter private RouteParamsFetcher $routeParamsFetcher, private MiddlewareProvider $middlewareProvider, private Log $log, - private Config $config, + private SystemConfig $systemConfig, ?string $routeCacheFile = null ) { $this->routeCacheFile = $routeCacheFile ?? $this->routeCacheFile; @@ -64,7 +64,7 @@ class Starter { $slim = SlimAppFactory::create(); - if ($this->config->get('useCache')) { + if ($this->systemConfig->useCache()) { $slim->getRouteCollector()->setCacheFile($this->routeCacheFile); } diff --git a/application/Espo/Core/Authentication/Oidc/KeysProvider.php b/application/Espo/Core/Authentication/Oidc/KeysProvider.php index 06f02cf130..febb621397 100644 --- a/application/Espo/Core/Authentication/Oidc/KeysProvider.php +++ b/application/Espo/Core/Authentication/Oidc/KeysProvider.php @@ -33,7 +33,7 @@ use Espo\Core\Authentication\Jwt\Exceptions\UnsupportedKey; use Espo\Core\Authentication\Jwt\Key; use Espo\Core\Authentication\Jwt\KeyFactory; use Espo\Core\Field\DateTime; -use Espo\Core\Utils\Config; +use Espo\Core\Utils\Config\SystemConfig; use Espo\Core\Utils\DataCache; use Espo\Core\Utils\Json; use Espo\Core\Utils\Log; @@ -48,10 +48,10 @@ class KeysProvider public function __construct( private DataCache $dataCache, - private Config $config, private ConfigDataProvider $configDataProvider, private KeyFactory $factory, - private Log $log + private Log $log, + private SystemConfig $systemConfig, ) {} /** @@ -147,7 +147,7 @@ class KeysProvider */ private function getRawFromCache(): ?array { - if (!$this->config->get('useCache')) { + if (!$this->systemConfig->useCache()) { return null; } @@ -189,7 +189,7 @@ class KeysProvider */ private function storeRawToCache(array $raw): void { - if (!$this->config->get('useCache')) { + if (!$this->systemConfig->useCache()) { return; } diff --git a/application/Espo/Core/HookManager.php b/application/Espo/Core/HookManager.php index 9ca02acc0d..e9448f5694 100644 --- a/application/Espo/Core/HookManager.php +++ b/application/Espo/Core/HookManager.php @@ -30,7 +30,7 @@ namespace Espo\Core; use Espo\Core\Hook\GeneralInvoker; -use Espo\Core\Utils\Config; +use Espo\Core\Utils\Config\SystemConfig; use Espo\Core\Utils\DataCache; use Espo\Core\Utils\File\Manager as FileManager; use Espo\Core\Utils\Log; @@ -72,11 +72,11 @@ class HookManager private InjectableFactory $injectableFactory, private FileManager $fileManager, private Metadata $metadata, - private Config $config, private DataCache $dataCache, private Log $log, private PathProvider $pathProvider, - private GeneralInvoker $generalInvoker + private GeneralInvoker $generalInvoker, + private SystemConfig $systemConfig, ) {} /** @@ -143,7 +143,7 @@ class HookManager private function loadHooks(): void { - if ($this->config->get('useCache') && $this->dataCache->has($this->cacheKey)) { + if ($this->systemConfig->useCache() && $this->dataCache->has($this->cacheKey)) { /** @var array> $cachedData */ $cachedData = $this->dataCache->get($this->cacheKey); @@ -166,7 +166,7 @@ class HookManager $this->data = $this->sortHooks($data); - if ($this->config->get('useCache')) { + if ($this->systemConfig->useCache()) { $this->dataCache->store($this->cacheKey, $this->data); } } diff --git a/application/Espo/Core/Loaders/Language.php b/application/Espo/Core/Loaders/Language.php index 90ff57bbca..de9d2632a8 100644 --- a/application/Espo/Core/Loaders/Language.php +++ b/application/Espo/Core/Loaders/Language.php @@ -33,7 +33,6 @@ use Espo\Core\Container\Loader; use Espo\Core\InjectableFactory; use Espo\Core\Utils\Config; use Espo\Core\Utils\Language as LanguageService; - use Espo\Entities\Preferences; class Language implements Loader @@ -41,14 +40,15 @@ class Language implements Loader public function __construct( private InjectableFactory $injectableFactory, private Config $config, - private Preferences $preferences + private Preferences $preferences, + private Config\SystemConfig $systemConfig, ) {} public function load(): LanguageService { return $this->injectableFactory->createWith(LanguageService::class, [ 'language' => LanguageService::detectLanguage($this->config, $this->preferences), - 'useCache' => $this->config->get('useCache') ?? false, + 'useCache' => $this->systemConfig->useCache(), ]); } } diff --git a/application/Espo/Core/Portal/Api/Starter.php b/application/Espo/Core/Portal/Api/Starter.php index 6b98650ae0..4beab9d16c 100644 --- a/application/Espo/Core/Portal/Api/Starter.php +++ b/application/Espo/Core/Portal/Api/Starter.php @@ -35,7 +35,7 @@ use Espo\Core\ApplicationState; use Espo\Core\Portal\Utils\Route as RouteUtil; use Espo\Core\Api\RouteProcessor; use Espo\Core\Api\Route\RouteParamsFetcher; -use Espo\Core\Utils\Config; +use Espo\Core\Utils\Config\SystemConfig; use Espo\Core\Utils\Log; class Starter extends StarterBase @@ -46,7 +46,7 @@ class Starter extends StarterBase RouteParamsFetcher $routeParamsFetcher, MiddlewareProvider $middlewareProvider, Log $log, - Config $config, + SystemConfig $systemConfig, ApplicationState $applicationState ) { $routeCacheFile = 'data/cache/application/slim-routes-portal-' . $applicationState->getPortalId() . '.php'; @@ -57,7 +57,7 @@ class Starter extends StarterBase $routeParamsFetcher, $middlewareProvider, $log, - $config, + $systemConfig, $routeCacheFile ); } diff --git a/application/Espo/Core/Utils/Address/CountryDataProvider.php b/application/Espo/Core/Utils/Address/CountryDataProvider.php index 7d2e0a33e1..bda0b84d1d 100644 --- a/application/Espo/Core/Utils/Address/CountryDataProvider.php +++ b/application/Espo/Core/Utils/Address/CountryDataProvider.php @@ -47,10 +47,10 @@ class CountryDataProvider public function __construct( private DataCache $dataCache, - private Config $config, - private EntityManager $entityManager + private EntityManager $entityManager, + Config\SystemConfig $systemConfig, ) { - $this->useCache = (bool) $this->config->get('useCache'); + $this->useCache = $systemConfig->useCache(); } /** diff --git a/application/Espo/Core/Utils/Autoload.php b/application/Espo/Core/Utils/Autoload.php index 63cfffd708..a6ccb7a72a 100644 --- a/application/Espo/Core/Utils/Autoload.php +++ b/application/Espo/Core/Utils/Autoload.php @@ -30,6 +30,7 @@ namespace Espo\Core\Utils; use Espo\Core\Utils\Autoload\Loader; +use Espo\Core\Utils\Config\SystemConfig; use Espo\Core\Utils\File\Manager as FileManager; use Espo\Core\Utils\Resource\PathProvider; @@ -44,12 +45,12 @@ class Autoload private string $autoloadFileName = 'autoload.json'; public function __construct( - private Config $config, private Metadata $metadata, private DataCache $dataCache, private FileManager $fileManager, private Loader $loader, - private PathProvider $pathProvider + private PathProvider $pathProvider, + private SystemConfig $systemConfig, ) {} /** @@ -68,7 +69,7 @@ class Autoload private function init(): void { - $useCache = $this->config->get('useCache'); + $useCache = $this->systemConfig->useCache(); if ($useCache && $this->dataCache->has($this->cacheKey)) { /** @var ?array $data */ diff --git a/application/Espo/Core/Utils/Autoload/NamespaceLoader.php b/application/Espo/Core/Utils/Autoload/NamespaceLoader.php index e29be71fbe..9216d9f4dc 100644 --- a/application/Espo/Core/Utils/Autoload/NamespaceLoader.php +++ b/application/Espo/Core/Utils/Autoload/NamespaceLoader.php @@ -29,7 +29,7 @@ namespace Espo\Core\Utils\Autoload; -use Espo\Core\Utils\Config; +use Espo\Core\Utils\Config\SystemConfig; use Espo\Core\Utils\DataCache; use Espo\Core\Utils\File\Manager as FileManager; use Espo\Core\Utils\Log; @@ -68,10 +68,10 @@ class NamespaceLoader private ClassLoader $classLoader; public function __construct( - private Config $config, private DataCache $dataCache, private FileManager $fileManager, - private Log $log + private Log $log, + private SystemConfig $systemConfig, ) { $this->classLoader = new ClassLoader(); @@ -231,7 +231,7 @@ class NamespaceLoader */ private function getVendorNamespaces(string $path): array { - $useCache = $this->config->get('useCache'); + $useCache = $this->systemConfig->useCache(); if (!isset($this->vendorNamespaces)) { $this->vendorNamespaces = []; diff --git a/application/Espo/Core/Utils/ClientManager.php b/application/Espo/Core/Utils/ClientManager.php index 48a576b5d9..ac3b096517 100644 --- a/application/Espo/Core/Utils/ClientManager.php +++ b/application/Espo/Core/Utils/ClientManager.php @@ -36,6 +36,8 @@ use Espo\Core\Utils\Client\LoaderParamsProvider; use Espo\Core\Utils\Client\RenderParams; use Espo\Core\Utils\Client\Script; use Espo\Core\Utils\Client\SecurityParams; +use Espo\Core\Utils\Config\ApplicationConfig; +use Espo\Core\Utils\Config\SystemConfig; use Espo\Core\Utils\File\Manager as FileManager; use Slim\Psr7\Response as Psr7Response; @@ -66,6 +68,8 @@ class ClientManager private DevModeJsFileListProvider $devModeJsFileListProvider, private Module $module, private LoaderParamsProvider $loaderParamsProvider, + private SystemConfig $systemConfig, + private ApplicationConfig $applicationConfig, ) { $this->nonce = Util::generateKey(); } @@ -130,7 +134,7 @@ class ClientManager return; } - $siteUrl = $this->config->get('siteUrl') ?? ''; + $siteUrl = $this->applicationConfig->getSiteUrl(); if (str_starts_with($siteUrl, 'https://')) { $response->setHeader('Strict-Transport-Security', 'max-age=10368000'); @@ -308,7 +312,7 @@ class ClientManager private function useCache(): bool { - return (bool) $this->config->get('useCache'); + return $this->systemConfig->useCache(); } private function useCacheInDeveloperMode(): bool diff --git a/application/Espo/Core/Utils/Config/ApplicationConfig.php b/application/Espo/Core/Utils/Config/ApplicationConfig.php index f3c7addedc..da8cfdbed0 100644 --- a/application/Espo/Core/Utils/Config/ApplicationConfig.php +++ b/application/Espo/Core/Utils/Config/ApplicationConfig.php @@ -42,7 +42,7 @@ class ApplicationConfig public function getSiteUrl(): string { - return rtrim($this->config->get('siteUrl'), '/'); + return rtrim($this->config->get('siteUrl') ?? '', '/'); } public function getDateFormat(): string diff --git a/application/Espo/Core/Utils/Config/SystemConfig.php b/application/Espo/Core/Utils/Config/SystemConfig.php new file mode 100644 index 0000000000..be8dd92353 --- /dev/null +++ b/application/Espo/Core/Utils/Config/SystemConfig.php @@ -0,0 +1,48 @@ +. + * + * The interactive user interfaces in modified source and object code versions + * of this program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU Affero General Public License version 3. + * + * In accordance with Section 7(b) of the GNU Affero General Public License version 3, + * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. + ************************************************************************/ + +namespace Espo\Core\Utils\Config; + + +use Espo\Core\Utils\Config; + +/** + * @since 9.1.0 + */ +class SystemConfig +{ + public function __construct( + private Config $config, + ) {} + + public function useCache(): bool + { + return (bool) $this->config->get('useCache'); + } +} diff --git a/application/Espo/Core/Utils/EmailFilterManager.php b/application/Espo/Core/Utils/EmailFilterManager.php index 914af9c2a1..769c8c34c4 100644 --- a/application/Espo/Core/Utils/EmailFilterManager.php +++ b/application/Espo/Core/Utils/EmailFilterManager.php @@ -31,6 +31,7 @@ namespace Espo\Core\Utils; use Espo\Core\ORM\EntityManager; use Espo\Core\Mail\FiltersMatcher; +use Espo\Core\Utils\Config\SystemConfig; use Espo\Entities\Email; use Espo\Entities\EmailFilter; use Espo\Entities\User; @@ -54,9 +55,9 @@ class EmailFilterManager private EntityManager $entityManager, private FiltersMatcher $filtersMatcher, private DataCache $dataCache, - Config $config + SystemConfig $systemConfig, ) { - $this->useCache = (bool) $config->get('useCache'); + $this->useCache = $systemConfig->useCache(); } public function getMatchingFilter(Email $email, string $userId): ?EmailFilter diff --git a/application/Espo/Core/Utils/File/ClassMap.php b/application/Espo/Core/Utils/File/ClassMap.php index 8e5222209d..e766b0688c 100644 --- a/application/Espo/Core/Utils/File/ClassMap.php +++ b/application/Espo/Core/Utils/File/ClassMap.php @@ -42,10 +42,10 @@ class ClassMap { public function __construct( private FileManager $fileManager, - private Config $config, private Module $module, private DataCache $dataCache, - private PathProvider $pathProvider + private PathProvider $pathProvider, + private Config\SystemConfig $systemConfig, ) {} /** @@ -66,7 +66,7 @@ class ClassMap if ( $cacheKey && $this->dataCache->has($cacheKey) && - $this->config->get('useCache') + $this->systemConfig->useCache() ) { /** @var array $data */ $data = $this->dataCache->get($cacheKey); @@ -102,7 +102,7 @@ class ClassMap ) ); - if ($cacheKey && $this->config->get('useCache')) { + if ($cacheKey && $this->systemConfig->useCache()) { $this->dataCache->store($cacheKey, $data); } diff --git a/application/Espo/Core/Utils/Language/LanguageFactory.php b/application/Espo/Core/Utils/Language/LanguageFactory.php index a50f5e412e..9d53537df2 100644 --- a/application/Espo/Core/Utils/Language/LanguageFactory.php +++ b/application/Espo/Core/Utils/Language/LanguageFactory.php @@ -37,14 +37,14 @@ class LanguageFactory { public function __construct( private InjectableFactory $injectableFactory, - private Config $config, + private Config\SystemConfig $systemConfig, ) {} public function create(string $language): Language { return $this->injectableFactory->createWith(Language::class, [ 'language' => $language, - 'useCache' => $this->config->get('useCache') ?? false, + 'useCache' => $this->systemConfig->useCache(), ]); } } diff --git a/application/Espo/Core/Utils/Metadata/OrmMetadataData.php b/application/Espo/Core/Utils/Metadata/OrmMetadataData.php index c4ccf6fd03..361f16c7f3 100644 --- a/application/Espo/Core/Utils/Metadata/OrmMetadataData.php +++ b/application/Espo/Core/Utils/Metadata/OrmMetadataData.php @@ -45,11 +45,10 @@ class OrmMetadataData public function __construct( private DataCache $dataCache, - private Config $config, - private InjectableFactory $injectableFactory + private InjectableFactory $injectableFactory, + Config\SystemConfig $systemConfig, ) { - - $this->useCache = (bool) $this->config->get('useCache', false); + $this->useCache = $systemConfig->useCache(); } private function getConverter(): Converter diff --git a/application/Espo/Core/Utils/Route.php b/application/Espo/Core/Utils/Route.php index ce73620ffd..2560b55d74 100644 --- a/application/Espo/Core/Utils/Route.php +++ b/application/Espo/Core/Utils/Route.php @@ -31,6 +31,7 @@ namespace Espo\Core\Utils; use Espo\Core\Api\Action; use Espo\Core\Api\Route as RouteItem; +use Espo\Core\Utils\Config\SystemConfig; use Espo\Core\Utils\File\Manager as FileManager; use Espo\Core\Utils\Resource\PathProvider; @@ -52,11 +53,11 @@ class Route private string $routesFileName = 'routes.json'; public function __construct( - private Config $config, private Metadata $metadata, private FileManager $fileManager, private DataCache $dataCache, - private PathProvider $pathProvider + private PathProvider $pathProvider, + private SystemConfig $systemConfig, ) {} /** @@ -89,7 +90,7 @@ class Route private function init(): void { - $useCache = $this->config->get('useCache'); + $useCache = $this->systemConfig->useCache(); if ($this->dataCache->has($this->cacheKey) && $useCache) { /** @var ?(RouteArrayShape[]) $data */ diff --git a/application/Espo/Core/Webhook/Manager.php b/application/Espo/Core/Webhook/Manager.php index 2dff319b3a..871809350f 100644 --- a/application/Espo/Core/Webhook/Manager.php +++ b/application/Espo/Core/Webhook/Manager.php @@ -33,6 +33,7 @@ use Espo\Core\Name\Field; use Espo\Core\ORM\Entity; use Espo\Core\ORM\EntityManager; use Espo\Core\Utils\Config; +use Espo\Core\Utils\Config\SystemConfig; use Espo\Core\Utils\DataCache; use Espo\Core\Utils\FieldUtil; use Espo\Core\Utils\Log; @@ -65,7 +66,8 @@ class Manager private DataCache $dataCache, private EntityManager $entityManager, private FieldUtil $fieldUtil, - private Log $log + private Log $log, + private SystemConfig $systemConfig, ) { $this->loadData(); @@ -73,7 +75,7 @@ class Manager private function loadData(): void { - if ($this->config->get('useCache') && $this->dataCache->has($this->cacheKey)) { + if ($this->systemConfig->useCache() && $this->dataCache->has($this->cacheKey)) { /** @var array $data */ $data = $this->dataCache->get($this->cacheKey); @@ -83,7 +85,7 @@ class Manager if (is_null($this->data)) { $this->data = $this->buildData(); - if ($this->config->get('useCache')) { + if ($this->systemConfig->useCache()) { $this->storeDataToCache(); } } @@ -132,7 +134,7 @@ class Manager { $this->data[$event] = true; - if ($this->config->get('useCache')) { + if ($this->systemConfig->useCache()) { $this->storeDataToCache(); } } @@ -154,7 +156,7 @@ class Manager if ($notExists) { unset($this->data[$event]); - if ($this->config->get('useCache')) { + if ($this->systemConfig->useCache()) { $this->storeDataToCache(); } } diff --git a/application/Espo/Tools/AdminNotifications/Manager.php b/application/Espo/Tools/AdminNotifications/Manager.php index 164edcbef4..b064c4bb6b 100644 --- a/application/Espo/Tools/AdminNotifications/Manager.php +++ b/application/Espo/Tools/AdminNotifications/Manager.php @@ -46,7 +46,8 @@ class Manager private EntityManager $entityManager, private Config $config, private Language $language, - private ScheduledJob $scheduledJob + private ScheduledJob $scheduledJob, + private Config\SystemConfig $systemConfig, ) {} /** @@ -60,7 +61,7 @@ class Manager return []; } - if (!$this->config->get('useCache')) { + if (!$this->systemConfig->useCache()) { $notificationList[] = [ 'id' => 'cacheIsDisabled', 'type' => 'cacheIsDisabled', diff --git a/application/Espo/Tools/App/Language/AclDependencyProvider.php b/application/Espo/Tools/App/Language/AclDependencyProvider.php index 01c84f8972..2737bb35b0 100644 --- a/application/Espo/Tools/App/Language/AclDependencyProvider.php +++ b/application/Espo/Tools/App/Language/AclDependencyProvider.php @@ -31,6 +31,7 @@ namespace Espo\Tools\App\Language; use Espo\Core\ORM\Type\FieldType; use Espo\Core\Utils\Config; +use Espo\Core\Utils\Config\SystemConfig; use Espo\Core\Utils\DataCache; use Espo\Core\Utils\Metadata; use Espo\ORM\Defs; @@ -54,10 +55,10 @@ class AclDependencyProvider public function __construct( private DataCache $dataCache, private Metadata $metadata, - Config $config, - private Defs $ormDefs + private Defs $ormDefs, + SystemConfig $systemConfig, ) { - $this->useCache = $config->get('useCache'); + $this->useCache = $systemConfig->useCache(); } /** diff --git a/application/Espo/Tools/App/Metadata/AclDependencyProvider.php b/application/Espo/Tools/App/Metadata/AclDependencyProvider.php index 51cfffbbe4..2aefcc5655 100644 --- a/application/Espo/Tools/App/Metadata/AclDependencyProvider.php +++ b/application/Espo/Tools/App/Metadata/AclDependencyProvider.php @@ -54,10 +54,10 @@ class AclDependencyProvider public function __construct( private DataCache $dataCache, private Metadata $metadata, - Config $config, - private Defs $ormDefs + private Defs $ormDefs, + Config\SystemConfig $systemConfig, ) { - $this->useCache = $config->get('useCache'); + $this->useCache = $systemConfig->useCache(); } /** diff --git a/application/Espo/Tools/App/SettingsService.php b/application/Espo/Tools/App/SettingsService.php index 76d24e4ca6..bb0d726c3a 100644 --- a/application/Espo/Tools/App/SettingsService.php +++ b/application/Espo/Tools/App/SettingsService.php @@ -68,7 +68,8 @@ class SettingsService private InjectableFactory $injectableFactory, private Access $access, private AuthenticationMethodProvider $authenticationMethodProvider, - private ThemeManager $themeManager + private ThemeManager $themeManager, + private Config\SystemConfig $systemConfig, ) {} /** @@ -222,7 +223,7 @@ class SettingsService if ( isset($data->useCache) && - $data->useCache !== $this->config->get('useCache') + $data->useCache !== $this->systemConfig->useCache() ) { $this->dataManager->clearCache(); } diff --git a/application/Espo/Tools/LeadCapture/FormService.php b/application/Espo/Tools/LeadCapture/FormService.php index 9725ed4d1b..6f897e9966 100644 --- a/application/Espo/Tools/LeadCapture/FormService.php +++ b/application/Espo/Tools/LeadCapture/FormService.php @@ -59,6 +59,7 @@ class FormService private Language\LanguageFactory $languageFactory, private DataCache $dataCache, private ThemeManager $themeManager, + private Config\SystemConfig $systemConfig, ) {} /** @@ -86,7 +87,7 @@ class FormService { $cacheKey = $this->getCacheKey($leadCapture); - if ($this->config->get('useCache') && $this->dataCache->has($cacheKey)) { + if ($this->systemConfig->useCache() && $this->dataCache->has($cacheKey)) { return $this->getFromCache($cacheKey); } diff --git a/tests/unit/Espo/Core/Acl/Map/MapTest.php b/tests/unit/Espo/Core/Acl/Map/MapTest.php index 9ca3e44f2f..4923f6228c 100644 --- a/tests/unit/Espo/Core/Acl/Map/MapTest.php +++ b/tests/unit/Espo/Core/Acl/Map/MapTest.php @@ -29,8 +29,6 @@ namespace tests\unit\Espo\Core\Acl\Map; -use Espo\Entities\User; - use Espo\Core\Acl\FieldData; use Espo\Core\Acl\Map\CacheKeyProvider; use Espo\Core\Acl\Map\DataBuilder; @@ -42,31 +40,30 @@ use Espo\Core\Utils\Config; use Espo\Core\Utils\DataCache; use Espo\Core\Utils\FieldUtil; +use PHPUnit\Framework\TestCase; use stdClass; -class MapTest extends \PHPUnit\Framework\TestCase +class MapTest extends TestCase { private $fieldUtil; - private $config; + private $systemConfig; private $table; private $metadataProvider; private $cacheKeyProvider; protected function setUp(): void { - $this->config = $this->createMock(Config::class); + $this->systemConfig = $this->createMock(Config\SystemConfig::class); $this->fieldUtil = $this->createMock(FieldUtil::class); $this->table = $this->createMock(Table::class); $this->dataCache = $this->createMock(DataCache::class); $this->metadataProvider = $this->createMock(MetadataProvider::class); $this->cacheKeyProvider = $this->createMock(CacheKeyProvider::class); - $this->config + $this->systemConfig ->expects($this->any()) - ->method('get') - ->willReturnMap([ - ['useCache', false] - ]); + ->method('useCache') + ->willReturn(false); } private function mockTableData(array $scopeData, array $fieldData, array $permissionData): void @@ -206,9 +203,9 @@ class MapTest extends \PHPUnit\Framework\TestCase $map = new Map( $this->table, $dataBuilder, - $this->config, $this->dataCache, - $this->cacheKeyProvider + $this->cacheKeyProvider, + $this->systemConfig, ); $this->assertEquals($expectedData, $map->getData()); diff --git a/tests/unit/Espo/Core/HookManagerTest.php b/tests/unit/Espo/Core/HookManagerTest.php index d8587a695f..35d0c8cd01 100644 --- a/tests/unit/Espo/Core/HookManagerTest.php +++ b/tests/unit/Espo/Core/HookManagerTest.php @@ -29,31 +29,33 @@ namespace tests\unit\Espo\Core; +use PHPUnit\Framework\TestCase; use tests\unit\ReflectionHelper; -use Espo\Core\{ - Hook\GeneralInvoker, - HookManager, - InjectableFactory, - Utils\Metadata, - Utils\Config, - Utils\File\Manager as FileManager, - Utils\DataCache, - Utils\Log, - Utils\Module\PathProvider}; +use Espo\Core\Hook\GeneralInvoker; +use Espo\Core\HookManager; +use Espo\Core\InjectableFactory; +use Espo\Core\Utils\Config; +use Espo\Core\Utils\DataCache; +use Espo\Core\Utils\File\Manager as FileManager; +use Espo\Core\Utils\Log; +use Espo\Core\Utils\Metadata; +use Espo\Core\Utils\Module\PathProvider; -class HookManagerTest extends \PHPUnit\Framework\TestCase +class HookManagerTest extends TestCase { private $hookManager; private $filesPath = 'tests/unit/testData/Hooks'; + private ?Config\SystemConfig $systemConfig = null; + protected function setUp(): void { $this->metadata = $this->createMock(Metadata::class); $this->getMockBuilder(Metadata::class)->disableOriginalConstructor()->getMock(); - $this->config = $this->createMock(Config::class); + $this->systemConfig = $this->createMock(Config\SystemConfig::class); $this->injectableFactory = $this->createMock(InjectableFactory::class); $this->dataCache = $this->createMock(DataCache::class); @@ -65,11 +67,11 @@ class HookManagerTest extends \PHPUnit\Framework\TestCase $this->injectableFactory, $this->fileManager, $this->metadata, - $this->config, $this->dataCache, $this->createMock(Log::class), $this->pathProvider, - $this->generalInvoker + $this->generalInvoker, + $this->systemConfig, ); $this->reflection = new ReflectionHelper($this->hookManager); @@ -255,9 +257,9 @@ class HookManagerTest extends \PHPUnit\Framework\TestCase { $this->initPathProvider('testCase1'); - $this->config + $this->systemConfig ->expects($this->exactly(2)) - ->method('get') + ->method('useCache') ->will($this->returnValue(false)); $this->metadata @@ -290,9 +292,9 @@ class HookManagerTest extends \PHPUnit\Framework\TestCase { $this->initPathProvider('testCase2'); - $this->config + $this->systemConfig ->expects($this->exactly(2)) - ->method('get') + ->method('useCache') ->will($this->returnValue(false)); $this->metadata @@ -326,9 +328,9 @@ class HookManagerTest extends \PHPUnit\Framework\TestCase { $this->initPathProvider('testCase2'); - $this->config + $this->systemConfig ->expects($this->exactly(2)) - ->method('get') + ->method('useCache') ->will($this->returnValue(false)); $this->metadata @@ -362,9 +364,9 @@ class HookManagerTest extends \PHPUnit\Framework\TestCase { $this->initPathProvider('testCase3'); - $this->config + $this->systemConfig ->expects($this->exactly(2)) - ->method('get') + ->method('useCache') ->will($this->returnValue(false)); $this->metadata diff --git a/tests/unit/Espo/Core/Utils/AutoloadTest.php b/tests/unit/Espo/Core/Utils/AutoloadTest.php index 186410a7b6..07d24415b4 100644 --- a/tests/unit/Espo/Core/Utils/AutoloadTest.php +++ b/tests/unit/Espo/Core/Utils/AutoloadTest.php @@ -29,21 +29,22 @@ namespace tests\unit\Espo\Core\Utils; -use Espo\Core\{ - Utils\Autoload, - Utils\Config, - Utils\Metadata, - Utils\Autoload\Loader, - Utils\DataCache, - Utils\File\Manager as FileManager, - Utils\Resource\PathProvider, -}; +use Espo\Core\Utils\Autoload; +use Espo\Core\Utils\Autoload\Loader; +use Espo\Core\Utils\Config; +use Espo\Core\Utils\DataCache; +use Espo\Core\Utils\File\Manager as FileManager; +use Espo\Core\Utils\Metadata; +use Espo\Core\Utils\Resource\PathProvider; +use PHPUnit\Framework\TestCase; -class AutoloadTest extends \PHPUnit\Framework\TestCase +class AutoloadTest extends TestCase { + private ?Config\SystemConfig $systemConfig = null; + protected function setUp(): void { - $this->config = $this->createMock(Config::class); + $this->systemConfig = $this->createMock(Config\SystemConfig::class); $this->metadata = $this->createMock(Metadata::class); $this->dataCache = $this->createMock(DataCache::class); $this->fileManager = $this->createMock(FileManager::class); @@ -53,12 +54,12 @@ class AutoloadTest extends \PHPUnit\Framework\TestCase $this->initPathProvider(); $this->autoload = new Autoload( - $this->config, $this->metadata, $this->dataCache, $this->fileManager, $this->loader, - $this->pathProvider + $this->pathProvider, + $this->systemConfig, ); } @@ -94,10 +95,9 @@ class AutoloadTest extends \PHPUnit\Framework\TestCase ->method('getModuleList') ->willReturn(['M1', 'M2']); - $this->config + $this->systemConfig ->expects($this->once()) - ->method('get') - ->with('useCache') + ->method('useCache') ->willReturn(false); $this->fileManager diff --git a/tests/unit/Espo/Core/Utils/File/ClassMapTest.php b/tests/unit/Espo/Core/Utils/File/ClassMapTest.php index 55d3ac8e18..d90825f5d1 100644 --- a/tests/unit/Espo/Core/Utils/File/ClassMapTest.php +++ b/tests/unit/Espo/Core/Utils/File/ClassMapTest.php @@ -29,18 +29,16 @@ namespace tests\unit\Espo\Core\Utils\File; +use PHPUnit\Framework\TestCase; use tests\unit\ReflectionHelper; - use Espo\Core\Utils\File\ClassMap; use Espo\Core\Utils\DataCache; use Espo\Core\Utils\File\Manager as FileManager; - use Espo\Core\Utils\Config; use Espo\Core\Utils\Module; - use Espo\Core\Utils\Module\PathProvider; -class ClassMapTest extends \PHPUnit\Framework\TestCase +class ClassMapTest extends TestCase { /** * @var ClassMap @@ -50,9 +48,7 @@ class ClassMapTest extends \PHPUnit\Framework\TestCase protected $reflection; private $customPath = 'tests/unit/testData/EntryPoints/Espo/Custom/'; - private $corePath = 'tests/unit/testData/EntryPoints/Espo/'; - private $modulePath = 'tests/unit/testData/EntryPoints/Espo/Modules/{*}/'; /** @@ -64,7 +60,7 @@ class ClassMapTest extends \PHPUnit\Framework\TestCase { $this->fileManager = new FileManager(); - $this->config = $this->createMock(Config::class); + $this->systemConfig = $this->createMock(Config\SystemConfig::class); $this->module = $this->createMock(Module::class); $this->dataCache = $this->createMock(DataCache::class); @@ -97,10 +93,10 @@ class ClassMapTest extends \PHPUnit\Framework\TestCase $this->classMap = new ClassMap( $this->fileManager, - $this->config, $this->module, $this->dataCache, - $pathProvider + $pathProvider, + $this->systemConfig, ); $this->reflection = new ReflectionHelper($this->classMap); @@ -125,9 +121,9 @@ class ClassMapTest extends \PHPUnit\Framework\TestCase ->with('entryPoints') ->willReturn(true); - $this->config + $this->systemConfig ->expects($this->exactly(2)) - ->method('get') + ->method('useCache') ->will($this->returnValue(false)); $this->module @@ -157,9 +153,9 @@ class ClassMapTest extends \PHPUnit\Framework\TestCase 'Download' => 'tests\\unit\\testData\\EntryPoints\\Espo\\EntryPoints\\Download', ]; - $this->config + $this->systemConfig ->expects($this->once()) - ->method('get') + ->method('useCache') ->will($this->returnValue(true)); $cacheKey = 'entryPoints'; @@ -185,10 +181,9 @@ class ClassMapTest extends \PHPUnit\Framework\TestCase public function testGetDataWithNoCacheString(): void { - $this->config + $this->systemConfig ->expects($this->exactly(2)) - ->method('get') - ->with('useCache') + ->method('useCache') ->will($this->returnValue(true)); $this->module diff --git a/tests/unit/Espo/Core/Utils/RouteTest.php b/tests/unit/Espo/Core/Utils/RouteTest.php index bf55a65675..de5e0214c0 100644 --- a/tests/unit/Espo/Core/Utils/RouteTest.php +++ b/tests/unit/Espo/Core/Utils/RouteTest.php @@ -45,7 +45,6 @@ class RouteTest extends TestCase protected function setUp(): void { - $this->config = $this->createMock(Config::class); $this->fileManager = new FileManager(); $this->metadata = $this->createMock(Metadata::class); @@ -53,11 +52,11 @@ class RouteTest extends TestCase $this->pathProvider = $this->createMock(PathProvider::class); $this->route = new Route( - $this->config, $this->metadata, $this->fileManager, $this->dataCache, - $this->pathProvider + $this->pathProvider, + $this->createMock(Config\SystemConfig::class), ); }