diff --git a/bundles/AdminBundle/Controller/Admin/Document/PrintpageControllerBase.php b/bundles/AdminBundle/Controller/Admin/Document/PrintpageControllerBase.php index 68330bcb8c6..f275d5cd25c 100644 --- a/bundles/AdminBundle/Controller/Admin/Document/PrintpageControllerBase.php +++ b/bundles/AdminBundle/Controller/Admin/Document/PrintpageControllerBase.php @@ -105,7 +105,7 @@ public function saveAction(Request $request): JsonResponse if ($request->get('task') !== self::TASK_SAVE) { //check, if to cleanup existing elements of document $config = Config::getWeb2PrintConfig(); - if ($config->get('generalDocumentSaveMode') == 'cleanup') { + if ($config['generalDocumentSaveMode'] == 'cleanup') { $page->setEditables([]); } } diff --git a/bundles/AdminBundle/Controller/Admin/SettingsController.php b/bundles/AdminBundle/Controller/Admin/SettingsController.php index 41190ac82de..79bbb432c07 100644 --- a/bundles/AdminBundle/Controller/Admin/SettingsController.php +++ b/bundles/AdminBundle/Controller/Admin/SettingsController.php @@ -446,11 +446,9 @@ public function setSystemAction( $values = $this->decodeJson($request->get('data')); - $existingValues = []; - try { $file = Config::locateConfigFile('system.yml'); - $existingValues = Config::getConfigInstance($file, true); + Config::getConfigInstance($file); } catch (\Exception $e) { // nothing to do } @@ -460,7 +458,6 @@ public function setSystemAction( // fallback languages $fallbackLanguages = []; - $existingValues['pimcore']['general']['fallback_languages'] = []; $languages = explode(',', $values['general.validLanguages']); $filteredLanguages = []; @@ -594,8 +591,7 @@ public function getWeb2printAction(Request $request) { $this->checkPermission('web2print_settings'); - $values = Config::getWeb2PrintConfig(); - $valueArray = $values->toArray(); + $valueArray = Config::getWeb2PrintConfig(); $optionsString = []; if ($valueArray['wkhtml2pdfOptions'] ?? false) { @@ -1595,7 +1591,6 @@ public function robotsTxtGetAction() $this->checkPermission('robots.txt'); $config = Config::getRobotsConfig(); - $config = $config->toArray(); return $this->adminJson([ 'success' => true, @@ -1842,7 +1837,7 @@ public function testWeb2printAction(Request $request) ]; } elseif ($adapter instanceof \Pimcore\Web2Print\Processor\HeadlessChrome) { $params = Config::getWeb2PrintConfig(); - $params = $params->get('headlessChromeSettings'); + $params = $params['headlessChromeSettings']; $params = json_decode($params, true); } diff --git a/bundles/AdminBundle/Controller/Reports/AnalyticsController.php b/bundles/AdminBundle/Controller/Reports/AnalyticsController.php index 591cab1be9e..8ea37adc965 100644 --- a/bundles/AdminBundle/Controller/Reports/AnalyticsController.php +++ b/bundles/AdminBundle/Controller/Reports/AnalyticsController.php @@ -51,7 +51,7 @@ public function deeplinkAction(Request $request, SiteConfigProvider $siteConfigP $config = $siteConfigProvider->getSiteConfig(); $url = $request->get('url'); - $url = str_replace(['{accountId}', '{internalWebPropertyId}', '{id}'], [$config->accountid, $config->internalid, $config->profile], $url); + $url = str_replace(['{accountId}', '{internalWebPropertyId}', '{id}'], [$config['accountid'], $config['internalid'], $config['profile']], $url); $url = 'https://www.google.com/analytics/web/' . $url; return $this->redirect($url); @@ -207,7 +207,7 @@ public function chartmetricdataAction(Request $request, SiteConfigProvider $site } $result = $this->service->data_ga->get( - 'ga:' . $config->profile, + 'ga:' . $config['profile'], $startDate, $endDate, implode(',', $metrics), @@ -271,7 +271,7 @@ public function summaryAction(Request $request, SiteConfigProvider $siteConfigPr } $result = $this->service->data_ga->get( - 'ga:' . $config->profile, + 'ga:' . $config['profile'], $startDate, $endDate, 'ga:uniquePageviews,ga:pageviews,ga:exits,ga:bounces,ga:entrances', @@ -351,7 +351,7 @@ public function sourceAction(Request $request, SiteConfigProvider $siteConfigPro } $result = $this->service->data_ga->get( - 'ga:' . $config->profile, + 'ga:' . $config['profile'], $startDate, $endDate, 'ga:pageviews', @@ -423,7 +423,7 @@ public function dataExplorerAction(Request $request, SiteConfigProvider $siteCon } $result = $this->service->data_ga->get( - 'ga:' . $config->profile, + 'ga:' . $config['profile'], $startDate, $endDate, $metric, diff --git a/bundles/AdminBundle/Controller/Reports/ReportsControllerBase.php b/bundles/AdminBundle/Controller/Reports/ReportsControllerBase.php index df801845e80..bfda7dadd4f 100644 --- a/bundles/AdminBundle/Controller/Reports/ReportsControllerBase.php +++ b/bundles/AdminBundle/Controller/Reports/ReportsControllerBase.php @@ -24,7 +24,7 @@ abstract class ReportsControllerBase extends AdminController { /** - * @return \Pimcore\Config\Config + * @return array */ public function getConfig() { diff --git a/bundles/AdminBundle/Controller/Reports/SettingsController.php b/bundles/AdminBundle/Controller/Reports/SettingsController.php index 31576010061..e6cc5e906f4 100644 --- a/bundles/AdminBundle/Controller/Reports/SettingsController.php +++ b/bundles/AdminBundle/Controller/Reports/SettingsController.php @@ -38,7 +38,7 @@ class SettingsController extends ReportsControllerBase public function getAction(Request $request) { $this->checkPermission('system_settings'); - $config = $this->getConfig()->toArray(); + $config = $this->getConfig(); $response = [ 'values' => $config, diff --git a/bundles/CoreBundle/Controller/PublicServicesController.php b/bundles/CoreBundle/Controller/PublicServicesController.php index 2667069ac79..54e71d82ed8 100644 --- a/bundles/CoreBundle/Controller/PublicServicesController.php +++ b/bundles/CoreBundle/Controller/PublicServicesController.php @@ -187,7 +187,7 @@ public function robotsTxtAction(Request $request) $domain = \Pimcore\Tool::getHostname(); $site = Site::getByDomain($domain); - $config = Config::getRobotsConfig()->toArray(); + $config = Config::getRobotsConfig(); $siteId = 'default'; if ($site instanceof Site) { diff --git a/bundles/CoreBundle/EventListener/Frontend/GoogleSearchConsoleVerificationListener.php b/bundles/CoreBundle/EventListener/Frontend/GoogleSearchConsoleVerificationListener.php index b917f29aa07..9703923451c 100644 --- a/bundles/CoreBundle/EventListener/Frontend/GoogleSearchConsoleVerificationListener.php +++ b/bundles/CoreBundle/EventListener/Frontend/GoogleSearchConsoleVerificationListener.php @@ -52,8 +52,8 @@ public function onKernelRequest(RequestEvent $event) $conf = \Pimcore\Config::getReportConfig(); - if (!is_null($conf->get('webmastertools')) && isset($conf->get('webmastertools')->sites)) { - $sites = $conf->get('webmastertools')->sites->toArray(); + if (isset($conf['webmastertools']) && isset($conf['webmastertools']['sites'])) { + $sites = $conf['webmastertools']['sites']; if (is_array($sites)) { foreach ($sites as $site) { diff --git a/bundles/CoreBundle/EventListener/Frontend/GoogleTagManagerListener.php b/bundles/CoreBundle/EventListener/Frontend/GoogleTagManagerListener.php index 7015109aaef..f70fea5bd56 100644 --- a/bundles/CoreBundle/EventListener/Frontend/GoogleTagManagerListener.php +++ b/bundles/CoreBundle/EventListener/Frontend/GoogleTagManagerListener.php @@ -101,11 +101,11 @@ public function onKernelResponse(ResponseEvent $event) $siteKey = $siteId->getConfigKey(); $reportConfig = Config::getReportConfig(); - if (!isset($reportConfig->get('tagmanager')->sites->$siteKey->containerId)) { + if (!isset($reportConfig['tagmanager']['sites'][$siteKey]['containerId'])) { return; } - $containerId = $reportConfig->get('tagmanager')->sites->$siteKey->containerId; + $containerId = $reportConfig['tagmanager']['sites'][$siteKey]['containerId']; if (!$containerId) { return; } diff --git a/bundles/CoreBundle/Migrations/Version20210323110055.php b/bundles/CoreBundle/Migrations/Version20210323110055.php index d0344a09cf6..af03ed9ff09 100644 --- a/bundles/CoreBundle/Migrations/Version20210323110055.php +++ b/bundles/CoreBundle/Migrations/Version20210323110055.php @@ -41,7 +41,6 @@ public function up(Schema $schema): void } $config = Config::getConfigInstance($file); - $config = $config->toArray(); foreach ($config as $siteId => $robotsContent) { SettingsStore::set('robots.txt-' . $siteId, $robotsContent, 'string', 'robots.txt'); diff --git a/bundles/CoreBundle/Migrations/Version20210630062445.php b/bundles/CoreBundle/Migrations/Version20210630062445.php index 231faea6a64..9e1b088aa2a 100644 --- a/bundles/CoreBundle/Migrations/Version20210630062445.php +++ b/bundles/CoreBundle/Migrations/Version20210630062445.php @@ -39,7 +39,6 @@ public function up(Schema $schema): void } $config = Config::getConfigInstance($file); - $config = $config->toArray(); SettingsStore::set( ReportConfigWriter::REPORT_SETTING_ID, diff --git a/bundles/EcommerceFrameworkBundle/IndexService/Config/AbstractConfig.php b/bundles/EcommerceFrameworkBundle/IndexService/Config/AbstractConfig.php index 2bc7d3b2a1b..59b4a5bd619 100644 --- a/bundles/EcommerceFrameworkBundle/IndexService/Config/AbstractConfig.php +++ b/bundles/EcommerceFrameworkBundle/IndexService/Config/AbstractConfig.php @@ -19,7 +19,6 @@ use Pimcore\Bundle\EcommerceFrameworkBundle\IndexService\Worker\WorkerInterface; use Pimcore\Bundle\EcommerceFrameworkBundle\Model\AbstractCategory; use Pimcore\Bundle\EcommerceFrameworkBundle\Model\IndexableInterface; -use Pimcore\Config\Config; use Pimcore\Model\DataObject; abstract class AbstractConfig implements ConfigInterface diff --git a/doc/Development_Documentation/18_Tools_and_Features/27_Website_Settings.md b/doc/Development_Documentation/18_Tools_and_Features/27_Website_Settings.md index 72e2103b9fe..7e62040ccaf 100644 --- a/doc/Development_Documentation/18_Tools_and_Features/27_Website_Settings.md +++ b/doc/Development_Documentation/18_Tools_and_Features/27_Website_Settings.md @@ -14,7 +14,7 @@ Examples: ### Access the Settings In controllers and views, you can use view helpers or argument resolves to access the config. -The returned configuration is a `Pimcore\Config\Config` object containing your settings. +The returned configuration is an array containing your settings. ### Example Configuration @@ -39,9 +39,9 @@ Usage in a controller: get('recaptchaPublic'); + $recaptchaKeyPublic = $websiteConfig['recaptchaPublic']; } } ``` diff --git a/doc/Development_Documentation/23_Installation_and_Upgrade/09_Upgrade_Notes/README.md b/doc/Development_Documentation/23_Installation_and_Upgrade/09_Upgrade_Notes/README.md index 8bcbe318da9..1d05353e7c9 100644 --- a/doc/Development_Documentation/23_Installation_and_Upgrade/09_Upgrade_Notes/README.md +++ b/doc/Development_Documentation/23_Installation_and_Upgrade/09_Upgrade_Notes/README.md @@ -15,7 +15,11 @@ - [Listings] Removed `JsonListing`, please see [#12877](https://github.com/pimcore/pimcore/pull/12877) for details. - [Traits] The traits PackageVersionTrait and StateHelperTrait in lib/Extension/Bundle/Traits have been marked as internal, please see [#12757](https://github.com/pimcore/pimcore/pull/12757) for details. - +- [Config] `Pimcore\Config\Config` has been removed, see [#12477](https://github.com/pimcore/pimcore/issues/12477). Please use the returned array instead, e.g. + ```php + $web2printConfig = Config::getWeb2PrintConfig(); + $web2printConfig = $web2printConfig['headlessChromeSettings']; + - ``` ## 10.5.0 - [Sessions] Changed default value for `symfony.session.cookie_secure` to `auto` diff --git a/lib/Analytics/Google/Config/Config.php b/lib/Analytics/Google/Config/Config.php index ecbab20d7eb..960399c1b78 100644 --- a/lib/Analytics/Google/Config/Config.php +++ b/lib/Analytics/Google/Config/Config.php @@ -17,33 +17,31 @@ namespace Pimcore\Analytics\Google\Config; -use Pimcore\Config\Config as ConfigObject; - class Config { /** - * @var ConfigObject + * @var array */ private $config; - public function __construct(ConfigObject $config) + public function __construct(array $config) { $this->config = $config; } - public static function fromReportConfig(ConfigObject $reportConfig): self + public static function fromReportConfig(array $reportConfig): self { $config = null; - if ($reportConfig->get('analytics')) { - $config = $reportConfig->get('analytics'); + if ($reportConfig['analytics']) { + $config = $reportConfig['analytics']; } else { - $config = new ConfigObject([]); + $config = []; } return new self($config); } - public function getConfig(): ConfigObject + public function getConfig(): array { return $this->config; } @@ -56,7 +54,7 @@ public function isSiteConfigured(string $configKey): bool return false; } - $trackId = $this->normalizeStringValue($config->get('trackid')); + $trackId = $this->normalizeStringValue($config['trackid']); if (null === $trackId) { return false; } @@ -67,22 +65,22 @@ public function isSiteConfigured(string $configKey): bool /** * @param string $configKey * - * @return null|ConfigObject + * @return null|array */ public function getConfigForSite(string $configKey) { - if (!$this->config->get('sites') || !$this->config->get('sites')->$configKey) { + if (!isset($this->config['sites']) || !isset($this->config['sites'][$configKey])) { return null; } - return $this->config->get('sites')->$configKey; + return $this->config['sites'][$configKey]; } public function getConfiguredSites(): array { - $sites = $this->config->get('sites'); - if ($sites && $sites instanceof ConfigObject) { - return array_keys($sites->toArray()); + $sites = $this->config['sites']; + if (is_array($sites)) { + return $sites; } return []; @@ -96,7 +94,7 @@ public function isReportingConfigured(string $configKey): bool return false; } - $profile = $this->normalizeStringValue($config->get('profile')); + $profile = $this->normalizeStringValue($config['profile']); if (null === $profile) { return false; } diff --git a/lib/Analytics/Google/Config/ConfigProvider.php b/lib/Analytics/Google/Config/ConfigProvider.php index 8ae1e6dc501..457c049953b 100644 --- a/lib/Analytics/Google/Config/ConfigProvider.php +++ b/lib/Analytics/Google/Config/ConfigProvider.php @@ -17,8 +17,6 @@ namespace Pimcore\Analytics\Google\Config; -use Pimcore\Config\Config as ConfigObject; - class ConfigProvider { /** @@ -27,14 +25,14 @@ class ConfigProvider private $config; /** - * @var ConfigObject|null + * @var array|null */ private $configObject; /** - * @param ConfigObject|null $configObject + * @param array|null $configObject */ - public function __construct(ConfigObject $configObject = null) + public function __construct(array $configObject = null) { $this->configObject = $configObject; } @@ -48,7 +46,7 @@ public function getConfig(): Config return $this->config; } - private function getConfigObject(): ConfigObject + private function getConfigObject(): array { if (null === $this->configObject) { $this->configObject = $this->loadDefaultConfigObject(); @@ -57,13 +55,13 @@ private function getConfigObject(): ConfigObject return $this->configObject; } - protected function loadDefaultConfigObject(): ConfigObject + protected function loadDefaultConfigObject(): array { $reportConfig = \Pimcore\Config::getReportConfig(); - $config = $reportConfig->get('analytics'); - if (!$config instanceof ConfigObject) { - $config = new ConfigObject([]); + $config = $reportConfig['analytics']; + if (!is_array($config)) { + $config = []; } return $config; diff --git a/lib/Analytics/Google/Config/SiteConfigProvider.php b/lib/Analytics/Google/Config/SiteConfigProvider.php index 669e4bfd20c..646aabadb02 100644 --- a/lib/Analytics/Google/Config/SiteConfigProvider.php +++ b/lib/Analytics/Google/Config/SiteConfigProvider.php @@ -44,7 +44,7 @@ public function __construct( /** * @param Site|null $site * - * @return \Pimcore\Config\Config|null + * @return array|null */ public function getSiteConfig(Site $site = null) { diff --git a/lib/Analytics/Google/Tracker.php b/lib/Analytics/Google/Tracker.php index 618a7227fd4..dd3314d9241 100644 --- a/lib/Analytics/Google/Tracker.php +++ b/lib/Analytics/Google/Tracker.php @@ -25,7 +25,6 @@ use Pimcore\Analytics\Google\Event\TrackingDataEvent; use Pimcore\Analytics\SiteId\SiteId; use Pimcore\Analytics\SiteId\SiteIdProvider; -use Pimcore\Config\Config as ConfigObject; use Pimcore\Event\Analytics\GoogleAnalyticsEvents; use Psr\Log\LoggerAwareTrait; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; @@ -142,12 +141,12 @@ protected function buildCode(SiteId $siteId) * This method exists for BC with the existing Pimcore\Google\Analytics implementation which supports to pass a config * object without a Site ID. Should be removed at a later point. * - * @param ConfigObject $siteConfig + * @param array $siteConfig * @param SiteId|null $siteId * * @return string */ - public function generateCodeForSiteConfig(ConfigObject $siteConfig, SiteId $siteId = null) + public function generateCodeForSiteConfig(array $siteConfig, SiteId $siteId = null) { if (null === $siteId) { $siteId = $this->siteIdProvider->getForRequest(); @@ -161,29 +160,29 @@ public function generateCodeForSiteConfig(ConfigObject $siteConfig, SiteId $site /** * @param SiteId $siteId * @param Config $config - * @param ConfigObject $siteConfig + * @param array $siteConfig * * @return string */ - private function doBuildCode(SiteId $siteId, Config $config, ConfigObject $siteConfig) + private function doBuildCode(SiteId $siteId, Config $config, array $siteConfig) { $data = [ 'siteId' => $siteId, 'config' => $config, 'siteConfig' => $siteConfig, - 'trackId' => $siteConfig->get('trackid'), + 'trackId' => $siteConfig['trackid'], 'defaultPath' => $this->getDefaultPath(), - 'universalConfiguration' => $siteConfig->get('universal_configuration') ?? null, - 'retargeting' => $siteConfig->get('retargetingcode') ?? false, + 'universalConfiguration' => $siteConfig['universal_configuration'] ?? null, + 'retargeting' => $siteConfig['retargetingcode'] ?? false, ]; - if ($siteConfig->get('gtagcode')) { + if ($siteConfig['gtagcode']) { $template = '@PimcoreCore/Analytics/Tracking/Google/Analytics/gtagTrackingCode.html.twig'; - $data['gtagConfig'] = $this->getTrackerConfigurationFromJson($siteConfig->get('universal_configuration') ?? null, [ + $data['gtagConfig'] = $this->getTrackerConfigurationFromJson($siteConfig['universal_configuration'] ?? null, [ 'anonymize_ip' => true, ]); - } elseif ($siteConfig->get('asynchronouscode') || $siteConfig->get('retargetingcode')) { + } elseif (isset($siteConfig['asynchronouscode']) || isset($siteConfig['retargetingcode'])) { $template = '@PimcoreCore/Analytics/Tracking/Google/Analytics/asynchronousTrackingCode.html.twig'; } else { $template = '@PimcoreCore/Analytics/Tracking/Google/Analytics/universalTrackingCode.html.twig'; @@ -214,7 +213,7 @@ private function getTrackerConfigurationFromJson($configValue = null, array $def return array_merge($defaultConfig, $config); } - private function buildCodeBlocks(SiteId $siteId, ConfigObject $siteConfig): array + private function buildCodeBlocks(SiteId $siteId, array $siteConfig): array { $blockData = $this->buildBlockData($siteConfig); @@ -234,20 +233,20 @@ private function buildCodeBlocks(SiteId $siteId, ConfigObject $siteConfig): arra return $blocks; } - private function buildBlockData(ConfigObject $siteConfig): array + private function buildBlockData(array $siteConfig): array { $blockData = []; - if (!empty($siteConfig->get('additionalcodebeforeinit'))) { - $blockData[self::BLOCK_BEFORE_INIT] = $siteConfig->get('additionalcodebeforeinit'); + if (!empty($siteConfig['additionalcodebeforeinit'])) { + $blockData[self::BLOCK_BEFORE_INIT] = $siteConfig['additionalcodebeforeinit']; } - if (!empty($siteConfig->get('additionalcodebeforepageview'))) { - $blockData[self::BLOCK_BEFORE_TRACK] = $siteConfig->get('additionalcodebeforepageview'); + if (!empty($siteConfig['additionalcodebeforepageview'])) { + $blockData[self::BLOCK_BEFORE_TRACK] = $siteConfig['additionalcodebeforepageview']; } - if (!empty($siteConfig->get('additionalcode'))) { - $blockData[self::BLOCK_AFTER_TRACK] = $siteConfig->get('additionalcode'); + if (!empty($siteConfig['additionalcode'])) { + $blockData[self::BLOCK_AFTER_TRACK] = $siteConfig['additionalcode']; } return $blockData; diff --git a/lib/Config.php b/lib/Config.php index f48dd6cffc4..c0e98406f6d 100644 --- a/lib/Config.php +++ b/lib/Config.php @@ -19,7 +19,6 @@ use Exception; use Pimcore; use Pimcore\Cache\RuntimeCache; -use Pimcore\Config\Config as PimcoreConfig; use Pimcore\Config\ReportConfigWriter; use Pimcore\Model\Element\ElementInterface; use Pimcore\Model\Tool\SettingsStore; @@ -191,7 +190,7 @@ public static function getWebsiteConfigRuntimeCacheKey($languange = null) * * @param string|null $language * - * @return PimcoreConfig + * @return array */ public static function getWebsiteConfig($language = null) { @@ -222,7 +221,6 @@ public static function getWebsiteConfig($language = null) $cacheKey = $cacheKey . '_site_' . $siteId; } - /** @var PimcoreConfig|null $config */ $config = Cache::load($cacheKey); if (!$config) { $settingsArray = []; @@ -282,12 +280,9 @@ public static function getWebsiteConfig($language = null) } //TODO resolve for all langs, current lang first, then no lang - $config = new PimcoreConfig($settingsArray, true); - - Cache::save($config, $cacheKey, $cacheTags, null, 998); - } elseif ($config instanceof PimcoreConfig) { - $data = $config->toArray(); - foreach ($data as $key => $setting) { + Cache::save($settingsArray, $cacheKey, $cacheTags, null, 998); + } elseif (is_array($config)) { + foreach ($config as $key => $setting) { if ($setting instanceof ElementInterface) { $elementCacheKey = $setting->getCacheTag(); if (!RuntimeCache::isRegistered($elementCacheKey)) { @@ -306,10 +301,10 @@ public static function getWebsiteConfig($language = null) /** * @internal * - * @param Config\Config|null $config + * @param array|null $config * @param string|null $language */ - public static function setWebsiteConfig(?PimcoreConfig $config, $language = null) + public static function setWebsiteConfig(?array $config, $language = null) { RuntimeCache::set(self::getWebsiteConfigRuntimeCacheKey($language), $config); } @@ -327,23 +322,23 @@ public static function getWebsiteConfigValue($key = null, $default = null, $lang { $config = self::getWebsiteConfig($language); if (null !== $key) { - return $config->get($key, $default); + return $config[$key] ?? $default; } return $config; } /** - * @return PimcoreConfig + * @return array * * @throws Exception * * @internal * @static */ - public static function getReportConfig(): PimcoreConfig + public static function getReportConfig(): array { - $config = null; + $config = []; if (RuntimeCache::isRegistered('pimcore_config_report')) { $config = RuntimeCache::get('pimcore_config_report'); } else { @@ -353,18 +348,13 @@ public static function getReportConfig(): PimcoreConfig ); if ($configJson) { - $configArray = json_decode($configJson->getData(), true); - $config = new PimcoreConfig($configArray); + $config = json_decode($configJson->getData(), true); } } catch (Exception $e) { // nothing to do } } - if (!$config) { - $config = new PimcoreConfig([]); - } - self::setReportConfig($config); return $config; @@ -373,11 +363,11 @@ public static function getReportConfig(): PimcoreConfig /** * @static * - * @param PimcoreConfig $config + * @param array $config * * @internal */ - public static function setReportConfig(PimcoreConfig $config) + public static function setReportConfig(array $config) { RuntimeCache::set('pimcore_config_report', $config); } @@ -385,12 +375,13 @@ public static function setReportConfig(PimcoreConfig $config) /** * @static * - * @return PimcoreConfig + * @return array * * @internal */ public static function getRobotsConfig() { + $config = []; if (RuntimeCache::isRegistered('pimcore_config_robots')) { $config = RuntimeCache::get('pimcore_config_robots'); } else { @@ -401,12 +392,9 @@ public static function getRobotsConfig() foreach ($robotsSettingsIds as $id) { $robots = SettingsStore::get($id, $settingsStoreScope); $siteId = preg_replace('/^robots\.txt\-/', '', $robots->getId()); - $configData[$siteId] = $robots->getData(); + $config[$siteId] = $robots->getData(); } - - $config = new PimcoreConfig($configData); } catch (Exception $e) { - $config = new PimcoreConfig([]); } self::setRobotsConfig($config); @@ -418,11 +406,11 @@ public static function getRobotsConfig() /** * @static * - * @param PimcoreConfig $config + * @param array $config * * @internal */ - public static function setRobotsConfig(PimcoreConfig $config) + public static function setRobotsConfig(array $config) { RuntimeCache::set('pimcore_config_robots', $config); } @@ -430,7 +418,7 @@ public static function setRobotsConfig(PimcoreConfig $config) /** * @static * - * @return PimcoreConfig + * @return array * * @internal */ @@ -449,11 +437,11 @@ public static function getWeb2PrintConfig() /** * @static * - * @param PimcoreConfig $config + * @param array $config * * @internal */ - public static function setWeb2PrintConfig(PimcoreConfig $config) + public static function setWeb2PrintConfig(array $config) { RuntimeCache::set('pimcore_config_web2print', $config); } @@ -461,7 +449,7 @@ public static function setWeb2PrintConfig(PimcoreConfig $config) /** * @static * - * @param PimcoreConfig $config + * @param array $config * * @internal */ @@ -524,13 +512,12 @@ public static function getEnvironment(): string * @internal * * @param string $file - * @param bool $asArray * - * @return Config\Config|array + * @return array * * @throws Exception */ - public static function getConfigInstance($file, bool $asArray = false) + public static function getConfigInstance($file) { $fileType = pathinfo($file, PATHINFO_EXTENSION); if (file_exists($file)) { @@ -541,11 +528,7 @@ public static function getConfigInstance($file, bool $asArray = false) } if (is_array($content)) { - if ($asArray) { - return $content; - } - - return new PimcoreConfig($content); + return $content; } } else { throw new Exception($file . " doesn't exist"); diff --git a/lib/Config/ReportConfigWriter.php b/lib/Config/ReportConfigWriter.php index d8128626905..af122a82f3e 100644 --- a/lib/Config/ReportConfigWriter.php +++ b/lib/Config/ReportConfigWriter.php @@ -64,22 +64,13 @@ public function write(array $settings) ); } - public function mergeConfig(Config $values) + public function mergeConfig(array $values) { // the config returned from getReportConfig is readonly // so we create a new writable one here - $config = new Config( - \Pimcore\Config::getReportConfig()->toArray(), - true - ); - - $config->merge($values); + $config = \Pimcore\Config::getReportConfig(); + $config = array_merge($config, $values); - $this->write($config->toArray()); - } - - public function mergeArray(array $values) - { - $this->mergeConfig(new Config($values)); + $this->write($config); } } diff --git a/lib/Controller/ArgumentValueResolver/WebsiteConfigValueResolver.php b/lib/Controller/ArgumentValueResolver/WebsiteConfigValueResolver.php index 6979fb17c4d..ea8ce8668a5 100644 --- a/lib/Controller/ArgumentValueResolver/WebsiteConfigValueResolver.php +++ b/lib/Controller/ArgumentValueResolver/WebsiteConfigValueResolver.php @@ -21,7 +21,8 @@ use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata; /** - * @internal + * Adds support for type hinting controller actions and getting the current website config. + * */ final class WebsiteConfigValueResolver implements ArgumentValueResolverInterface { @@ -33,7 +34,7 @@ final class WebsiteConfigValueResolver implements ArgumentValueResolverInterface */ public function supports(Request $request, ArgumentMetadata $argument): bool { - return $argument->getType() === Config\Config::class && $argument->getName() === 'websiteConfig'; + return $argument->getType() === "array" && $argument->getName() === 'websiteConfig'; } /** diff --git a/lib/Perspective/Config.php b/lib/Perspective/Config.php index e531f8e711f..9e9486a3405 100644 --- a/lib/Perspective/Config.php +++ b/lib/Perspective/Config.php @@ -145,7 +145,7 @@ public static function getStandardPerspective() 'treeContextMenu' => [ 'document' => [ 'items' => [ - 'addPrintPage' => \Pimcore\Config::getWeb2PrintConfig()->get('enableInDefaultView') ? true : false, // hide add print documents by default + 'addPrintPage' => \Pimcore\Config::getWeb2PrintConfig()['enableInDefaultView'] ? true : false, // hide add print documents by default ], ], ], diff --git a/lib/Web2Print/Config.php b/lib/Web2Print/Config.php index 3a380cfb083..cb30581969c 100644 --- a/lib/Web2Print/Config.php +++ b/lib/Web2Print/Config.php @@ -89,15 +89,15 @@ public static function isWriteable(): bool } /** - * @return \Pimcore\Config\Config + * @return array */ - public static function get(): \Pimcore\Config\Config + public static function get(): array { $repository = self::getRepository(); - list($config) = $repository->loadConfigByKey(self::CONFIG_ID); + $config = $repository->loadConfigByKey(self::CONFIG_ID); - return new \Pimcore\Config\Config($config ?? []); + return $config[0] ?? []; } /** diff --git a/lib/Web2Print/Processor.php b/lib/Web2Print/Processor.php index d3c828f70fa..1da8bbdacb3 100644 --- a/lib/Web2Print/Processor.php +++ b/lib/Web2Print/Processor.php @@ -47,14 +47,14 @@ public static function getInstance() { $config = Config::getWeb2PrintConfig(); - if ($config->get('generalTool') === 'pdfreactor') { + if ($config['generalTool'] === 'pdfreactor') { return new PdfReactor(); - } elseif ($config->get('generalTool') === 'wkhtmltopdf') { + } elseif ($config['generalTool'] === 'wkhtmltopdf') { return new WkHtmlToPdf(); - } elseif ($config->get('generalTool') === 'headlesschrome') { + } elseif ($config['generalTool'] === 'headlesschrome') { return new HeadlessChrome(); } else { - throw new \Exception('Invalid Configuration - ' . $config->get('generalTool')); + throw new \Exception('Invalid Configuration - ' . $config['generalTool']); } } diff --git a/lib/Web2Print/Processor/HeadlessChrome.php b/lib/Web2Print/Processor/HeadlessChrome.php index 07ab4ee94e0..acc6fb3cfd2 100644 --- a/lib/Web2Print/Processor/HeadlessChrome.php +++ b/lib/Web2Print/Processor/HeadlessChrome.php @@ -36,7 +36,7 @@ class HeadlessChrome extends Processor protected function buildPdf(Document\PrintAbstract $document, $config) { $web2printConfig = Config::getWeb2PrintConfig(); - $web2printConfig = $web2printConfig->get('headlessChromeSettings'); + $web2printConfig = $web2printConfig['headlessChromeSettings']; $web2printConfig = json_decode($web2printConfig, true); $params = ['document' => $document]; diff --git a/lib/Web2Print/Processor/PdfReactor.php b/lib/Web2Print/Processor/PdfReactor.php index 8b2a5020ec8..e89e3b70c5a 100644 --- a/lib/Web2Print/Processor/PdfReactor.php +++ b/lib/Web2Print/Processor/PdfReactor.php @@ -43,7 +43,7 @@ protected function getConfig($config) $web2PrintConfig = Config::getWeb2PrintConfig(); $reactorConfig = [ 'document' => '', - 'baseURL' => (string)$web2PrintConfig->get('pdfreactorBaseUrl'), + 'baseURL' => (string)$web2PrintConfig['pdfreactorBaseUrl'], 'author' => $config->author ?? '', 'title' => $config->title ?? '', 'addLinks' => isset($config->links) && $config->links === true, @@ -53,15 +53,15 @@ protected function getConfig($config) 'encryption' => $config->encryption ?? Encryption::NONE, 'addTags' => isset($config->tags) && $config->tags === true, 'logLevel' => $config->loglevel ?? LogLevel::FATAL, - 'enableDebugMode' => $web2PrintConfig->get('pdfreactorEnableDebugMode') || (isset($config->enableDebugMode) && $config->enableDebugMode === true), + 'enableDebugMode' => $web2PrintConfig['pdfreactorEnableDebugMode'] || (isset($config->enableDebugMode) && $config->enableDebugMode === true), 'addOverprint' => isset($config->addOverprint) && $config->addOverprint === true, - 'httpsMode' => $web2PrintConfig->get('pdfreactorEnableLenientHttpsMode') ? HttpsMode::LENIENT : HttpsMode::STRICT, + 'httpsMode' => $web2PrintConfig['pdfreactorEnableLenientHttpsMode'] ? HttpsMode::LENIENT : HttpsMode::STRICT, ]; if (!empty($config->viewerPreference)) { $reactorConfig['viewerPreferences'] = [$config->viewerPreference]; } - if (trim($web2PrintConfig->get('pdfreactorLicence'))) { - $reactorConfig['licenseKey'] = trim($web2PrintConfig->get('pdfreactorLicence')); + if (trim($web2PrintConfig['pdfreactorLicence'])) { + $reactorConfig['licenseKey'] = trim($web2PrintConfig['pdfreactorLicence']); } return $reactorConfig; @@ -75,13 +75,13 @@ protected function getClient() $web2PrintConfig = Config::getWeb2PrintConfig(); $this->includeApi(); - $port = ((string)$web2PrintConfig->get('pdfreactorServerPort')) ? (string)$web2PrintConfig->get('pdfreactorServerPort') : '9423'; - $protocol = ((string)$web2PrintConfig->get('pdfreactorProtocol')) ? (string)$web2PrintConfig->get('pdfreactorProtocol') : 'http'; + $port = ($web2PrintConfig['pdfreactorServerPort']) ? (string)$web2PrintConfig['pdfreactorServerPort'] : '9423'; + $protocol = ($web2PrintConfig['pdfreactorProtocol']) ? (string)$web2PrintConfig['pdfreactorProtocol'] : 'http'; - $pdfreactor = new \com\realobjects\pdfreactor\webservice\client\PDFreactor($protocol . '://' . $web2PrintConfig->get('pdfreactorServer') . ':' . $port . '/service/rest'); + $pdfreactor = new \com\realobjects\pdfreactor\webservice\client\PDFreactor($protocol . '://' . $web2PrintConfig['pdfreactorServer'] . ':' . $port . '/service/rest'); - if (trim($web2PrintConfig->get('pdfreactorApiKey'))) { - $pdfreactor->apiKey = trim($web2PrintConfig->get('pdfreactorApiKey')); + if (trim($web2PrintConfig['pdfreactorApiKey'])) { + $pdfreactor->apiKey = trim($web2PrintConfig['pdfreactorApiKey']); } return $pdfreactor; diff --git a/lib/Web2Print/Processor/WkHtmlToPdf.php b/lib/Web2Print/Processor/WkHtmlToPdf.php index 2fb21e1104c..0828184ef09 100644 --- a/lib/Web2Print/Processor/WkHtmlToPdf.php +++ b/lib/Web2Print/Processor/WkHtmlToPdf.php @@ -59,15 +59,15 @@ public function __construct($wkhtmltopdfBin = null, $options = null) if (!empty($wkhtmltopdfBin)) { $this->wkhtmltopdfBin = $wkhtmltopdfBin; - } elseif ($web2printConfig->get('wkhtmltopdfBin')) { - $this->wkhtmltopdfBin = $web2printConfig->get('wkhtmltopdfBin'); + } elseif ($web2printConfig['wkhtmltopdfBin']) { + $this->wkhtmltopdfBin = $web2printConfig['wkhtmltopdfBin']; } elseif ($determined = Console::getExecutable('wkhtmltopdf')) { $this->wkhtmltopdfBin = $determined; } if (empty($options)) { - if ($web2printConfig->get('wkhtml2pdfOptions')) { - $options = $web2printConfig->get('wkhtml2pdfOptions')->toArray(); + if ($web2printConfig['wkhtml2pdfOptions']) { + $options = $web2printConfig['wkhtml2pdfOptions']->toArray(); } } @@ -96,8 +96,8 @@ protected function buildPdf(Document\PrintAbstract $document, $config) $html = $document->renderDocument($params); $params['hostUrl'] = $config->protocol . '://' . $config->hostName; - if ($web2printConfig->get('wkhtml2pdfHostname')) { - $params['hostUrl'] = $config->protocol . '://' . $web2printConfig->get('wkhtml2pdfHostname'); + if ($web2printConfig['wkhtml2pdfHostname']) { + $params['hostUrl'] = $config->protocol . '://' . $web2printConfig['wkhtml2pdfHostname']; } $html = $this->processHtml($html, $params);