/** * {@inheritDoc} */ public function register(Container $container) { // Append custom settings with missing params from default settings $container['settings']['database'] = self::mergeWithDefaultSettings($container['settings']['database']); $settings = $container['settings']['database']; $logLevel = $settings['logger']['level'] ?? null; $logPath = $settings['logger']['path'] ?? null; $className = $settings['classname'] ?? null; if (!$className) { $className = 'Propel\\Runtime\\Connection\\ConnectionWrapper'; if ($logLevel == Logger::DEBUG) { $className = 'Propel\\Runtime\\Connection\\ProfilerConnectionWrapper'; } } $manager = new ConnectionManagerSingle(); $manager->setConfiguration(['classname' => $className, 'dsn' => $settings['dsn'], 'user' => $settings['user'], 'password' => $settings['password'], 'settings' => $settings['settings']]); $manager->setName($settings['connection']); /** @var StandardServiceContainer $serviceContainer */ $serviceContainer = Propel::getServiceContainer(); $serviceContainer->checkVersion($settings['version']); $serviceContainer->setAdapterClass($settings['connection'], $settings['adapter']); $serviceContainer->setConnectionManager($settings['connection'], $manager); $serviceContainer->setDefaultDatasource($settings['connection']); if ($logPath && $logLevel) { $logger = new Logger('defaultLogger'); $logger->pushHandler(new StreamHandler($logPath, $logLevel)); $serviceContainer->setLogger('defaultLogger', $logger); if ($logLevel == Logger::DEBUG) { /** @var ConnectionWrapper $con */ $con = Propel::getConnection(); $con->useDebug(true); } } }
/** * Register propel runtime configuration. * * @return void */ protected function registerRuntimeConfiguration() { $propel_conf = $this->app->config['propel.propel']; if (!isset($propel_conf['runtime']['connections'])) { throw new \InvalidArgumentException('Unable to guess Propel runtime config file. Please, initialize the "propel.runtime" parameter.'); } /** @var $serviceContainer \Propel\Runtime\ServiceContainer\StandardServiceContainer */ $serviceContainer = Propel::getServiceContainer(); $serviceContainer->closeConnections(); $serviceContainer->checkVersion('2.0.0-dev'); $runtime_conf = $propel_conf['runtime']; // set connections foreach ($runtime_conf['connections'] as $connection_name) { $config = $propel_conf['database']['connections'][$connection_name]; $serviceContainer->setAdapterClass($connection_name, $config['adapter']); $manager = new ConnectionManagerSingle(); $manager->setConfiguration($config + [$propel_conf['paths']]); $manager->setName($connection_name); $serviceContainer->setConnectionManager($connection_name, $manager); } $serviceContainer->setDefaultDatasource($runtime_conf['defaultConnection']); // set loggers $has_default_logger = false; if (isset($runtime_conf['log'])) { $has_default_logger = array_key_exists('defaultLogger', $runtime_conf['log']); foreach ($runtime_conf['log'] as $logger_name => $logger_conf) { $serviceContainer->setLoggerConfiguration($logger_name, $logger_conf); } } if (!$has_default_logger) { $serviceContainer->setLogger('defaultLogger', \Log::getMonolog()); } Propel::setServiceContainer($serviceContainer); }
public function testGetWriteConnectionReturnsAConnectionNamedAfterTheManager() { $manager = new ConnectionManagerSingle(); $manager->setName('foo'); $manager->setConfiguration(['dsn' => 'sqlite::memory:']); $con = $manager->getWriteConnection(new SqliteAdapter()); $this->assertEquals('foo', $con->getName()); }
/** * @param \Silex\Application $app * * @return void */ public function boot(Application $app) { $manager = new ConnectionManagerSingle(); $manager->setConfiguration($this->getPropelConfig()); $manager->setName('zed'); $serviceContainer = $this->getServiceContainer(); $serviceContainer->setAdapterClass('zed', Config::get(PropelConstants::ZED_DB_ENGINE)); $serviceContainer->setConnectionManager('zed', $manager); $serviceContainer->setDefaultDatasource('zed'); $this->addLogger($serviceContainer); if (Config::get(PropelConstants::PROPEL_DEBUG, false) && $this->hasConnection()) { $connection = Propel::getConnection(); $connection->useDebug(true); } }
protected function initPropel() { if (self::isInstalled() === false) { return; } /** @var \Propel\Runtime\ServiceContainer\StandardServiceContainer $serviceContainer */ $serviceContainer = Propel::getServiceContainer(); $serviceContainer->setDefaultDatasource('thelia'); $manager = new ConnectionManagerSingle(); $manager->setConfiguration($this->getPropelConfig()); $manager->setName('thelia'); $serviceContainer->setConnectionManager('thelia', $manager); $serviceContainer->setAdapterClass('thelia', 'mysql'); /** @var ConnectionWrapper $con */ $con = Propel::getConnection(ProductTableMap::DATABASE_NAME); $con->setAttribute(ConnectionWrapper::PROPEL_ATTR_CACHE_PREPARES, true); if ($this->isDebug()) { // In debug mode, we have to initialize Tlog at this point, as this class uses Propel Tlog::getInstance()->setLevel(Tlog::DEBUG); $serviceContainer->setLogger('defaultLogger', Tlog::getInstance()); $con->useDebug(true); } }
/** * Sets the configuration for Propel and all dependencies. * * @param mixed The Configuration (array or Configuration) */ public static function setConfiguration($c) { $serviceContainer = self::getServiceContainer(); $serviceContainer->closeConnections(); if (is_array($c)) { $c = new Registry($c); } // set datasources if (isset($c['datasources'])) { foreach ($c['datasources'] as $name => $params) { if (!is_array($params)) { continue; } // set adapters if (isset($params['adapter'])) { $serviceContainer->setAdapterClass($name, $params['adapter']); } // set connection settings if (isset($params['connection'])) { $conParams = $params['connection']; if (isset($conParams['slaves'])) { $manager = new ConnectionManagerMasterSlave(); $manager->setName($name); $manager->setReadConfiguration($conParams['slaves']); unset($conParams['slaves']); $manager->setWriteConfiguration($conParams); } else { $manager = new ConnectionManagerSingle(); $manager->setName($name); $manager->setConfiguration($conParams); } $serviceContainer->setConnectionManager($name, $manager); } } } // set default datasource $defaultDatasource = isset($c['datasources']['default']) ? $c['datasources']['default'] : self::DEFAULT_NAME; $serviceContainer->setDefaultDatasource($defaultDatasource); // set profiler if (isset($c['profiler'])) { $profilerConf = $c['profiler']; if (isset($profilerConf['class'])) { $serviceContainer->setProfilerClass($profilerConf['class']); unset($profilerConf['class']); } if ($profilerConf) { $serviceContainer->setProfilerConfiguration($profilerConf); } } // set logger if (isset($c['log'])) { foreach ($c['log'] as $loggerConfiguration) { $name = $loggerConfiguration['name']; unset($loggerConfiguration['name']); $serviceContainer->setLoggerConfiguration($name, $loggerConfiguration); } } self::$configuration = $c; }
public function loadConfig() { $serviceContainer = Propel::getServiceContainer(); $database = $this->getJarves()->getSystemConfig()->getDatabase(); if ($database->hasSlaveConnection()) { $manager = new ConnectionManagerMasterSlave(); $config = $this->getManagerConfig($database->getMainConnection()); $manager->setWriteConfiguration($config); $slaves = []; foreach ($database->getConnections() as $connection) { if ($connection->isSlave()) { $slaves[] = $this->getManagerConfig($connection); } } $manager->setReadConfiguration($slaves); } else { $manager = new ConnectionManagerSingle(); $config = $this->getManagerConfig($database->getMainConnection()); $manager->setConfiguration($config); } $manager->setName('default'); $serviceContainer->setAdapterClass('default', $database->getMainConnection()->getType()); $serviceContainer->setConnectionManager('default', $manager); $serviceContainer->setDefaultDatasource('default'); }
if ($repo->contains('/config/development.yaml')) { $devConfig->load('development.yaml'); } // development config define('KEEKO_ENVIRONMENT', $devConfig->isLoaded() ? KEEKO_DEVELOPMENT : KEEKO_PRODUCTION); if (KEEKO_ENVIRONMENT == KEEKO_DEVELOPMENT) { error_reporting(E_ALL | E_STRICT); } // database config define('KEEKO_DATABASE_LOADED', $dbConfig->isLoaded()); if ($dbConfig->isLoaded()) { $serviceContainer = Propel::getServiceContainer(); $serviceContainer->setAdapterClass('keeko', 'mysql'); $manager = new ConnectionManagerSingle(); $manager->setConfiguration(['dsn' => 'mysql:host=' . $dbConfig->getHost() . ';dbname=' . $dbConfig->getDatabase(), 'user' => $dbConfig->getUser(), 'password' => $dbConfig->getPassword()]); $manager->setName('keeko'); $serviceContainer->setConnectionManager('keeko', $manager); $serviceContainer->setDefaultDatasource('keeko'); // set utf-8 $con = Propel::getWriteConnection('keeko'); $con->exec('SET NAMES utf8 COLLATE utf8_unicode_ci, COLLATION_CONNECTION = utf8_unicode_ci, COLLATION_DATABASE = utf8_unicode_ci, COLLATION_SERVER = utf8_unicode_ci;'); // $con->exec('SET SQL_SAFE_UPDATES=0;'); if (KEEKO_ENVIRONMENT == KEEKO_DEVELOPMENT) { $con->useDebug(true); $logger = new Logger('defaultLogger'); if ($devConfig->getPropelLogging() == 'stderr') { $logger->pushHandler(new StreamHandler('php://stderr')); } $serviceContainer->setLogger('defaultLogger', $logger); } }
/** * Configures the database * * @param Configuration $configuration * @param LoggerInterface $logger */ private function configurePropel(Configuration $configuration, LoggerInterface $logger) { $connectionName = 'tvheadend_status_manager'; /* @var StandardServiceContainer $serviceContainer */ $serviceContainer = Propel::getServiceContainer(); $serviceContainer->checkVersion('2.0.0-dev'); $serviceContainer->setAdapterClass($connectionName, 'sqlite'); $manager = new ConnectionManagerSingle(); $manager->setConfiguration(['classname' => 'Propel\\Runtime\\Connection\\ConnectionWrapper', 'dsn' => 'sqlite:' . $configuration->getDatabasePath(), 'user' => null, 'password' => '', 'attributes' => ['ATTR_EMULATE_PREPARES' => false], 'settings' => ['charset' => 'utf8', 'queries' => []]]); $manager->setName($connectionName); $serviceContainer->setConnectionManager($connectionName, $manager); $serviceContainer->setDefaultDatasource($connectionName); $serviceContainer->setLogger($connectionName, $logger); }