| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
class sfPropelDatabase extends sfCreoleDatabase |
|---|
| 30 |
{ |
|---|
| 31 |
static protected |
|---|
| 32 |
$config = array(); |
|---|
| 33 |
|
|---|
| 34 |
public function initialize($parameters = null, $name = 'propel') |
|---|
| 35 |
{ |
|---|
| 36 |
parent::initialize($parameters); |
|---|
| 37 |
|
|---|
| 38 |
if (!$this->hasParameter('datasource')) |
|---|
| 39 |
{ |
|---|
| 40 |
$this->setParameter('datasource', $name); |
|---|
| 41 |
} |
|---|
| 42 |
|
|---|
| 43 |
$this->addConfig(); |
|---|
| 44 |
|
|---|
| 45 |
$is_default = $this->getParameter('is_default', false); |
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
if ($is_default || count(self::$config['propel']['datasources']) == 1) |
|---|
| 49 |
{ |
|---|
| 50 |
$this->setDefaultConfig(); |
|---|
| 51 |
} |
|---|
| 52 |
} |
|---|
| 53 |
|
|---|
| 54 |
public function setDefaultConfig() |
|---|
| 55 |
{ |
|---|
| 56 |
self::$config['propel']['datasources']['default'] = $this->getParameter('datasource'); |
|---|
| 57 |
} |
|---|
| 58 |
|
|---|
| 59 |
public function addConfig() |
|---|
| 60 |
{ |
|---|
| 61 |
if ($this->hasParameter('host')) |
|---|
| 62 |
{ |
|---|
| 63 |
$this->setParameter('hostspec', $this->getParameter('host')); |
|---|
| 64 |
} |
|---|
| 65 |
|
|---|
| 66 |
if ($dsn = $this->getParameter('dsn')) |
|---|
| 67 |
{ |
|---|
| 68 |
require_once('creole/Creole.php'); |
|---|
| 69 |
$params = Creole::parseDSN($dsn); |
|---|
| 70 |
|
|---|
| 71 |
$options = array('phptype', 'hostspec', 'database', 'username', 'password', 'port', 'protocol', 'encoding', 'persistent', 'socket','compat_assoc_lower','compat_rtrim_string'); |
|---|
| 72 |
foreach ($options as $option) |
|---|
| 73 |
{ |
|---|
| 74 |
if (!$this->getParameter($option) && isset($params[$option])) |
|---|
| 75 |
{ |
|---|
| 76 |
$this->setParameter($option, $params[$option]); |
|---|
| 77 |
} |
|---|
| 78 |
} |
|---|
| 79 |
} |
|---|
| 80 |
|
|---|
| 81 |
self::$config['propel']['datasources'][$this->getParameter('datasource')] = |
|---|
| 82 |
array( |
|---|
| 83 |
'adapter' => $this->getParameter('phptype'), |
|---|
| 84 |
'connection' => |
|---|
| 85 |
array( |
|---|
| 86 |
'phptype' => $this->getParameter('phptype'), |
|---|
| 87 |
'hostspec' => $this->getParameter('hostspec'), |
|---|
| 88 |
'database' => $this->getParameter('database'), |
|---|
| 89 |
'username' => $this->getParameter('username'), |
|---|
| 90 |
'password' => $this->getParameter('password'), |
|---|
| 91 |
'port' => $this->getParameter('port'), |
|---|
| 92 |
'encoding' => $this->getParameter('encoding'), |
|---|
| 93 |
'persistent' => $this->getParameter('persistent'), |
|---|
| 94 |
'protocol' => $this->getParameter('protocol'), |
|---|
| 95 |
'socket' => $this->getParameter('socket'), |
|---|
| 96 |
'compat_assoc_lower' => $this->getParameter('compat_assoc_lower'), |
|---|
| 97 |
'compat_rtrim_string' => $this->getParameter('compat_rtrim_string'), |
|---|
| 98 |
), |
|---|
| 99 |
); |
|---|
| 100 |
} |
|---|
| 101 |
|
|---|
| 102 |
public static function getConfiguration() |
|---|
| 103 |
{ |
|---|
| 104 |
return self::$config; |
|---|
| 105 |
} |
|---|
| 106 |
|
|---|
| 107 |
public function setConnectionParameter($key, $value) |
|---|
| 108 |
{ |
|---|
| 109 |
if ($key == 'host') |
|---|
| 110 |
{ |
|---|
| 111 |
$key = 'hostspec'; |
|---|
| 112 |
} |
|---|
| 113 |
|
|---|
| 114 |
self::$config['propel']['datasources'][$this->getParameter('datasource')]['connection'][$key] = $value; |
|---|
| 115 |
$this->setParameter($key, $value); |
|---|
| 116 |
} |
|---|
| 117 |
} |
|---|
| 118 |
|
|---|