Development

Changeset 6805

You must first sign up to be able to contribute.

Changeset 6805

Show
Ignore:
Timestamp:
12/29/07 08:37:56 (8 months ago)
Author:
fabien
Message:

fixed sfPropelDatabase::initialize() signature (the database name is now a parameter - closes #2267)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/lib/config/sfDatabaseConfigHandler.class.php

    r6729 r6805  
    5050 
    5151    // get a list of database connections 
    52     foreach ($myConfig as $key => $dbConfig) 
     52    foreach ($myConfig as $name => $dbConfig) 
    5353    { 
    5454      // is this category already registered? 
    55       if (in_array($key, $databases)) 
     55      if (in_array($name, $databases)) 
    5656      { 
    5757        // this category is already registered 
    58         throw new sfParseException(sprintf('Configuration file "%s" specifies previously registered category "%s".', $configFiles[0], $key)); 
     58        throw new sfParseException(sprintf('Configuration file "%s" specifies previously registered category "%s".', $configFiles[0], $name)); 
    5959      } 
    6060 
    6161      // add this database 
    62       $databases[] = $key
     62      $databases[] = $name
    6363 
    6464      // let's do our fancy work 
     
    6666      { 
    6767        // missing class key 
    68         throw new sfParseException(sprintf('Configuration file "%s" specifies category "%s" with missing class key.', $configFiles[0], $key)); 
     68        throw new sfParseException(sprintf('Configuration file "%s" specifies category "%s" with missing class key.', $configFiles[0], $name)); 
    6969      } 
    7070 
     
    7272      { 
    7373        // we have a file to include 
    74         $file = $this->replaceConstants($dbConfig['file']); 
    75         $file = $this->replacePath($file); 
     74        $file = $this->replacePath($this->replaceConstants($dbConfig['file'])); 
    7675 
    7776        if (!is_readable($file)) 
     
    8685 
    8786      // parse parameters 
     87      $parameters = array(); 
    8888      if (isset($dbConfig['param'])) 
    8989      { 
    90         foreach ($dbConfig['param'] as &$value) 
     90        foreach ($dbConfig['param'] as $key => $value) 
    9191        { 
    92           $value = $this->replaceConstants($value); 
     92          $parameters[$key] = $this->replaceConstants($value); 
    9393        } 
    94  
    95         $parameters = var_export($dbConfig['param'], true); 
    9694      } 
    97       else 
    98       { 
    99         $parameters = 'null'; 
    100       } 
     95      $parameters['name'] = $name; 
    10196 
    10297      // append new data 
    103       $data[] = sprintf("\n\$database = new %s(%s, '%s');\n". 
    104                         "\$this->databases['%s'] = \$database;", 
    105                         $dbConfig['class'], $parameters, $key, $key); 
     98      $data[] = sprintf("\n\$this->databases['%s'] = new %s(%s);", $name, $dbConfig['class'], var_export($parameters, true)); 
    10699    } 
    107100 
    108101    // compile data 
    109     $retval = sprintf("<?php\n". 
     102    return sprintf("<?php\n". 
    110103                      "// auto-generated by sfDatabaseConfigHandler\n". 
    111104                      "// date: %s%s\n%s\n", 
    112105                      date('Y/m/d H:i:s'), implode("\n", $includes), implode("\n", $data)); 
    113  
    114     return $retval; 
    115106  } 
    116107} 
  • branches/1.1/lib/plugins/sfPropelPlugin/lib/propel/database/sfPropelDatabase.class.php

    r6370 r6805  
    3232    $config = array(); 
    3333 
    34   public function initialize($parameters = null, $name = 'propel'
     34  public function initialize($parameters = null
    3535  { 
    3636    parent::initialize($parameters); 
     
    3838    if (!$this->hasParameter('datasource')) 
    3939    { 
    40       $this->setParameter('datasource', $name); 
     40      $this->setParameter('datasource', $this->getParameter('name', 'propel')); 
    4141    } 
    4242