1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-15 02:25:10 +02:00

* removed static factory DibiDriver::connect()

* added support for lazy connections
This commit is contained in:
David Grudl
2007-04-25 06:18:06 +00:00
parent 166f716091
commit af7c4de14a
9 changed files with 194 additions and 117 deletions

View File

@@ -27,6 +27,12 @@ abstract class DibiDriver
*/
protected $config;
/**
* Connection resource
* @var resource
*/
private $res;
/**
* Describes how convert some datatypes to SQL command
* @var array
@@ -39,31 +45,32 @@ abstract class DibiDriver
);
/**
* DibiDriver factory: creates object and connects to a database
*
* @param array connect configuration
* @return DibiDriver
* Creates object and (optionally) connects to a database
* @param array connect configuration
* @throw DibiException
*/
/*abstract disallowed since PHP 5.2*/ static public function connect($config) {}
/**
* Protected constructor. Must be initialized using the factory method.
* @see DibiDriver::connect()
* @param array connect configuration
*/
protected function __construct($config)
public function __construct($config)
{
$this->config = $config;
if (empty($config['lazy'])) $this->res = $this->connect();
}
/**
* Get the configuration descriptor used by connect() to connect to database.
* @see DibiDriver::connect()
* Connects to a database
* @throw DibiException
* @return resource
*/
abstract protected function connect();
/**
* Gets the configuration descriptor
* @see DibiDriver::__construct
* @return array
*/
public function getConfig()
@@ -73,6 +80,19 @@ abstract class DibiDriver
/**
* Returns the connection resource
* @return resource
*/
public function getResource()
{
if (!$this->res) $this->res = $this->connect();
return $this->res;
}
/**
* Generates and executes SQL query
*