Skip to content

Instantly share code, notes, and snippets.

@johndevman
Created March 31, 2020 12:53
Show Gist options
  • Save johndevman/6f095d41e6d49ed0306bd9683789c905 to your computer and use it in GitHub Desktop.
Save johndevman/6f095d41e6d49ed0306bd9683789c905 to your computer and use it in GitHub Desktop.
Config importer factory
<?php
class ConfigImporterFactory {
/**
* The event dispatcher used to notify subscribers.
*
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
*/
protected $eventDispatcher;
/**
* The configuration manager.
*
* @var \Drupal\Core\Config\ConfigManagerInterface
*/
protected $configManager;
// ...
public function __construct(EventDispatcherInterface $event_dispatcher) {
$this->eventDispatcher = $event_dispatcher;
// ...
}
public function create(StorageComparerInterface $storage_comparer) {
return new ConfigImporter($this->eventDispatcher, $storage_comparer);
}
}
config_importer.factory:
class: Drupal\Core\Config\ConfigImporterFactory
arguments: ['@...']
<?php
class Foo {
public function __construct(ConfigImporterFactory $config_importer_factory) {
}
public function bar() {
// Get a storage comparer somehow...
$storage_comparer = // ...
$config_importer = $this->config_importer_factory->create($storage_comparer)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment