Development

/branches/1.0/lib/addon/propel/database/sfPropelDatabase.class.php

You must first sign up to be able to contribute.

root/branches/1.0/lib/addon/propel/database/sfPropelDatabase.class.php

Revision 8699, 3.6 kB (checked in by FabianLange, 7 years ago)

added compat options to propel databse (sfPropelDatabase.class.php) (fixes #3364)

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Rev Date
Line 
1 <?php
2
3 /*
4  * This file is part of the symfony package.
5  * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 /**
12  * A symfony database driver for Propel, derived from the native Creole driver.
13  *
14  * <b>Optional parameters:</b>
15  *
16  * # <b>datasource</b>     - [symfony] - datasource to use for the connection
17  * # <b>is_default</b>     - [false]   - use as default if multiple connections
18  *                                       are specified. The parameters
19  *                                       that has been flagged using this param
20  *                                       is be used when Propel is initialized
21  *                                       via sfPropelAutoload.
22  *
23  * @package    symfony
24  * @subpackage database
25  *
26  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
27  * @version    SVN: $Id$
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     // first defined if none listed as default
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
Note: See TracBrowser for help on using the browser.