final class YamlDefinitionsLoader in Hook Event Dispatcher 3.x
Same name and namespace in other branches
- 8.2 modules/preprocess_event_dispatcher/tests/src/Unit/Helpers/YamlDefinitionsLoader.php \Drupal\Tests\preprocess_event_dispatcher\Unit\Helpers\YamlDefinitionsLoader
Class YamlDefinitionsLoader.
Hierarchy
- class \Drupal\Tests\preprocess_event_dispatcher\Unit\Helpers\YamlDefinitionsLoader
Expanded class hierarchy of YamlDefinitionsLoader
6 files declare their use of YamlDefinitionsLoader
- EntityEventTest.php in modules/
preprocess_event_dispatcher/ tests/ src/ Unit/ EntityEventTest.php - EntityEventVariablesTest.php in modules/
preprocess_event_dispatcher/ tests/ src/ Unit/ EntityEventVariablesTest.php - FactoryMapperTest.php in modules/
preprocess_event_dispatcher/ tests/ src/ Unit/ FactoryMapperTest.php - OtherEventTest.php in modules/
preprocess_event_dispatcher/ tests/ src/ Unit/ OtherEventTest.php - OtherEventVariablesTest.php in modules/
preprocess_event_dispatcher/ tests/ src/ Unit/ OtherEventVariablesTest.php
File
- modules/
preprocess_event_dispatcher/ tests/ src/ Unit/ Helpers/ YamlDefinitionsLoader.php, line 13
Namespace
Drupal\Tests\preprocess_event_dispatcher\Unit\HelpersView source
final class YamlDefinitionsLoader {
/**
* Singleton instance of this class.
*
* @var YamlDefinitionsLoader
*/
private static $instance;
/**
* Factory mapper.
*
* @var \Drupal\preprocess_event_dispatcher\Service\PreprocessEventFactoryMapper
*/
private $mapper;
/**
* Service definitions loaded from the YAML services file.
*
* @var array
*/
private $services;
/**
* Factory definitions loaded from the YAML services file.
*
* @var array
*/
private $factories;
/**
* YamlDefinitionsLoader constructor.
*/
private function __construct() {
$this
->loadDefinitionsFromServicesYaml();
$this
->setUpFactoriesMapper();
}
/**
* Load the definitions from the services YAML.
*/
private function loadDefinitionsFromServicesYaml() : void {
$yaml = new Parser();
$content = file_get_contents(dirname(__DIR__, 4) . '/preprocess_event_dispatcher.services.yml');
$factories = $this->services = $yaml
->parse($content)['services'];
// Remove the Service and Factory Mapper.
unset($factories['preprocess_event.service'], $factories['preprocess_event.factory_mapper']);
$this->factories = $factories;
}
/**
* Set up Factories Mapper.
*/
private function setUpFactoriesMapper() : void {
$this->mapper = new PreprocessEventFactoryMapper();
foreach ($this->factories as $entry) {
$factory = new $entry['class']();
$this->mapper
->addFactory($factory);
}
}
/**
* Singleton get instance function.
*
* Only need to load the files once from the filesystem.
*
* @return \Drupal\Tests\preprocess_event_dispatcher\Unit\Helpers\YamlDefinitionsLoader
* Existing or new YamlDefinitionsLoader instance.
*/
public static function getInstance() : YamlDefinitionsLoader {
if (static::$instance === NULL) {
static::$instance = new static();
}
return static::$instance;
}
/**
* Get the FactoryMapper.
*
* @return \Drupal\preprocess_event_dispatcher\Service\PreprocessEventFactoryMapper
* Factory mapper.
*/
public function getMapper() : PreprocessEventFactoryMapper {
return $this->mapper;
}
/**
* Get the Services.
*
* @return array
* Service definitions.
*/
public function getServices() : array {
return $this->services;
}
/**
* Get the Factories.
*
* @return array
* Factory definitions.
*/
public function getFactories() : array {
return $this->factories;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
YamlDefinitionsLoader:: |
private | property | Factory definitions loaded from the YAML services file. | |
YamlDefinitionsLoader:: |
private static | property | Singleton instance of this class. | |
YamlDefinitionsLoader:: |
private | property | Factory mapper. | |
YamlDefinitionsLoader:: |
private | property | Service definitions loaded from the YAML services file. | |
YamlDefinitionsLoader:: |
public | function | Get the Factories. | |
YamlDefinitionsLoader:: |
public static | function | Singleton get instance function. | |
YamlDefinitionsLoader:: |
public | function | Get the FactoryMapper. | |
YamlDefinitionsLoader:: |
public | function | Get the Services. | |
YamlDefinitionsLoader:: |
private | function | Load the definitions from the services YAML. | |
YamlDefinitionsLoader:: |
private | function | Set up Factories Mapper. | |
YamlDefinitionsLoader:: |
private | function | YamlDefinitionsLoader constructor. |