/** * Instantiates and adds the data providers implementing ContaoDataProviderInformation to the environment. * * @param EnvironmentInterface $environment The environment to populate. * * @return void * * @throws DcGeneralRuntimeException When a data provider has already been added to the environment. */ public function populate(EnvironmentInterface $environment) { $definition = $environment->getDataDefinition(); foreach ($definition->getDataProviderDefinition() as $information) { if ($information instanceof ContaoDataProviderInformation) { if ($environment->hasDataProvider($information->getName())) { throw new DcGeneralRuntimeException(sprintf('Data provider %s already added to environment.', $information->getName())); } $providerClass = new \ReflectionClass($information->getClassName()); /** @var DataProviderInterface $dataProvider */ $dataProvider = $providerClass->newInstance(); if ($initializationData = $information->getInitializationData()) { $dataProvider->setBaseConfig($initializationData); } $environment->addDataProvider($information->getName(), $dataProvider); } } }