40 lines
1.2 KiB
PHP
40 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Nest\Database\Configuration;
|
|
|
|
use Nest\Application;
|
|
use Nest\Configuration\Exceptions\ConfigurationValueNotFoundException;
|
|
use Nest\Database\Exceptions\Configuration\UndefinedDatabaseTypeException;
|
|
|
|
class DatabasesArrayConfiguration extends DatabasesConfiguration
|
|
{
|
|
/**
|
|
* @param Application $application The application.
|
|
* @param string $configurationKey Configuration key where to find the databases configuration array.
|
|
*/
|
|
public function __construct(protected Application $application, protected string $configurationKey)
|
|
{}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
* @throws ConfigurationValueNotFoundException
|
|
* @throws UndefinedDatabaseTypeException
|
|
*/
|
|
#[\Override] public function getFactories(): array
|
|
{
|
|
// Initialize loaded factories.
|
|
$factories = [];
|
|
|
|
foreach ($this->application->configuration()->getValue($this->configurationKey) as $identifier => $configuration)
|
|
{
|
|
if (empty($configuration["type"]))
|
|
// Undefined database type, throwing an exception.
|
|
throw new UndefinedDatabaseTypeException($identifier);
|
|
|
|
// Create the factory with the given configuration.
|
|
$factories[$identifier] = new $configuration["type"]($identifier, $configuration);
|
|
}
|
|
|
|
return $factories; // Return loaded factories.
|
|
}
|
|
}
|