final class YamlDefinitionsLoader in Hook Event Dispatcher 8
Class YamlDefinitionsLoader.
@package Drupal\Tests\hook_event_dispatcher\Preprocess\Helpers
Hierarchy
- class \Drupal\Tests\hook_event_dispatcher\Unit\Preprocess\Helpers\YamlDefinitionsLoader
Expanded class hierarchy of YamlDefinitionsLoader
6 files declare their use of YamlDefinitionsLoader
- EntityEventTest.php in tests/
src/ Unit/ Preprocess/ EntityEventTest.php - EntityEventVariablesTest.php in tests/
src/ Unit/ Preprocess/ EntityEventVariablesTest.php - FactoryMapperTest.php in tests/
src/ Unit/ Preprocess/ FactoryMapperTest.php - OtherEventTest.php in tests/
src/ Unit/ Preprocess/ OtherEventTest.php - OtherEventVariablesTest.php in tests/
src/ Unit/ Preprocess/ OtherEventVariablesTest.php
File
- tests/
src/ Unit/ Preprocess/ Helpers/ YamlDefinitionsLoader.php, line 13
Namespace
Drupal\Tests\hook_event_dispatcher\Unit\Preprocess\HelpersView source
final class YamlDefinitionsLoader {
/**
* Singleton instance of this class.
*
* @var YamlDefinitionsLoader
*/
private static $instance;
/**
* Factory mapper.
*
* @var \Drupal\hook_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() {
$yaml = new Parser();
$content = file_get_contents(dirname(dirname(dirname(dirname(dirname(__DIR__))))) . '/hook_event_dispatcher.services.yml');
$services = $yaml
->parse($content)['services'];
// Remove the Manager.
unset($services['hook_event_dispatcher.manager']);
$factories = $this->services = $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() {
$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\hook_event_dispatcher\Unit\Preprocess\Helpers\YamlDefinitionsLoader
* Existing or new YamlDefinitionsLoader instance.
*/
public static function getInstance() {
if (static::$instance === NULL) {
static::$instance = new static();
}
return static::$instance;
}
/**
* Get the FactoryMapper.
*
* @return \Drupal\hook_event_dispatcher\Service\PreprocessEventFactoryMapper
* Factory mapper.
*/
public function getMapper() {
return $this->mapper;
}
/**
* Get the Services.
*
* @return array
* Service definitions.
*/
public function getServices() {
return $this->services;
}
/**
* Get the Factories.
*
* @return array
* Factory definitions.
*/
public function getFactories() {
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. |