class StorageFactory in Radioactivity 4.0.x
Same name and namespace in other branches
- 8.3 src/StorageFactory.php \Drupal\radioactivity\StorageFactory
Storage factory service.
Hierarchy
- class \Drupal\radioactivity\StorageFactory
Expanded class hierarchy of StorageFactory
4 files declare their use of StorageFactory
- EmitController.php in src/
Controller/ EmitController.php - EmitControllerTest.php in tests/
src/ Unit/ EmitControllerTest.php - RadioactivityProcessorTest.php in tests/
src/ Unit/ RadioactivityProcessorTest.php - StorageFactoryTest.php in tests/
src/ Unit/ StorageFactoryTest.php
1 string reference to 'StorageFactory'
1 service uses StorageFactory
File
- src/
StorageFactory.php, line 11
Namespace
Drupal\radioactivityView source
class StorageFactory {
/**
* The radioactivity storage configuration.
*
* @var \Drupal\Core\Config\ImmutableConfig
*/
protected $config;
/**
* The class resolver.
*
* @var \Drupal\Core\DependencyInjection\ClassResolverInterface
*/
protected $classResolver;
/**
* StorageFactory constructor.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
* The configuration factory.
* @param \Drupal\Core\DependencyInjection\ClassResolverInterface $classResolver
* The class resolver.
*/
public function __construct(ConfigFactoryInterface $configFactory, ClassResolverInterface $classResolver) {
$this->config = $configFactory
->get('radioactivity.storage');
$this->classResolver = $classResolver;
}
/**
* Getter for classes which implement IncidentStorageInterface.
*
* @param string $type
* The type of storage to get.
*
* @return \Drupal\radioactivity\IncidentStorageInterface
* Instance of the requested storage.
*/
public function get($type) {
switch ($type) {
case 'rest_local':
$instance = $this->classResolver
->getInstanceFromDefinition('radioactivity.rest_incident_storage');
$instance
->setEndpoint(NULL);
break;
case 'rest_remote':
$instance = $this->classResolver
->getInstanceFromDefinition('radioactivity.rest_incident_storage');
$instance
->setEndpoint($this->config
->get('endpoint'));
break;
case 'default':
default:
$instance = $this->classResolver
->getInstanceFromDefinition('radioactivity.default_incident_storage');
}
/** @var \Drupal\radioactivity\IncidentStorageInterface $instance */
return $instance;
}
/**
* Get the configured incident storage.
*
* @return \Drupal\radioactivity\IncidentStorageInterface
* The configured storage instance.
*/
public function getConfiguredStorage() {
$type = $this->config
->get('type') ?: 'default';
return $this
->get($type);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
StorageFactory:: |
protected | property | The class resolver. | |
StorageFactory:: |
protected | property | The radioactivity storage configuration. | |
StorageFactory:: |
public | function | Getter for classes which implement IncidentStorageInterface. | |
StorageFactory:: |
public | function | Get the configured incident storage. | |
StorageFactory:: |
public | function | StorageFactory constructor. |