[ Index ]
 

Code source de Symfony 1.0.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/addon/propel/database/ -> sfPropelDatabase.class.php (source)

   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: sfPropelDatabase.class.php 3493 2007-02-18 09:23:10Z fabien $
  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');
  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          ),
  96        );
  97    }
  98  
  99    public static function getConfiguration()
 100    {
 101      return self::$config;
 102    }
 103  
 104    public function setConnectionParameter($key, $value)
 105    {
 106      if ($key == 'host')
 107      {
 108        $key = 'hostspec';
 109      }
 110  
 111      self::$config['propel']['datasources'][$this->getParameter('datasource')]['connection'][$key] = $value;
 112      $this->setParameter($key, $value);
 113    }
 114  }


Généré le : Fri Mar 16 22:42:14 2007 par Balluche grâce à PHPXref 0.7