Skip to content

Commit

Permalink
Database: database extensible by row factory
Browse files Browse the repository at this point in the history
  • Loading branch information
juzna committed Oct 6, 2012
1 parent 3bd4e87 commit 10771d1
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
20 changes: 20 additions & 0 deletions Nette/Database/Connection.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class Connection extends PDO
/** @var Nette\Caching\Cache */ /** @var Nette\Caching\Cache */
private $cache; private $cache;


/** @var IRowFactory */
private $rowFactory;

/** @var array of function(Statement $result, $params); Occurs after query is executed */ /** @var array of function(Statement $result, $params); Occurs after query is executed */
public $onQuery; public $onQuery;


Expand Down Expand Up @@ -119,6 +122,23 @@ public function getCache()






public function setRowFactory(IRowFactory $rowFactory)
{
$this->rowFactory = $rowFactory;
}



/**
* @return IRowFactory
*/
public function getRowFactory()
{
return $this->rowFactory;
}



/** /**
* Generates and executes SQL query. * Generates and executes SQL query.
* @param string statement * @param string statement
Expand Down
31 changes: 31 additions & 0 deletions Nette/Database/IRowFactory.php
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/**
* This file is part of the Nette Framework (http://nette.org)
*
* Copyright (c) 2004 David Grudl (http://davidgrudl.com)
*
* For the full copyright and license information, please view
* the file license.txt that was distributed with this source code.
*/

namespace Nette\Database;

use Nette;



/**
* Information about tables and columns structure.
*/
interface IRowFactory
{
/**
* Create new entity
*
* @param array
* @param Table\Selection
* @return mixed
*/
function createRow(array $data, Table\Selection $table);
}
7 changes: 6 additions & 1 deletion Nette/Database/Table/Selection.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -493,7 +493,12 @@ protected function execute()


protected function createRow(array $row) protected function createRow(array $row)
{ {
return new ActiveRow($row, $this); if ($factory = $this->connection->getRowFactory()) {
return $factory->createRow($row, $this);

} else {
return new ActiveRow($row, $this);
}
} }




Expand Down

0 comments on commit 10771d1

Please sign in to comment.