diff --git a/core/core.services.yml b/core/core.services.yml index 9213c11b1f..1dc8a190ea 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -366,6 +366,10 @@ services: - { name: service_collector, tag: 'config.factory.override', call: addOverride } arguments: ['@config.storage', '@event_dispatcher', '@config.typed'] Drupal\Core\Config\ConfigFactoryInterface: '@config.factory' + config.factory.lazy: + class: Drupal\Core\Config\LazyConfigFactory + arguments: ['@config.factory'] + lazy: true config.importer_subscriber: class: Drupal\Core\Config\Importer\FinalMissingContentSubscriber config.installer: diff --git a/core/lib/Drupal/Core/Config/LazyConfigFactory.php b/core/lib/Drupal/Core/Config/LazyConfigFactory.php new file mode 100644 index 0000000000..7575c6b83b --- /dev/null +++ b/core/lib/Drupal/Core/Config/LazyConfigFactory.php @@ -0,0 +1,79 @@ +configFactory->get($name); + } + + /** + * {@inheritdoc} + */ + public function getEditable($name) { + return $this->configFactory->getEditable($name); + } + + /** + * {@inheritdoc} + */ + public function loadMultiple(array $names) { + return $this->configFactory->loadMultiple($names); + } + + /** + * {@inheritdoc} + */ + public function reset($name = NULL) { + return $this->configFactory->reset($name); + } + + /** + * {@inheritdoc} + */ + public function rename($old_name, $new_name) { + return $this->configFactory->rename($old_name, $new_name); + } + + /** + * {@inheritdoc} + */ + public function getCacheKeys() { + return $this->configFactory->getCacheKeys(); + } + + /** + * {@inheritdoc} + */ + public function clearStaticCache() { + return $this->configFactory->clearStaticCache(); + } + + /** + * {@inheritdoc} + */ + public function listAll($prefix = '') { + return $this->configFactory->listAll($prefix); + } + + /** + * {@inheritdoc} + */ + public function addOverride(ConfigFactoryOverrideInterface $config_factory_override) { + return $this->configFactory->addOverride($config_factory_override); + } + +} diff --git a/core/lib/Drupal/Core/ProxyClass/Config/LazyConfigFactory.php b/core/lib/Drupal/Core/ProxyClass/Config/LazyConfigFactory.php new file mode 100644 index 0000000000..8a81769610 --- /dev/null +++ b/core/lib/Drupal/Core/ProxyClass/Config/LazyConfigFactory.php @@ -0,0 +1,144 @@ +container = $container; + $this->drupalProxyOriginalServiceId = $drupal_proxy_original_service_id; + } + + /** + * Lazy loads the real service from the container. + * + * @return object + * Returns the constructed real service. + */ + protected function lazyLoadItself() + { + if (!isset($this->service)) { + $this->service = $this->container->get($this->drupalProxyOriginalServiceId); + } + + return $this->service; + } + + /** + * {@inheritdoc} + */ + public function get($name) + { + return $this->lazyLoadItself()->get($name); + } + + /** + * {@inheritdoc} + */ + public function getEditable($name) + { + return $this->lazyLoadItself()->getEditable($name); + } + + /** + * {@inheritdoc} + */ + public function loadMultiple(array $names) + { + return $this->lazyLoadItself()->loadMultiple($names); + } + + /** + * {@inheritdoc} + */ + public function reset($name = NULL) + { + return $this->lazyLoadItself()->reset($name); + } + + /** + * {@inheritdoc} + */ + public function rename($old_name, $new_name) + { + return $this->lazyLoadItself()->rename($old_name, $new_name); + } + + /** + * {@inheritdoc} + */ + public function getCacheKeys() + { + return $this->lazyLoadItself()->getCacheKeys(); + } + + /** + * {@inheritdoc} + */ + public function clearStaticCache() + { + return $this->lazyLoadItself()->clearStaticCache(); + } + + /** + * {@inheritdoc} + */ + public function listAll($prefix = '') + { + return $this->lazyLoadItself()->listAll($prefix); + } + + /** + * {@inheritdoc} + */ + public function addOverride(\Drupal\Core\Config\ConfigFactoryOverrideInterface $config_factory_override) + { + return $this->lazyLoadItself()->addOverride($config_factory_override); + } + + } + +} diff --git a/core/modules/syslog/src/Logger/SysLog.php b/core/modules/syslog/src/Logger/SysLog.php index ee3c7da402..7eb21746c0 100644 --- a/core/modules/syslog/src/Logger/SysLog.php +++ b/core/modules/syslog/src/Logger/SysLog.php @@ -16,11 +16,11 @@ class SysLog implements LoggerInterface { use RfcLoggerTrait; /** - * A configuration object containing syslog settings. + * Lazy config factory. * - * @var \Drupal\Core\Config\Config + * @var \Drupal\Core\Config\ConfigFactoryInterface */ - protected $config; + protected $configFactory; /** * The message's placeholders parser. @@ -45,7 +45,7 @@ class SysLog implements LoggerInterface { * The parser to use when extracting message variables. */ public function __construct(ConfigFactoryInterface $config_factory, LogMessageParserInterface $parser) { - $this->config = $config_factory->get('syslog.settings'); + $this->configFactory = $config_factory; $this->parser = $parser; } @@ -55,8 +55,9 @@ public function __construct(ConfigFactoryInterface $config_factory, LogMessagePa protected function openConnection() { if (!$this->connectionOpened) { // Do not connect if identity or facility are not configured. - $identity = $this->config->get('identity'); - $facility = $this->config->get('facility'); + $config = $this->configFactory->get('syslog.settings'); + $identity = $config->get('identity'); + $facility = $config->get('facility'); if ($identity === NULL || $facility === NULL) { return; } @@ -70,7 +71,7 @@ protected function openConnection() { public function log($level, string|\Stringable $message, array $context = []): void { global $base_url; - $format = $this->config->get('format'); + $format = $this->configFactory->get('syslog.settings')->get('format'); // If no format is configured then a message will not be written to syslog // so return early. This occurs during installation of the syslog module // before configuration has been written. diff --git a/core/modules/syslog/syslog.services.yml b/core/modules/syslog/syslog.services.yml index 78c7d38ec8..30da283866 100644 --- a/core/modules/syslog/syslog.services.yml +++ b/core/modules/syslog/syslog.services.yml @@ -1,6 +1,7 @@ + services: logger.syslog: class: Drupal\syslog\Logger\SysLog - arguments: ['@config.factory', '@logger.log_message_parser'] + arguments: ['@config.factory.lazy', '@logger.log_message_parser'] tags: - { name: logger }