Created
March 31, 2020 12:53
-
-
Save johndevman/6f095d41e6d49ed0306bd9683789c905 to your computer and use it in GitHub Desktop.
Config importer factory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
config_importer.factory: | |
class: Drupal\Core\Config\ConfigImporterFactory | |
arguments: ['@...'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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