本文整理汇总了PHP中Propel::getConfiguration方法的典型用法代码示例。如果您正苦于以下问题:PHP Propel::getConfiguration方法的具体用法?PHP Propel::getConfiguration怎么用?PHP Propel::getConfiguration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Propel
的用法示例。
在下文中一共展示了Propel::getConfiguration方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* @see Console\Command\Command
*/
protected function execute(Input\InputInterface $input, Output\OutputInterface $output)
{
$schemaFile = $input->getArgument('schema-file');
$configFile = $input->getArgument('config-file');
$dataSource = $input->getOption('datasource');
$ignoreConstraints = $input->getOption('ignore-constraints');
// initialize propel
\Propel::init($configFile);
// get xml representation of schema file
$schemaXml = simplexml_load_file($schemaFile);
// intitialize doctrine DBAL with data from propel
$config = \PropelCli\Configuration::getDataSourceConfiguration($dataSource, \Propel::getConfiguration());
$conn = DBAL\DriverManager::getConnection($config->toArray(), new DBAL\Configuration());
$sm = $conn->getSchemaManager();
// create a schema of the existing db
$fromSchema = $sm->createSchema();
// initialize a schema for the updated db
$toSchema = new \Doctrine\DBAL\Schema\Schema();
// generate the schema object
$generator = new \PropelCli\Schema\Generator($schemaXml);
$generator->generate($toSchema);
// generate the sql to migrate from fromSchema to toSchema
$sql = $fromSchema->getMigrateToSql($toSchema, $conn->getDatabasePlatform());
if ($input->getOption('dump-sql')) {
foreach ($sql as $stmt) {
if ($ignoreConstraints && preg_match('/CONSTRAINT/', $stmt)) {
continue;
}
$output->write($stmt . ';' . PHP_EOL);
}
}
}
示例2: getModels
/**
* Get a list of all Propel-model classes.
*
* @param bool $packages Group by package name.
* @return array
*/
public static function getModels($packages = true)
{
$classes = array();
$configArray = Propel::getConfiguration();
foreach ($configArray['classmap'] as $className => $file) {
if (preg_match('@^(.*)/map/(\\w+)TableMap\\.php$@', $file, $match)) {
$package = $match[1];
$clazz = $match[2];
if ($packages) {
if (!isset($classes[$package])) {
$classes[$package] = array();
}
$classes[$package][] = $clazz;
} else {
$classes[] = $clazz;
}
}
}
if ($packages) {
ksort($classes, SORT_STRING);
foreach ($classes as $package => &$cl) {
sort($cl, SORT_STRING);
}
unset($cl);
}
return $classes;
}
示例3: enablePropelLogging
public static function enablePropelLogging()
{
$logger = Logging::getLogger();
Propel::setLogger($logger);
$con = Propel::getConnection();
$con->useDebug(true);
$config = Propel::getConfiguration(PropelConfiguration::TYPE_OBJECT);
$config->setParameter('debugpdo.logging.details.method.enabled', true);
$config->setParameter('debugpdo.logging.details.time.enabled', true);
$config->setParameter('debugpdo.logging.details.mem.enabled', true);
}
示例4: getConnection
/**
* @return PHPUnit_Extensions_Database_DB_IDatabaseConnection
*/
public function getConnection()
{
if (self::$testCon === null) {
self::$propelCon = Propel::getConnection();
$propelConfig = Propel::getConfiguration(PropelConfiguration::TYPE_ARRAY);
$this->assertTrue(isset($propelConfig['datasources'][PROJECT_NAME]['connection']));
$dbConfig = $propelConfig['datasources'][PROJECT_NAME]['connection'];
$this->assertTrue(isset($dbConfig['dsn'], $dbConfig['database'], $dbConfig['user'], $dbConfig['password']));
self::$testCon = $this->createDefaultDBConnection(new PDO($dbConfig['dsn'], $dbConfig['user'], $dbConfig['password']), $dbConfig['database']);
}
return self::$testCon;
}
示例5: __construct
/**
* Class constructor.
*
* @see initialize()
*/
public function __construct($url = 'http://voota.es')
{
$this->serverUrl = $url;
$dbConf = Propel::getConfiguration();
$dsn = $dbConf['datasources']['propel']['connection']['dsn'];
if (preg_match("/dbname=(.*);host=(.*)\$/", $dsn, $matches)) {
$db = $matches[1];
$host = $matches[2];
}
$databaseArray = array('server' => $host, 'username' => $dbConf['datasources']['propel']['connection']['user'], 'password' => $dbConf['datasources']['propel']['connection']['password'], 'database' => $db);
OAuthStore::instance('MySQL', OAuthStore::instance('MySQL', $databaseArray));
}
示例6: storeInstance
public static function storeInstance()
{
$dbConf = Propel::getConfiguration();
$dsn = $dbConf['datasources']['propel']['connection']['dsn'];
if (preg_match("/dbname=(.*);host=(.*)\$/", $dsn, $matches)) {
$db = $matches[1];
$host = $matches[2];
}
$store = OAuthStore::instance('MySQL', array('server' => $host, 'username' => $dbConf['datasources']['propel']['connection']['user'], 'password' => $dbConf['datasources']['propel']['connection']['password'], 'database' => $db));
if (!$store) {
sfContext::getInstance()->getLogger()->err("Cannot connect to database.");
throw new OAuthException("Cannot connect to database.");
}
return $store;
}
示例7: instanciate
/**
* @static
* @param string $connectionName
* @return PropelPDO
*/
public static function instanciate($connectionName)
{
$propelConfiguration = Propel::getConfiguration();
if (isset($propelConfiguration['datasources'][$connectionName]['connection'])) {
$parameters = $propelConfiguration['datasources'][$connectionName]['connection'];
} else {
if (isset($propelConfiguration['datasources'][Propel::getDefaultDB()])) {
$propelConfiguration['datasources'][$connectionName] = $propelConfiguration['datasources'][Propel::getDefaultDB()];
Propel::setConfiguration(new PropelConfiguration($propelConfiguration));
$parameters = $propelConfiguration['datasources'][$connectionName]['connection'];
} else {
throw new Exception(sprintf("Unable to find connection parameters for connection '%s'", $connectionName));
}
}
return Propel::initConnection($parameters, $connectionName);
}
示例8: setUp
protected function setUp()
{
if (Propel::isInit()) {
$this->oldPropelConfiguration = Propel::getConfiguration();
}
$xmlDom = new DOMDocument();
$xmlDom->load(dirname(__FILE__) . '/../../fixtures/reverse/mysql/runtime-conf.xml');
$xml = simplexml_load_string($xmlDom->saveXML());
$phpconf = PlatformDatabaseBuildTimeBaseTask::simpleXmlToArray($xml);
Propel::setConfiguration($phpconf);
Propel::initialize();
$this->con = Propel::getConnection('reverse-bookstore');
$this->parser = new MysqlSchemaParser(Propel::getConnection('reverse-bookstore'));
$this->parser->setGeneratorConfig(new QuickGeneratorConfig(new MysqlPlatform()));
parent::setUp();
}
示例9: processDatabaseList
/**
* Databases and tables list helper
*
* @return array
*/
public function processDatabaseList()
{
$aConfiguration = Propel::getConfiguration();
// Extract default connection
$sDefault = '';
if (isset($aConfiguration['datasources']['default'])) {
$sDefault = $aConfiguration['datasources']['default'];
unset($aConfiguration['datasources']['default']);
}
$aDatabases = array();
// Generating response
foreach ($aConfiguration['datasources'] as $db_connection => $db_connecttion_info) {
$sDsn = $db_connecttion_info['connection']['dsn'];
$aDsnInfo = afsDatabaseQuery::parseDSN($sDsn);
$aTables = afsDatabaseQuery::getTables($db_connection);
// Generate list of databases and tables
$aDatabases[] = array('name' => $aDsnInfo['dbname'], 'tables_num' => count($aTables), 'connection' => $db_connection, 'tables' => array_values((array) $aTables));
}
return $aDatabases;
}
示例10: initialize
/**
* Load Propel config
*
* @param AgaviDatabaseManager The database manager of this instance.
* @param array An assoc array of initialization params.
*
* @author David Zülke <dz@bitxtender.com>
* @since 0.10.0
*/
public function initialize(AgaviDatabaseManager $databaseManager, array $parameters = array())
{
parent::initialize($databaseManager, $parameters);
$configPath = AgaviToolkit::expandDirectives($this->getParameter('config'));
$datasource = $this->getParameter('datasource', null);
$use_as_default = $this->getParameter('use_as_default', false);
$config = (require $configPath);
if ($datasource === null || $datasource == 'default') {
if (isset($config['propel']['datasources']['default'])) {
$datasource = $config['propel']['datasources']['default'];
} elseif (isset($config['datasources']['default'])) {
$datasource = $config['datasources']['default'];
} else {
throw new AgaviDatabaseException('No datasource given for Propel connection, and no default datasource specified in runtime configuration file.');
}
}
if (!class_exists('Propel')) {
include 'propel/Propel.php';
}
if (!Propel::isInit()) {
Propel::init($configPath);
}
$is13 = version_compare(Propel::VERSION, '1.4', '<');
// grab the configuration values and inject possibly defined overrides for this data source
if ($is13) {
// old-style config array; PropelConfiguration was added after 1.3.0, http://trac.agavi.org/ticket/1195
$config = Propel::getConfiguration();
$config['datasources'][$datasource]['adapter'] = $this->getParameter('overrides[adapter]', $config['datasources'][$datasource]['adapter']);
$config['datasources'][$datasource]['connection'] = array_merge($config['datasources'][$datasource]['connection'], $this->getParameter('overrides[connection]', array()));
// also the autoload classes
$config['datasources'][$datasource]['classes'] = array_merge($config['datasources'][$datasource]['classes'], $this->getParameter('overrides[classes]', array()));
// and init queries
if (!isset($config['datasources'][$datasource]['connection']['settings']['queries']['query'])) {
$config['datasources'][$datasource]['connection']['settings']['queries']['query'] = array();
}
// array cast because "query" might be a string if just one init query was given, http://trac.agavi.org/ticket/1194
$config['datasources'][$datasource]['connection']['settings']['queries']['query'] = array_merge((array) $config['datasources'][$datasource]['connection']['settings']['queries']['query'], (array) $this->getParameter('init_queries'));
// set the new config
Propel::setConfiguration($config);
} else {
$config = Propel::getConfiguration(PropelConfiguration::TYPE_OBJECT);
$overrides = (array) $this->getParameter('overrides');
// set override values
foreach ($overrides as $key => $value) {
$config->setParameter($key, $value);
}
// handle init queries in a cross-adapter fashion (they all support the "init_queries" param)
$queries = (array) $config->getParameter('datasources.' . $datasource . '.connection.settings.queries.query', array());
// yes... it's one array, [connection][settings][queries][query], with all the init queries from the config, so we append to that
$queries = array_merge($queries, (array) $this->getParameter('init_queries'));
$config->setParameter('datasources.' . $datasource . '.connection.settings.queries.query', $queries);
}
if (true === $this->getParameter('enable_instance_pooling')) {
Propel::enableInstancePooling();
} elseif (false === $this->getParameter('enable_instance_pooling')) {
Propel::disableInstancePooling();
}
}
示例11: getSlowQueryThreshold
/**
* Returns the slow query threshold.
*
* @return integer|null
*/
protected function getSlowQueryThreshold()
{
return Propel::getConfiguration(PropelConfiguration::TYPE_OBJECT)->getParameter('debugpdo.logging.details.slow.threshold');
}
示例12: session
{
$result = $this->db->query("SELECT session_data FROM session WHERE session_id = '{$sess_id}'");
if ($result->rowCount() === 0) {
$this->db->exec("INSERT INTO session (session_id, date_created, last_updated, session_data) VALUES ('{$sess_id}', NOW(), NOW(), '')");
return '';
}
$res = $result->fetch(PDO::FETCH_ASSOC);
$this->db->exec("UPDATE session SET last_updated = NOW() WHERE session_id = '{$sess_id}'");
return $res['session_data'];
}
function write($sess_id, $data)
{
$this->db->exec("UPDATE session SET session_data = '{$data}', last_updated = NOW() WHERE session_id = '{$sess_id}'");
return true;
}
function destroy($sess_id)
{
$this->db->exec("DELETE FROM session WHERE session_id = '{$sess_id}'");
return true;
}
function gc($sess_maxlifetime)
{
$this->db->exec("DELETE FROM session WHERE session_data = \"slim.flash|a:0:{}\" AND last_updated < '" . date('c', time() - 86400 * 30) . "'");
return true;
}
}
$conf = Propel::getConfiguration(PropelConfiguration::TYPE_ARRAY);
$dbconf = $conf['datasources']['datawrapper']['connection'];
$pdo = new PDO($dbconf['dsn'], $dbconf['user'], $dbconf['password']);
$handler = new DatabaseSessionHandler($pdo);
session_set_save_handler(array($handler, 'open'), array($handler, 'close'), array($handler, 'read'), array($handler, 'write'), array($handler, 'destroy'), array($handler, 'gc'));
示例13: getConfiguration
/**
* Get the runtime configuration
*
* @return PropelConfiguration
*/
public function getConfiguration()
{
if (null === $this->configuration) {
$this->configuration = Propel::getConfiguration(PropelConfiguration::TYPE_OBJECT);
}
return $this->configuration;
}
示例14: _initPropel
private function _initPropel($propelConfig)
{
if (!file_exists($propelConfig)) {
throw new ZFscaffold_ZfTool_Exception("Propel config {$propelConfig} not exist");
}
//require_once $this->cwd. . '/../library/propel/Propel.php';
Propel::init($propelConfig);
$propelConf = Propel::getConfiguration();
if ($propelConf['classmap']) {
foreach ($propelConf['classmap'] as $class => $file) {
if (substr($class, -4) === 'Peer') {
class_exists($class);
}
}
}
$this->tables = Propel::getDatabaseMap()->getTables();
/** @var $table TableMap */
foreach ($this->tables as $table) {
$table->buildRelations();
Dfi_Propel_Helper::bulidRelationsOnFK($table);
Dfi_Propel_Helper::findAutoLabel($table);
}
}
示例15: getDatabaseName
/**
* Returns the name of the database which is used by Propel
*
* @return string the name of the database which is used by Propel
*/
private function getDatabaseName()
{
$config = Propel::getConfiguration();
$dsnString = $config['datasources'][Propel::getDefaultDB()]['connection']['dsn'];
$dbNameStart = stripos($dsnString, 'dbname=') + strlen('dbname=');
return substr($dsnString, $dbNameStart, strpos($dsnString, ';', $dbNameStart) - $dbNameStart);
}
开发者ID:kasperg,项目名称:symfony-propel-slope-one-recommendations-plugin,代码行数:12,代码来源:sfPropelSlopeOneMySqlBuilder.php