public static function init() { if (self::$_started) { return; } $redirection_conf = sfConfig::get('app_redirection_databases', null); if ($redirection_conf === null) { return; } //Iterate over the databases configurations. foreach ($redirection_conf as $dbName => $dbOptions) { //Check if there are any slaves servers configured. if ($dbOptions['slaves'] === null) { continue; } foreach ($dbOptions['slaves'] as &$slave) { foreach ($slave as &$param) { $param = sfConfigHandler::replaceConstants($param); } #Symfony uses 'username' but Propel expects 'user'. $slave['user'] = $slave['username']; unset($slave['username']); } self::$_slaveConfig[$dbName] = $dbOptions['slaves']; //Check if there is any entity that maybe be redirected to the slave. if ($dbOptions['entities'] === null) { continue; } //Iterate over the entities. foreach ($dbOptions['entities'] as $model => $options) { $peerClass = "{$model}Peer"; //Check if the peer exits. if (!class_exists($peerClass)) { continue; } $doSelectStmtHook = "{$peerClass}:doSelectStmt:doSelectStmt"; $doCountHook = "{$peerClass}:doCount:doCount"; //Register the interceptor function on the peer hooks. $interceptor = array('sfPropelRedirection', 'slaveConnection'); sfMixer::register($doSelectStmtHook, $interceptor); sfMixer::register($doCountHook, $interceptor); //Check if the peer has conditions in order to be redirected to the slave. if (!isset($options['conditions'])) { continue; } self::$_peerOptions[$peerClass]['conditions'] = $options['conditions']; //If there are zero conditions then we don't need to check a gen_column. if (!isset($options['gen_column'])) { continue; } $columnName = strtolower($model) . '.' . strtoupper($options['gen_column']); //Check if the gen column really exists in the model if (!in_array($columnName, $peerClass::getFieldNames(BasePeer::TYPE_COLNAME))) { continue; } self::$_peerOptions[$peerClass]['gen_column'] = $columnName; } } self::$_started = true; }
$t = new lime_test(8); class myConfigHandler extends sfConfigHandler { public function execute($configFiles) { } } $config = new myConfigHandler(); $config->initialize(); // ->initialize() $t->diag('->initialize()'); $config->initialize(array('foo' => 'bar')); $t->is($config->getParameterHolder()->get('foo'), 'bar', '->initialize() takes an array of parameters as its first argument'); // ::replaceConstants() $t->diag('::replaceConstants()'); sfConfig::set('foo', 'bar'); $t->is(sfConfigHandler::replaceConstants('my value with a %foo% constant'), 'my value with a bar constant', '::replaceConstants() replaces constants enclosed in %'); $t->is(sfConfigHandler::replaceConstants('%Y/%m/%d %H:%M'), '%Y/%m/%d %H:%M', '::replaceConstants() does not replace unknown constants'); sfConfig::set('foo', 'bar'); $value = array('foo' => 'my value with a %foo% constant', 'bar' => array('foo' => 'my value with a %foo% constant')); $value = sfConfigHandler::replaceConstants($value); $t->is($value['foo'], 'my value with a bar constant', '::replaceConstants() replaces constants in arrays recursively'); $t->is($value['bar']['foo'], 'my value with a bar constant', '::replaceConstants() replaces constants in arrays recursively'); // ->getParameterHolder() $t->diag('->getParameterHolder()'); $t->isa_ok($config->getParameterHolder(), 'sfParameterHolder', "->getParameterHolder() returns a parameter holder instance"); // ->replacePath() $t->diag('->replacePath()'); sfConfig::set('sf_app_dir', 'ROOTDIR'); $t->is($config->replacePath('test'), 'ROOTDIR/test', '->replacePath() prefix a relative path with "sf_app_dir"'); $t->is($config->replacePath('/test'), '/test', '->replacePath() prefix a relative path with "sf_app_dir"');
/** Validates the uploads directory to ensure we're not going to inadvertently * put test uploads in the wrong place and/or delete production files. * * @param bool $force * * @return void */ protected function _assertTestUploadsDir($force = false) { if (!self::$_uploadsDirCheck or $force) { $this->_assertTestEnvironment(); $config = sfConfigHandler::replaceConstants(sfYaml::load($this->_getSettingsFilename())); /* Determine whether a the test uploads directory is different than the * production one. */ if (isset($config['prod']['.settings']['upload_dir'])) { $prod = $config['prod']['.settings']['upload_dir']; } elseif (isset($config['all']['.settings']['upload_dir'])) { $prod = $config['all']['.settings']['upload_dir']; } else { /* Get the default value: no good way to do this in Symfony 1.4. */ $prod = sfConfig::get('sf_web_dir') . DIRECTORY_SEPARATOR . 'uploads'; } $test = sfConfig::get('sf_test_dir'); if ($prod == $test) { self::_halt(sprintf('Please specify a *separate* test value for sf_upload_dir in %s.', $this->_getSettingsFilename())); } /* Check the directory itself to make sure it's valid. */ if (!file_exists($test)) { /* If it doesn't exist, let's see if we can't create it. */ if (!mkdir($test, 0777, true)) { self::_halt('Test upload directory (%s) does not exist. Please create this directory before continuing.', $test); } } elseif (!is_dir($test)) { self::_halt('Test upload directory (%s) not a directory.', $test); } if (!is_writable($test)) { self::_halt('Test upload directory (%s) is not writable.', $test); } self::$_uploadsDirCheck = true; } }