Development

Changeset 10655

You must first sign up to be able to contribute.

Changeset 10655

Show
Ignore:
Timestamp:
08/04/08 21:50:47 (4 months ago)
Author:
francois
Message:

sfPropelFinderPlugin Refactoring for better code clarity:

  • [BC Break] Replaced sfPropelFinder::setPeerClass() by sfPropelFinder::setClass() (will break classes extending sfPropelFinder)
  • Refactored connection management, query reinitialization, and simplified executers signature
  • Abstract methods in DbFinder
  • Implemented sfDoctrineFinder::count()
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfPropelFinderPlugin/README

    r10606 r10655  
    514514=== Writing your own business logic into a finder === 
    515515 
    516 You can create a new finder for your objects, with custom methods. The only prerequisites are to extend `sfPropelFinder` and to define a protected `$peerClass` property. Then, the object has access to a protected `$criteria` property, which is a Propel Criteria that can be augmented in the usual way. Don't forget to return the current object (`$this`) in the new methods. 
     516You can create a new finder for your objects, with custom methods. The only prerequisites are to extend `sfPropelFinder` and to define a protected `$class` property. Then, the object has access to a protected `$criteria` property, which is a Propel Criteria that can be augmented in the usual way. Don't forget to return the current object (`$this`) in the new methods. 
    517517 
    518518{{{ 
     
    522522class ArticleFinder extends sfPropelFinder 
    523523{ 
    524   protected $peerClass = 'ArticlePeer'; 
     524  protected $class = 'Article'; 
    525525 
    526526  public function recent() 
     
    596596 
    597597== TODO / Ideas == 
    598  
     598  
     599 * Fix connection issue (defined at initialization with Doctrine, at the end with Propel) 
    599600 * Allow i18n hydration of related objects (#3897) 
    600601 * Allow `between` as a `where()` operator for simplicity 
     
    611612== Changelog == 
    612613 
    613 === 2008-08-02 | Trunk === 
    614  
     614=== 2008-08-04 | Trunk === 
     615 
     616 * francois: Implemented `sfDoctrineFinder::count()` 
     617 * francois: [BC Break] Replaced `sfPropelFinder::setPeerClass()` by `sfPropelFinder::setClass()` (will break classes extending sfPropelFinder) 
     618 * francois: Refactored connection management, query reinitialization, and simplified executers signature 
    615619 * francois: Implemented `sfDoctrineFinder::fromArray()`, and `sfDoctrineFinder::getLatestQuery()` 
    616620 * francois: Added `DbFinderAdminGenerator` (WIP) 
  • plugins/sfPropelFinderPlugin/lib/DbFinder.php

    r10606 r10655  
    1010 */ 
    1111  
    12 class DbFinder 
     12abstract class DbFinder 
    1313{ 
    1414  const  
     
    1818  protected $relations = array(); 
    1919   
     20  public function __construct($class = '', $connection = null) 
     21  { 
     22    $this->connection = $connection; 
     23    $class = $class ? $class : $this->class; 
     24    if($class) 
     25    { 
     26      list($class, $alias) = $this->getClassAndAlias($class); 
     27      $this->setClass($class, $alias); 
     28    } 
     29  } 
     30   
    2031  // Finder Initializers 
    2132   
     
    2536   * 
    2637   * @param mixed $from The data to initialize the finder with 
     38   * @param mixed $connection Optional connection object 
     39   * 
    2740   * @return DbFinder a finder object 
    2841   * @throws Exception If the data is neither a classname nor an array 
    2942   */ 
    30   public static function from($from
     43  public static function from($from, $connection = null
    3144  { 
    3245    if (is_string($from)) 
    3346    { 
    34       return self::fromClass($from); 
     47      return self::fromClass($from, $connection); 
    3548    } 
    3649    if (is_array($from) || $from instanceof Doctrine_Collection) 
     
    4154  } 
    4255   
    43     /** 
     56  /** 
    4457   * Class initializer 
    4558   * 
    4659   * @param string $from Model classname on which the search will be done 
     60   * @param mixed $connection Optional connection object 
     61   * 
    4762   * @return DbFinder a finder object 
    4863   */ 
    49   public static function fromClass($class
     64  public static function fromClass($class, $connection = null
    5065  { 
    5166    if(strpos($class, ' ') !== false) 
     
    6075    if($tmp instanceof BaseObject) 
    6176    { 
    62       $finder = new sfPropelFinder($class); 
     77      $finder = new sfPropelFinder($class, $connection); 
    6378    } 
    6479    else if($tmp instanceof Doctrine_Record) 
    6580    { 
    66       $finder = new sfDoctrineFinder($class); 
     81      $finder = new sfDoctrineFinder($class, $connection); 
    6782    } 
    6883    else 
     
    202217  } 
    203218   
     219  // Finder accessors 
     220   
     221  abstract public function getClass(); 
     222  abstract public function setClass($class, $alias = ''); 
     223  abstract public function getConnection(); 
     224  abstract public function setConnection($connection); 
     225   
     226  // Finder executers 
     227   
     228  abstract public function count($distinct = false); 
     229  abstract public function find($limit = null); 
     230  abstract public function findOne(); 
     231  abstract public function findLast($column = null); 
     232  abstract public function findFirst($column = null); 
     233  abstract public function findBy($columnName, $value, $limit = null); 
     234  abstract public function findOneBy($columnName, $value); 
     235  abstract public function findPk($pk); 
     236  abstract public function delete($forceIndividualDeletes = false); 
     237  abstract public function paginate($page = 1, $maxPerPage = 10); 
     238  abstract public function set($values, $forceIndividualSaves = false); 
     239 
     240  // Finder utilities 
     241   
     242  abstract public function getLatestQuery(); 
     243  abstract protected function cleanup(); 
     244   
    204245  // Finder Outputters 
    205246   
  • plugins/sfPropelFinderPlugin/lib/sfDoctrineFinder.php

    r10606 r10655  
    1313{ 
    1414  protected 
     15    $connection    = null, 
    1516    $class         = null, 
     17    $alias         = null, 
    1618    $object        = null, 
     19    $reinit        = true, 
    1720    $queryListener = null, 
    1821    $withClasses   = array(), 
    1922    $withColumns   = array(), 
    2023    $culture       = null; 
    21  
    22   public function __construct($class = '') 
    23   { 
    24     if($class) 
    25     { 
    26       list($class, $alias) = $this->getClassAndAlias($class); 
    27       $this->setClass($class, $alias); 
    28     } 
    29     elseif($this->class) 
    30     { 
    31       list($class, $alias) = $this->getClassAndAlias($this->class); 
    32       $this->setClass($class, $alias); 
    33     } 
    34   } 
    3524   
    3625  public function getClass() 
     
    3827    return $this->class; 
    3928  } 
    40  
     29   
     30  /** 
     31   * Caution: reinitializes the finder's Doctrine_Query object 
     32   */ 
    4133  public function setClass($class, $alias = '') 
    4234  { 
    4335    $this->addRelation($class, $alias); 
    4436    $this->class = $class; 
     37    $this->alias = $alias; 
    4538    $this->object = new $class(); 
    46     $this->query = Doctrine_Query::create()->from($class . ' ' . $alias); 
     39    $this->initialize($this->connection, $class, $alias); 
     40     
     41    return $this; 
     42  } 
     43 
     44  public function getConnection() 
     45  { 
     46    return $this->connection; 
     47  } 
     48 
     49  /** 
     50   * Caution: reinitializes the finder's Doctrine_Query object 
     51   */ 
     52  public function setConnection($connection) 
     53  { 
     54    $this->connection = $connection; 
     55    if($this->class) 
     56    { 
     57      $this->initialize($connection, $this->class, $this->alias); 
     58    } 
     59     
     60    return $this; 
     61  } 
     62   
     63  public function initialize($connection, $class, $alias) 
     64  { 
     65    $this->query = Doctrine_Query::create($connection)->from($class . ' ' . $alias); 
    4766    $this->queryListener = sfDoctrineFinderListener::getInstance(); 
    48      
    4967     
    5068    return $this; 
     
    6280  } 
    6381 
    64   public function getLatestQuery($con = null
     82  public function getLatestQuery(
    6583  { 
    6684    return $this->queryListener->getLatestQuery(); 
    6785  } 
    6886   
    69   public function updateLatestQuery($con = null
     87  public function updateLatestQuery(
    7088  { 
    7189     throw new Exception('This method is not yet implemented'); 
     
    105123  // Finder Executers 
    106124   
    107   public function count($con = null, $reinitCriteria = true) 
    108   { 
    109     throw new Exception('This method is not yet implemented'); 
    110   } 
    111    
    112   public function find($limit = null, $con = null, $reinitCriteria = false) 
     125  public function count($distinct = false) 
     126  { 
     127    $res = $this->query->count(); 
     128    $this->cleanup(); 
     129     
     130    return $res; 
     131  } 
     132   
     133  public function find($limit = null) 
    113134  { 
    114135    if($limit) 
     
    116137      $this->query->limit($limit); 
    117138    } 
    118     return $this->query->execute(); 
    119   } 
    120    
    121   public function findOne($con = null, $reinitCriteria = true) 
    122   { 
    123     $coll = $this->find(1, $con, $reinitCriteria); 
    124      
    125     return isset($coll[0]) ? $coll[0] : null; 
    126   } 
    127    
    128   public function findLast($column = null, $con = null, $reinitCriteria = true) 
     139    $res = $this->query->execute(); 
     140    $this->cleanup(); 
     141     
     142    return $res; 
     143  } 
     144   
     145  public function findOne() 
     146  { 
     147    $records = $this->find(1); 
     148     
     149    return isset($records[0]) ? $records[0] : null; 
     150  } 
     151   
     152  public function findLast($column = null) 
    129153  { 
    130154    if($column) 
     
    140164  } 
    141165   
    142   public function findFirst($column = null, $con = null, $reinitCriteria = true
     166  public function findFirst($column = null
    143167  { 
    144168    if($column) 
     
    154178  } 
    155179   
    156   public function findBy($columnName, $value, $limit = null, $con = null, $reinitCriteria = false
     180  public function findBy($columnName, $value, $limit = null
    157181  { 
    158182    $column = $this->getColName($columnName); 
    159183    $this->where($column, '=', $value); 
    160184     
    161     return $this->find($limit, $con, $reinitCriteria); 
    162   } 
    163  
    164   public function findOneBy($columnName, $value, $con = null, $reinitCriteria = false
     185    return $this->find($limit); 
     186  } 
     187 
     188  public function findOneBy($columnName, $value
    165189  { 
    166190    $column = $this->getColName($columnName); 
    167191    $this->where($column, '=', $value); 
    168192     
    169     return $this->findOne($con, $reinitCriteria); 
    170   } 
    171    
    172   public function findPk($pk, $con = null
     193    return $this->findOne(); 
     194  } 
     195   
     196  public function findPk($pk
    173197  { 
    174198    $pkColumns = $this->getObject()->getTable()->getIdentifierColumnNames(); 
     
    208232  } 
    209233   
    210   public function delete($con = null, $reinitCriteria = true) 
    211   { 
    212     throw new Exception('This method is not yet implemented'); 
    213   } 
    214    
    215   public function paginate($page = 1, $maxPerPage = 10, $con = null) 
    216   { 
    217     throw new Exception('This method is not yet implemented'); 
    218   } 
    219    
    220   public function set($values, $forceIndividualSaves = false, $con = null, $reinitCriteria = true ) 
    221   { 
    222     throw new Exception('This method is not yet implemented'); 
    223   } 
    224    
    225   public function doFind($con = null) 
     234  public function delete($forceIndividualDeletes = false) 
     235  { 
     236    $this->cleanup(); 
     237    throw new Exception('This method is not yet implemented'); 
     238  } 
     239   
     240  public function paginate($page = 1, $maxPerPage = 10) 
     241  { 
     242    throw new Exception('This method is not yet implemented'); 
     243  } 
     244   
     245  public function set($values, $forceIndividualSaves = false) 
     246  { 
     247    $this->cleanup(); 
     248    throw new Exception('This method is not yet implemented'); 
     249  } 
     250   
     251  protected function cleanup() 
     252  { 
     253    if($this->reinit) 
     254    { 
     255      $this->initialize($this->connection, $this->class, $this->alias); 
     256    } 
     257     
     258    return $this; 
     259  } 
     260   
     261   
     262  public function doFind() 
    226263  { 
    227264    throw new Exception('This method is not yet implemented'); 
     
    466503  } 
    467504   
     505  public function keepQuery($keep = true) 
     506  { 
     507    $this->reinit = $keep; 
     508     
     509    return $this; 
     510  } 
     511   
    468512  protected function hasRelation($peerName) 
    469513  { 
  • plugins/sfPropelFinderPlugin/lib/sfDoctrineFinderListener.php

    r10607 r10655  
    5252  public function getLatestQuery() 
    5353  { 
    54     return $this->queries[count($this->queries)-1]
     54    return ($count = count($this->queries)) ? $this->queries[$count - 1] : ''
    5555  } 
    5656   
  • plugins/sfPropelFinderPlugin/lib/sfPropelFinder.php

    r10592 r10655  
    1212class sfPropelFinder extends DbFinder 
    1313{ 
    14   protected $class = null; 
    15   protected $peerClass = null; 
    16   protected $databaseMap = null; 
    17   protected $criteria = null; 
    18   protected $latestQuery = ''; 
    19   protected $criterions = array(); 
    20   protected $withClasses = array(); 
    21   protected $withColumns = array(); 
    22   protected $culture = null; 
    23  
    24   public function __construct($class = '') 
    25   { 
    26     $this->criteria = new Criteria(); 
    27     if($class) 
    28     { 
    29       // Instanciation with a class 
    30       list($class, $alias) = $this->getClassAndAlias($class); 
    31       $this->class = $class; 
    32       $tmp = new $class; 
    33       $this->setPeerClass(get_class($tmp->getPeer()), $alias); 
    34     } 
    35     else if($this->peerClass) 
    36     { 
    37       // Instanciation for a child of sfPropelFinder 
    38       $this->addRelation($this->peerClass); 
    39     } 
    40     if($this->peerClass) 
    41     { 
    42       $this->initialize(); 
    43     } 
    44   } 
    45    
     14  protected  
     15    $class        = null, 
     16    $peerClass    = null, 
     17    $object       = null, 
     18    $databaseMap  = null, 
     19    $connection   = null, 
     20    $criteria     = null, 
     21    $reinit       = true, 
     22    $latestQuery  = '', 
     23    $criterions   = array(), 
     24    $withClasses  = array(), 
     25    $withColumns  = array(), 
     26    $culture      = null; 
     27   
     28  public function getClass() 
     29  { 
     30    return $this->class; 
     31  } 
     32 
     33  public function setClass($class, $alias = '') 
     34  { 
     35    $this->class = $class; 
     36    $this->object = new $class(); 
     37    $this->peerClass = get_class($this->object->getPeer()); 
     38    $this->addRelation($this->peerClass, $alias); 
     39    $this->initialize(); 
     40     
     41    return $this; 
     42  } 
     43 
     44  public function getConnection() 
     45  { 
     46    if(is_null($this->connection)) 
     47    { 
     48      $name = $this->peerClass ? constant($this->peerClass.'::DATABASE_NAME') : ''; 
     49      $this->connection = Propel::getConnection($name); 
     50    } 
     51     
     52    return $this->connection; 
     53  } 
     54 
     55  public function setConnection($connection) 
     56  { 
     57    $this->connection = $connection; 
     58     
     59    return $this; 
     60  } 
     61 
    4662  public function initialize() 
    4763  { 
     64    $this->reinitCriteria(); 
    4865    $mapBuilder = call_user_func(array($this->peerClass, 'getMapBuilder')); 
    4966    $mapBuilder->doBuild(); 
     
    5168  } 
    5269   
    53   public function getPeerClass() 
    54   { 
    55     return $this->peerClass; 
    56   } 
    57  
    58   public function setPeerClass($peerClass, $alias = '') 
    59   { 
    60     $this->addRelation($peerClass, $alias); 
    61     $this->peerClass = $peerClass; 
    62      
    63     return $this; 
    64   } 
    65    
    6670  protected function addRelation($peerClass, $alias = '') 
    6771  { 
     
    8892  } 
    8993   
    90   public function getLatestQuery($con = null) 
    91   { 
    92     if(is_null($con)) $con = Propel::getConnection(); 
    93     if(method_exists($con, 'getLastExecutedQuery')) 
     94  public function getLatestQuery() 
     95  { 
     96    if(method_exists($this->getConnection(), 'getLastExecutedQuery')) 
    9497    { 
    9598      return $this->latestQuery; 
     
    101104  } 
    102105   
    103   public function updateLatestQuery($con = null) 
    104   { 
    105     if(is_null($con)) $con = Propel::getConnection(); 
    106     if(method_exists($con, 'getLastExecutedQuery')) 
    107     { 
    108       $this->latestQuery = $con->getLastExecutedQuery(); 
     106  public function updateLatestQuery() 
     107  { 
     108    if(method_exists($this->getConnection(), 'getLastExecutedQuery')) 
     109    { 
     110      $this->latestQuery = $this->getConnection()->getLastExecutedQuery(); 
    109111    } 
    110112  } 
     
    143145  // Finder Executers 
    144146   
    145   public function count($con = null, $reinitCriteria = true) 
    146   { 
    147     $ret = call_user_func(array($this->getPeerClass(), 'doCount'), $this->getCriteria(), $con); 
    148     $this->updateLatestQuery($con); 
    149     if($reinitCriteria) 
    150     { 
    151       $this->reinitCriteria(); 
    152     } 
     147  public function count($distinct = false) 
     148  { 
     149    $ret = call_user_func(array($this->peerClass, 'doCount'), $this->getCriteria(), $distinct, $this->getConnection()); 
     150    $this->cleanup(); 
    153151     
    154152    return $ret; 
    155153  } 
    156154   
    157   public function find($limit = null, $con = null, $reinitCriteria = false
     155  public function find($limit = null
    158156  { 
    159157    if($limit) 
     
    161159      $this->criteria->setLimit($limit); 
    162160    } 
    163     $ret = $this->doFind($con); 
    164     $this->updateLatestQuery($con); 
    165     if($reinitCriteria) 
    166     { 
    167       $this->reinitCriteria(); 
    168     } 
     161    $ret = $this->doFind(); 
     162    $this->cleanup(); 
    169163     
    170164    return $ret; 
    171165  } 
    172166   
    173   public function findOne($con = null, $reinitCriteria = true
     167  public function findOne(
    174168  { 
    175169    $this->criteria->setLimit(1); 
    176     $ret = $this->doFind($con); 
    177     $this->updateLatestQuery($con); 
    178     if($reinitCriteria) 
    179     { 
    180       $this->reinitCriteria(); 
    181     } 
    182     if ($ret) 
    183     { 
    184       return $ret[0]; 
    185     } 
    186     return null; 
    187   } 
    188    
    189   public function findLast($column = null, $con = null, $reinitCriteria = true) 
     170    $ret = $this->doFind(); 
     171    $this->cleanup(); 
     172     
     173    return isset($ret[0]) ? $ret[0] : null; 
     174  } 
     175   
     176  public function findLast($column = null) 
    190177  { 
    191178    if($column) 
     
    198185    } 
    199186     
    200     return $this->findOne($con, $reinitCriteria); 
    201   } 
    202    
    203   public function findFirst($column = null, $con = null, $reinitCriteria = true
     187    return $this->findOne(); 
     188  } 
     189   
     190  public function findFirst($column = null
    204191  { 
    205192    if($column) 
     
    212199    } 
    213200     
    214     return $this->findOne($con, $reinitCriteria); 
    215   } 
    216    
    217   public function findBy($columnName, $value, $limit = null, $con = null, $reinitCriteria = false
     201    return $this->findOne(); 
     202  } 
     203   
     204  public function findBy($columnName, $value, $limit = null
    218205  { 
    219206    $column = $this->getColName($columnName); 
    220207    $this->addCondition('and', $column, $value, Criteria::EQUAL); 
    221208     
    222     return $this->find($limit, $con, $reinitCriteria); 
    223   } 
    224  
    225   public function findOneBy($columnName, $value, $con = null, $reinitCriteria = false
     209    return $this->find($limit); 
     210  } 
     211 
     212  public function findOneBy($columnName, $value
    226213  { 
    227214    $column = $this->getColName($columnName); 
    228215    $this->addCondition('and', $column, $value, Criteria::EQUAL); 
    229216     
    230     return $this->findOne($con, $reinitCriteria); 
    231   } 
    232    
    233   public function findPk($pk, $con = null
     217    return $this->findOne(); 
     218  } 
     219   
     220  public function findPk($pk
    234221  { 
    235222    $tableMap = call_user_func(array($this->peerClass, 'getTableMap')); 
     
    283270   * 
    284271   * @param Boolean $forceIndividualDeletes If false (default), the resulting call is a BasePeer::doDelete(), ortherwise it is a series of delete() calls on all the found objects 
    285    * @param Connection $con optional connection object 
    286    * @param Boolean $reinitCriteria If true (default), the finder Criteria objects is replaced by a new one after deletion 
    287272   * 
    288273   * @return Integer Number of deleted rows 
    289274   */ 
    290   public function delete($forceIndividualDeletes = false, $con = null, $reinitCriteria = true
     275  public function delete($forceIndividualDeletes = false
    291276  { 
    292277    $deleteCriteria = $this->getCriteria(); 
    293278    if($forceIndividualDeletes) 
    294279    { 
    295       $objects = $this->find(null, $con, $reinitCriteria); 
     280      $objects = $this->find(); 
    296281      foreach($objects as $object) 
    297282      { 
    298         $object->delete(); 
     283        $object->delete($this->getConnection()); 
    299284      } 
    300285      $ret = count($objects); 
     
    308293        $deleteCriteria = $this->addTrueCondition($deleteCriteria); 
    309294      } 
    310       $ret = call_user_func(array($this->getPeerClass(), 'doDelete'), $deleteCriteria, $con); 
    311     } 
    312     $this->updateLatestQuery($con); 
    313     if($reinitCriteria) 
    314     { 
    315       $this->reinitCriteria(); 
    316     } 
     295      $ret = call_user_func(array($this->peerClass, 'doDelete'), $deleteCriteria, $this->getConnection()); 
     296    } 
     297    $this->cleanup(); 
    317298     
    318299    return $ret; 
    319300  } 
    320301   
    321   public function paginate($page = 1, $maxPerPage = 10, $con = null
     302  public function paginate($page = 1, $maxPerPage = 10
    322303  { 
    323304    // Children of sfPropelPager don't have a $class property, so we need to guess it 
    324     $class = isset($this->class) ? $this->class : sfPropelFinderUtils::getClassFromPeerClass($this->peerClass); 
    325     $pager = new sfPropelFinderPager($class, $maxPerPage); 
     305    $pager = new sfPropelFinderPager($this->class, $maxPerPage); 
    326306    $pager->setFinder($this); 
    327     $pager->setConnection($con); 
    328307    $pager->setPage($page); 
    329308    $pager->init(); 
     
    339318   * @param Array $values Associative array of keys and values to replace 
    340319   * @param Boolean $forceIndividualSaves If false (default), the resulting call is a BasePeer::doUpdate(), ortherwise it is a series of save() calls on all the found objects 
    341    * @param Connection $con optional connection object 
    342    * @param Boolean $reinitCriteria If true (default), the finder Criteria objects is replaced by a new one after update 
    343320   * 
    344321   * @return Integer Number of deleted rows 
    345322   */ 
    346   public function set($values, $forceIndividualSaves = false, $con = null, $reinitCriteria = true
     323  public function set($values, $forceIndividualSaves = false
    347324  { 
    348325    if (!is_array($values)) 
     
    352329    if($forceIndividualSaves) 
    353330    { 
    354       $objects = $this->find(null, $con, $reinitCriteria); 
     331      $objects = $this->find(); 
    355332      foreach ($objects as $object) 
    356333      { 
     
    383360      } 
    384361       
    385       if(is_null($con)) $con = Propel::getConnection(); 
    386       $ret = BasePeer::doUpdate($find, $set, $con); 
    387     } 
    388     $this->updateLatestQuery($con); 
    389     if($reinitCriteria) 
     362      $ret = BasePeer::doUpdate($find, $set, $this->getConnection()); 
     363    } 
     364    $this->cleanup(); 
     365     
     366    return $ret; 
     367  } 
     368   
     369  protected function cleanup() 
     370  { 
     371    if($this->reinit) 
    390372    { 
    391373      $this->reinitCriteria(); 
    392374    } 
    393      
    394     return $ret; 
    395   } 
    396    
    397   public function doFind($con = null) 
     375    $this->updateLatestQuery(); 
     376     
     377    return $this; 
     378  } 
     379   
     380  public function doFind() 
    398381  { 
    399382    $this->addMissingJoins(); 
     
    401384    { 
    402385      $c = $this->prepareCompositeCriteria(); 
    403       if(method_exists($this->getPeerClass(), 'doSelectRS')) 
    404       { 
    405         $resultSet = call_user_func(array($this->getPeerClass(), 'doSelectRS'), $c, $con); 
     386      if(method_exists($this->peerClass, 'doSelectRS')) 
     387      { 
     388        $resultSet = call_user_func(array($this->peerClass, 'doSelectRS'), $c, $this->getConnection()); 
    406389        $propelVersion = '1.2'; 
    407390        $nextFunction = 'next'; 
     
    410393      else 
    411394      { 
    412         $resultSet = call_user_func(array($this->getPeerClass(), 'doSelectStmt'), $c, $con); 
     395        $resultSet = call_user_func(array($this->peerClass, 'doSelectStmt'), $c, $this->getConnection()); 
    413396        $propelVersion = '1.3'; 
    414397        $nextFunction = 'fetch'; 
     
    417400       
    418401      // Hydrate the objects based on the resultset 
    419       $omClass = call_user_func(array($this->getPeerClass(), 'getOMClass')); 
     402      $omClass = call_user_func(array($this->peerClass, 'getOMClass')); 
    420403      $cls = substr('.'.$omClass, strrpos('.'.$omClass, '.') + 1); 
    421404      $objects = array(); 
     
    529512    { 
    530513      // No 'with', so we use the native Propel doSelect() 
    531       return call_user_func(array($this->getPeerClass(), 'doSelect'), $this->buildCriteria(), $con); 
     514      return call_user_func(array($this->peerClass, 'doSelect'), $this->buildCriteria(), $this->getConnection()); 
    532515    } 
    533516  } 
     
    566549    $c->clearSelectColumns(); 
    567550    // First come the columns of the main class 
    568     call_user_func(array($this->getPeerClass(), 'addSelectColumns'), $c); 
     551    call_user_func(array($this->peerClass, 'addSelectColumns'), $c); 
    569552    // Then the related classes added by way of 'with' 
    570553    foreach ($this->getWithClasses() as $className) 
     
    840823  { 
    841824    $relatedObjectTableName = $object->getPeer()->getTableMap()->getName(); 
    842     foreach (sfPropelFinderUtils::getColumnsForPeerClass($this->getPeerClass()) as $c) 
     825    foreach (sfPropelFinderUtils::getColumnsForPeerClass($this->peerClass) as $c) 
    843826    { 
    844827      if($c->getRelatedTableName() == $relatedObjectTableName) 
     
    939922  { 
    940923    $columnNames = array(); 
    941     foreach (sfPropelFinderUtils::getColumnsForPeerClass($this->getPeerClass()) as $c) 
     924    foreach (sfPropelFinderUtils::getColumnsForPeerClass($this->peerClass) as $c) 
    942925    { 
    943926      $columnNames []= $c->getPhpName(); 
     
    1006989  } 
    1007990   
     991  public function keepQuery($keep = true) 
     992  { 
     993    $this->reinit = $keep; 
     994     
     995    return $this; 
     996  } 
     997   
    1008998  protected function hasRelation($peerName) 
    1009999  { 
     
    10851075  protected function addTrueCondition(Criteria $c) 
    10861076  { 
    1087     $fieldNames = call_user_func(array($this->getPeerClass(), 'getFieldNames'), BasePeer::TYPE_COLNAME); 
     1077    $fieldNames = call_user_func(array($this->peerClass, 'getFieldNames'), BasePeer::TYPE_COLNAME); 
    10881078    $firstFieldName = $fieldNames[0]; 
    10891079    $c->add($firstFieldName, true, Criteria::BINARY_OR); 
     
    11421132   * Cloning instance should clone its components. 
    11431133   *   
    1144    * Solves problems with sfPropelFinderPager.  
     1134   * Solves problems with sfPropelFinderPager. 
    11451135   */  
    11461136  public function __clone() 
  • plugins/sfPropelFinderPlugin/lib/sfPropelFinderPager.php

    r10542 r10655  
    33{ 
    44  protected  
    5     $finder,  
    6     $connection; 
    7  
     5    $finder; 
     6     
    87  /** 
    98   * __construct 
     
    4140 
    4241  /** 
    43    * Set finder object for the pager 
    44    * 
    45    * @param sfPropelFinder $finder 
    46    * @return void 
    47    */ 
    48   public function setConnection($connection) 
    49   { 
    50     $this->connection = $connection; 
    51   } 
    52  
    53   /** 
    54    * Get the connection for the pager 
    55    * 
    56    * @return Connection $connection 
    57    */ 
    58   public function getConnection() 
    59   { 
    60     return $this->connection; 
    61   } 
    62  
    63   /** 
    6442   * init pager 
    6543   * 
    6644   * @return void 
    6745   */ 
    68   public function init($con = null
     46  public function init(
    6947  { 
    7048    $hasMaxRecordLimit = ($this->getMaxRecordLimit() !== false); 
     
    7654      setLimit(0)-> 
    7755      clearGroupByColumns()-> 
    78       count($con ? $con : $this->getConnection()); 
     56      count(); 
    7957 
    8058    $this->setNbResults($hasMaxRecordLimit ? min($count, $maxRecordLimit) : $count); 
     
    135113   * @return Array $array of BaseObject instances 
    136114   */ 
    137   public function getResults($con = null
     115  public function getResults(
    138116  { 
    139     return $this->getFinder()->find($con ? $con : $this->getConnection()); 
     117    return $this->getFinder()->find(); 
    140118  } 
    141119   
  • plugins/sfPropelFinderPlugin/test/unit/sfDoctrineFinderTest.php

    r10606 r10655  
    7171Doctrine_Query::create()->delete()->from('DArticle')->execute(); 
    7272 
    73 $t = new lime_test(47, new lime_output_color()); 
     73$t = new lime_test(53, new lime_output_color()); 
    7474 
    7575$t->diag('find()'); 
     
    278278$finder = new sfDoctrineFinder('DArticle'); 
    279279$t->is($finder->getClass(), 'DArticle', 'Record Class can be set during instanciation, in which case the finder is automatically initialized'); 
    280 $articles = $finder->find(); 
    281 $article = $articles[0]
     280$article = $finder->findOne(); 
     281$t->isa_ok($article, 'DArticle', 'A finder instanciated directly with a Record class returns the correct objects')
    282282$t->is($article->getTitle(), 'foo', 'A finder instanciated directly with a Record class returns the correct objects'); 
    283283 
     
    285285$finder->setClass('DArticle'); 
    286286$t->is($finder->getClass(), 'DArticle', 'setClass() and getClass() are accesors to the protected $class property'); 
    287 $articles = $finder->find(); 
    288 $article = $articles[0]
     287$article = $finder->findOne(); 
     288$t->isa_ok($article, 'DArticle', 'A finder instanciated directly with a Record class returns the correct objects')
    289289$t->is($article->getTitle(), 'foo', 'A finder can be instanciated without parameter, and initialized later after defining its class'); 
    290290 
     
    335335$articles = sfDoctrineFinder::from($category1->getArticles())->where('Title', 'aaaaa')->find(); 
    336336$t->is(count($articles), 1, 'A finder initialized from an array accepts further conditions'); 
     337 
     338$t->diag('count()'); 
     339 
     340Doctrine_Query::create()->delete()->from('DArticle')->execute(); 
     341$finder = new sfDoctrineFinder('DArticle'); 
     342$nbArticles = $finder->count(); 
     343$t->isa_ok($nbArticles, 'integer', 'count() returns an integer'); 
     344$t->is($nbArticles, 0, 'count() returns 0 on empty tables'); 
     345$article2 = new DArticle(); 
     346$article2->setTitle('foo2'); 
     347$article2->save(); 
     348$article3 = new DArticle(); 
     349$article3->setTitle('foo3'); 
     350$article3->save(); 
     351$nbArticles = $finder->count(); 
     352$t->is($nbArticles, 2, 'count() returns the number of records matching the condition'); 
     353$nbArticles = $finder->whereTitle('foo2')->count(); 
     354$t->is($nbArticles, 1, 'count() returns the number of records matching the condition'); 
  • plugins/sfPropelFinderPlugin/test/unit/sfPropelFinderInternalsTest.php

    r10342 r10655  
    6060$databaseManager->initialize(); 
    6161 
    62 $con = Propel::getConnection(); 
    63  
    6462// cleanup database 
    6563ArticlePeer::doDeleteAll(); 
  • plugins/sfPropelFinderPlugin/test/unit/sfPropelFinderPagerTest.php

    r10546 r10655  
    140140class ArticleFinder extends sfPropelFinder 
    141141{ 
    142   protected $peerClass = 'ArticlePeer'; 
     142  protected $class = 'Article'; 
    143143} 
    144144$finder = new ArticleFinder(); 
  • plugins/sfPropelFinderPlugin/test/unit/sfPropelFinderRelationsTest.php

    r10592 r10655  
    7777$databaseManager->initialize(); 
    7878 
    79 $con = Propel::getConnection(); 
    80  
    8179$t = new lime_test(82, new lime_output_color()); 
    8280 
     
    472470class ArticleFinder extends sfPropelFinder 
    473471{ 
    474   protected $peerClass = 'ArticlePeer'; 
     472  protected $class = 'Article'; 
    475473} 
    476474 
  • plugins/sfPropelFinderPlugin/test/unit/sfPropelFinderTest.php

    r10545 r10655  
    6060$databaseManager->initialize(); 
    6161 
    62 $con = Propel::getConnection(); 
    63  
    6462// cleanup database 
    6563ArticlePeer::doDeleteAll(); 
    6664 
    67 $t = new lime_test(120, new lime_output_color()); 
     65$t = new lime_test(122, new lime_output_color()); 
    6866 
    6967$t->diag('find()'); 
     
    266264 
    267265$finder = new sfPropelFinder('Article'); 
    268 $t->is($finder->getPeerClass(), 'ArticlePeer', 'PeerClass can be set during instanciation, in which case the finder is automatically initialized'); 
    269 $articles = $finder->find(); 
    270 $article = $articles[0]
     266$t->is($finder->getClass(), 'Article', 'Class can be set during instanciation, in which case the finder is automatically initialized'); 
     267$article = $finder->findOne(); 
     268$t->isa_ok($article, 'Article', 'A finder instanciated directly with a class returns the correct objects')
    271269$t->is($article->getTitle(), 'foo', 'A finder instanciated directly with a class returns the correct objects'); 
    272270 
    273271$finder = new sfPropelFinder(); 
    274 $finder->setPeerClass('ArticlePeer'); 
    275 $t->is($finder->getPeerClass(), 'ArticlePeer', 'setPeerClass() and getPeerClass() are accesors to the protected $peerClass property'); 
    276 $finder->initialize(); 
    277 $articles = $finder->find(); 
    278 $article = $articles[0]; 
     272$finder->setClass('Article'); 
     273$t->is($finder->getClass(), 'Article', 'setClass() and getClass() are accesors to the protected $class property'); 
     274$article = $finder->findOne(); 
     275$t->isa_ok($article, 'Article', 'A finder instanciated directly with a class returns the correct objects'); 
    279276$t->is($article->getTitle(), 'foo', 'A finder can be instanciated without parameter, and initialized later after defining its peer class'); 
    280277 
     
    284281class ArticleFinder extends sfPropelFinder 
    285282{ 
    286   protected $peerClass = 'ArticlePeer'; 
     283  protected $class = 'Article'; 
    287284} 
    288285$finder = new ArticleFinder(); 
    289286$article = $finder->findOne(); 
    290 $t->isa_ok($article, 'Article', 'A finder extending sfPropelFinder can be used directly if defining the $peerClass property'); 
     287$t->isa_ok($article, 'Article', 'A finder extending sfPropelFinder can be used directly if defining the $class property'); 
    291288$finder = new ArticleFinder(); 
    292289$articles = $finder->find(); 
    293 $t->is(count($articles), 3, 'A finder extending sfPropelFinder can be used directly if defining the $peerClass property'); 
     290$t->is(count($articles), 3, 'A finder extending sfPropelFinder can be used directly if defining the $class property'); 
    294291 
    295292ArticlePeer::doDeleteAll();