/** * Check if the current call is my context. * * @param EnvironmentInterface $environment The container with the env. * * @param null|string $overwrite Set a overwrite for the data provider name. * * @return bool Return false if this class should not do something in this context. */ public function isRightContext($environment, $overwrite = null) { if ($overwrite !== null && !$environment->hasDataProvider($overwrite)) { return false; } else { if ($overwrite === null && !$environment->hasDataProvider($this->getContextProviderName())) { return false; } } return true; }
/** * 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); } } }