protected function __construct() { $this->adapter = Config::get('db.adapter'); $this->host = Config::get('db.host'); $this->database = Config::get('db.name'); $this->manager = new ConnectionManagerSingle(); $this->manager->setConfiguration($this->defaultConfig()); $this->serviceContainer = Propel::getServiceContainer(); $this->serviceContainer->setAdapterClass($this->database, $this->adapter); $this->serviceContainer->setConnectionManager($this->database, $this->manager); }
/** * 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); }
protected function configureConnections() { $config = $this->container->getParameter('propel.configuration'); $defaultConnection = !empty($config['runtime']['defaultConnection']) ? $config['runtime']['defaultConnection'] : key($config['database']['connections']); $serviceContainer = Propel::getServiceContainer(); $serviceContainer->setDefaultDatasource($defaultConnection); foreach ($config['database']['connections'] as $name => $config) { if (!empty($config['slaves'])) { $manager = new ConnectionManagerMasterSlave(); // configure the master (write) connection $manager->setWriteConfiguration($config); // configure the slave (read) connections $slaveConnections = []; foreach ($config['slaves'] as $slave) { $slaveConnections[] = array_merge($config, ['dsn' => $slave['dsn'], 'slaves' => null]); } $manager->setReadConfiguration($slaveConnections); } else { $manager = new ConnectionManagerSingle(); $manager->setConfiguration($config); } $serviceContainer->setAdapterClass($name, $config['adapter']); $serviceContainer->setConnectionManager($name, $manager); } }
/** * {@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); } } }
protected static function setPropelManager($config) { $manager = new ConnectionManagerSingle(); $configuration = ['dsn' => $config['dsn'], 'user' => $config['username'], 'password' => $config['password']]; $manager->setConfiguration($configuration); return $manager; }
public function testGetReadConnectionReturnsWriteConnection() { $manager = new ConnectionManagerSingle(); $manager->setConfiguration(['dsn' => 'sqlite::memory:']); $writeCon = $manager->getWriteConnection(new SqliteAdapter()); $readCon = $manager->getReadConnection(new SqliteAdapter()); $this->assertSame($writeCon, $readCon); }
public static function init($manager, $namespace) { $workingDirectory = $manager->getWorkingDirectory(); $paths = explode(DIRECTORY_SEPARATOR, $workingDirectory); $modulePaths = array(); $found = false; foreach ($paths as $path) { if ($found == false) { $modulePaths[] = $path; } if ($path == $namespace) { $found = true; } } $moduleConfigPath = implode(DIRECTORY_SEPARATOR, $modulePaths); $moduleConfig = (include $moduleConfigPath . '/config/module.config.php'); $appConfigPath = self::findAppConfig($moduleConfigPath); $applicationConfig = (include $appConfigPath . '/config/application.config.php'); $zf2ModulePaths = array(); if (isset($applicationConfig['module_listener_options']['module_paths'])) { $modulePaths = $applicationConfig['module_listener_options']['module_paths']; foreach ($modulePaths as $modulePath) { if ($path = static::findParentPath($modulePath)) { $zf2ModulePaths[] = $path; } } } if (isset($applicationConfig['module_listener_options']['config_glob_paths'])) { $globConfigs = $applicationConfig['module_listener_options']['config_glob_paths']; foreach ($globConfigs as $globConfig) { $localConfig = (include $appConfigPath . '/config/autoload/local.php'); $globalConfig = (include $appConfigPath . '/config/autoload/global.php'); } } $zf2ModulePaths = implode(PATH_SEPARATOR, $zf2ModulePaths) . PATH_SEPARATOR; static::initAutoloader(); $baseConfig = array('module_listener_options' => array('module_paths' => explode(PATH_SEPARATOR, $zf2ModulePaths))); $config = ArrayUtils::merge($moduleConfig, $applicationConfig); $config = ArrayUtils::merge($config, $baseConfig); $config = ArrayUtils::merge($config, $localConfig); $config = ArrayUtils::merge($config, $globalConfig); $serviceManager = new ServiceManager(new ServiceManagerConfig()); $serviceManager->setService('ApplicationConfig', $config); $serviceManager->get('ModuleManager')->loadModules(); static::$serviceManager = $serviceManager; static::$config = $config; $serviceContainer = Propel::getServiceContainer(); $connectionName = array_keys($moduleConfig['propel']['database']['connections']); $connectionName = array_shift($connectionName); $connectionName = $connectionName; $propelConfig = $config['propel']; list($dsn, $dbUser, $dbPass) = static::generateDsn($connectionName, $propelConfig['database']['connections']); $serviceContainer->setAdapterClass($connectionName, 'mysql'); $manager = new ConnectionManagerSingle(); $manager->setConfiguration(array('dsn' => $dsn, 'user' => $dbUser, 'password' => $dbPass)); $serviceContainer->setConnectionManager($connectionName, $manager); }
protected function initPropel() { $serviceContainer = Propel::getServiceContainer(); $serviceContainer->setAdapterClass($this->config["dbname"], $this->config["engine"]); $manager = new ConnectionManagerSingle(); $port = empty($this->config["port"]) ? "" : ";port=" . $this->config["port"]; $manager->setConfiguration(array("dsn" => $this->config["engine"] . ":host=" . $this->config["host"] . ";dbname=" . $this->config["dbname"] . $port, "user" => $this->config["user"], "password" => $this->config["password"])); $serviceContainer->setConnectionManager($this->config["dbname"], $manager); $this->alreadyInit = true; }
/** * @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; } $definePropel = new DefinePropel(new DatabaseConfiguration(), Yaml::parse(THELIA_CONF_DIR . 'database.yml')); $serviceContainer = Propel::getServiceContainer(); $serviceContainer->setAdapterClass('thelia', 'mysql'); $manager = new ConnectionManagerSingle(); $manager->setConfiguration($definePropel->getConfig()); $serviceContainer->setConnectionManager('thelia', $manager); $con = Propel::getConnection(\Thelia\Model\Map\ProductTableMap::DATABASE_NAME); $con->setAttribute(ConnectionWrapper::PROPEL_ATTR_CACHE_PREPARES, true); if ($this->isDebug()) { $serviceContainer->setLogger('defaultLogger', Tlog::getInstance()); $con->useDebug(true); } }
/** * @see Command * * @throws \InvalidArgumentException When the target directory does not exist */ protected function execute(InputInterface $input, OutputInterface $output) { $connectionName = $input->getOption('connection') ?: $this->getDefaultConnection(); $config = $this->getConnectionData($connectionName); $dbName = $this->parseDbName($config['dsn']); if (null === $dbName) { return $output->writeln('<error>No database name found.</error>'); } else { $query = 'CREATE DATABASE ' . $dbName . ';'; } $manager = new ConnectionManagerSingle(); $manager->setConfiguration($this->getTemporaryConfiguration($config)); $serviceContainer = Propel::getServiceContainer(); $serviceContainer->setAdapterClass($connectionName, $config['adapter']); $serviceContainer->setConnectionManager($connectionName, $manager); $connection = Propel::getConnection($connectionName); $statement = $connection->prepare($query); $statement->execute(); $output->writeln(sprintf('<info>Database <comment>%s</comment> has been created.</info>', $dbName)); }
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); } }
/** * Setup Propel connection for all loaded modules */ public function propelInit($app) { $serviceContainer = Propel::getServiceContainer(); $config = $app->getServiceManager()->get('config'); $config = $config['propel']['database']['connections']; $default_settings = $config['default'] ? $config['default'] : array(); $db_settings = array(); foreach ($config as $key => $settings) { $settings = array_merge($default_settings, $settings); $settings['adapter'] = @$settings['adapter'] ?: 'mysql'; $settings['host'] = @$settings['host'] ?: 'localhost'; $settings['dbname'] = @$settings['dbname'] ?: $key; $dsn = null; if (isset($settings['dsn'])) { $dsn = $settings['dsn']; } elseif (isset($settings['dbname'])) { switch ($settings['adapter']) { case 'mysql': $dsn = sprintf("mysql:host=%s;dbname=%s", $settings['host'], $settings['dbname']); break; case 'oci': $dsn = sprintf("oci:dbname=//%s/%s", $settings['host'], $settings['dbname']); break; case 'pgsql': $dsn = sprintf("pgsql:host=%s;port=5432;dbname=%s;user=%s;password=%s", $settings['host'], $settings['dbname'], $settings['user'], $settings['password']); break; case 'sqlite': $dsn = sprintf("sqlite:%s/%s", $settings['host'], $settings['dbname']); break; } } if ($dsn) { $serviceContainer->setAdapterClass($key, $settings['adapter']); $manager = new ConnectionManagerSingle(); $manager->setConfiguration(array('dsn' => $dsn, 'user' => $settings['user'], 'password' => $settings['password'])); $serviceContainer->setConnectionManager($key, $manager); } } }
/** * 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; }
protected function initPropel() { $serviceContainer = Propel::getServiceContainer(); $serviceContainer->setAdapterClass(self::CERBERUS_DB_SRC_NAME, $this->config["db-engine"]); $manager = new ConnectionManagerSingle(); $port = empty($this->config["db-port"]) ? "" : ";port=" . $this->config["db-port"]; $manager->setConfiguration(array("dsn" => $this->config["db-engine"] . ":host=" . $this->config["db-host"] . ";dbname=" . $this->config["db-name"] . $port, "user" => $this->config["db-user"], "password" => $this->config["db-password"])); $serviceContainer->setConnectionManager(self::CERBERUS_DB_SRC_NAME, $manager); }
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'); }
/** * 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); }
/** * Initialize Test Propel Connections for Sqlite */ public static function initPropel() { $serviceContainer = Propel::getServiceContainer(); $conectionName = static::getConnection(); $config = static::getConfig(); $propelConfig = $config['propel']; $dsn = $propelConfig['database']['connections'][$conectionName]['dsn']; $serviceContainer->setAdapterClass($conectionName, 'sqlite'); $manager = new ConnectionManagerSingle(); $manager->setConfiguration(array('dsn' => $dsn)); $serviceContainer->setConnectionManager($conectionName, $manager); }
$devConfig = new DevelopmentConfiguration($locator); 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); }
/** * your server configuration of your data base and twitter account */ /// set internal encoding to UTF-8 which is needed for qaul app mb_internal_encoding("UTF-8"); /// display or hide debug messages function get_debug() { return true; } /// autoloading of all classes require_once dirname(__FILE__) . '/../vendor/autoload.php'; use Propel\Runtime\Propel; use Propel\Runtime\Connection\ConnectionManagerSingle; $serviceContainer = Propel::getServiceContainer(); $serviceContainer->setAdapterClass('qaulhub', 'mysql'); $manager = new ConnectionManagerSingle(); $manager->setConfiguration(array('dsn' => 'mysql:host=localhost;dbname=qaulhub', 'user' => 'DBuser', 'password' => 'DBpassword', 'settings' => array('charset' => 'utf8'))); $serviceContainer->setConnectionManager('qaulhub', $manager); /// twitter account keys $twitter_settings = array('consumer_key' => "API key", 'consumer_secret' => "API secret", 'oauth_access_token' => "Access token", 'oauth_access_token_secret' => "Access token secret"); /// qaul configurations $qaul_settings = array("ip" => "10.67.33.81", "name" => "i_qaul", "domain" => "i.qaul.net", "download_folder" => "/PATH/TO/YOUR/QAUL/DOWNLOAD/FOLDER/", "twitter_search_term" => "#HASHTAG"); function get_qaul_setting($key) { global $qaul_settings; if (isset($qaul_settings[$key])) { return $qaul_settings[$key]; } return NULL; }
if (REPORT_ERRORS) { ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); } // Initialize the session session_start(); // Initialize CSRF Protection CSRF::init(); // Setup Framework Settings::getInstance()->addTemplateDirectories(dirname(__FILE__) . "/project-templates"); Settings::getInstance()->addAcronyms('ssn'); Cipher::createInstance(ATHENS_ENCRYPTION_PASSWORD); // Setup Propel $serviceContainer = Propel::getServiceContainer(); $serviceContainer->setAdapterClass(APPLICATION_NAME, 'mysql'); $manager = new ConnectionManagerSingle(); $manager->setConfiguration(array('dsn' => MYSQL_DSN, 'user' => MYSQL_USER, 'password' => MYSQL_PASSWORD)); $serviceContainer->setConnectionManager(APPLICATION_NAME, $manager); // Include project-specific CSS $fullCSSFilesnames = glob(dirname(__FILE__) . "/project-assets/css/*.css"); $relativeCSSFilesnames = str_replace(dirname(__FILE__) . "/", "", $fullCSSFilesnames); foreach ($relativeCSSFilesnames as $file) { Settings::getInstance()->addProjectCSS($file); } // Include project-specific JS $fullJSFilesnames = glob(dirname(__FILE__) . "/project-assets/js/*.js"); $relativeJSFilesnames = str_replace(dirname(__FILE__) . "/", "", $fullJSFilesnames); foreach ($relativeJSFilesnames as $file) { Settings::getInstance()->addProjectJS($file); }