public function testInstantiate() { // Test the factory $this->assertEquals('\\Phruts\\Util\\PDODataSourceFactory', \Phruts\Util\DataSourceFactory::getFactoryClass()); $config = new \Phruts\Config\DataSourceConfig(); $config->setKey('Example'); $config->setType('PDO'); $config->addProperty('dsn', 'sqlite::memory:'); $factory = \Phruts\Util\DataSourceFactory::createFactory($config); $this->assertNotEmpty($factory); // Create the resources $pdo = $factory->createDataSource(); $this->assertNotEmpty($pdo); }
protected function initModuleDataSources(\Phruts\Config\ModuleConfig $config) { if (!empty($this->log)) { $this->log->debug('Initialization module path "' . $config->getPrefix() . '" data sources'); } $dscs = $config->findDataSourceConfigs(); foreach ($dscs as $dsc) { /* @var $dsc \Phruts\Config\DataSourceConfig */ if (!empty($this->log)) { $this->log->debug('Initialization module path "' . $config->getPrefix() . '" data source "' . $dsc->getKey() . '"'); } try { \Phruts\Util\DataSourceFactory::setFactoryClass($dsc->getType()); $dsFactory = \Phruts\Util\DataSourceFactory::createFactory($dsc); } catch (\Exception $e) { $msg = $this->getInternal()->getMessage(null, 'dataSource.init', $dsc->getKey()); if (!empty($this->log)) { $this->log->error($msg . ' - ' . $e->getMessage()); } throw new \Phruts\Exception($msg); } $this->dataSourceFactories[$dsc->getKey() . $config->getPrefix()] = $dsFactory; } }