Skip to content

Commit

Permalink
added ISupplementalDriver::initialize(), is used instead of construct…
Browse files Browse the repository at this point in the history
…or (BC break!)
  • Loading branch information
dg committed Jan 25, 2017
1 parent 230b081 commit b4c5cd1
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/Database/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ public function connect()
$class = empty($this->options['driverClass'])
? 'Nette\Database\Drivers\\' . ucfirst(str_replace('sql', 'Sql', $this->pdo->getAttribute(PDO::ATTR_DRIVER_NAME))) . 'Driver'
: $this->options['driverClass'];
$this->driver = new $class($this, $this->options);
$this->driver = new $class;
$this->driver->initialize($this, $this->options);
$this->preprocessor = new SqlPreprocessor($this);
$this->onConnect($this);
}
Expand Down
5 changes: 5 additions & 0 deletions src/Database/Drivers/MsSqlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ class MsSqlDriver implements Nette\Database\ISupplementalDriver
{
use Nette\SmartObject;

public function initialize(Nette\Database\Connection $connection, array $options)
{
}


public function convertException(\PDOException $e)
{
return Nette\Database\DriverException::from($e);
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Drivers/MySqlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class MySqlDriver implements Nette\Database\ISupplementalDriver
* - charset => character encoding to set (default is utf8 or utf8mb4 since MySQL 5.5.3)
* - sqlmode => see http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html
*/
public function __construct(Nette\Database\Connection $connection, array $options)
public function initialize(Nette\Database\Connection $connection, array $options)
{
$this->connection = $connection;
$charset = $options['charset']
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Drivers/OciDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class OciDriver implements Nette\Database\ISupplementalDriver
private $fmtDateTime;


public function __construct(Nette\Database\Connection $connection, array $options)
public function initialize(Nette\Database\Connection $connection, array $options)
{
$this->connection = $connection;
$this->fmtDateTime = $options['formatDateTime'] ?? 'U';
Expand Down
5 changes: 5 additions & 0 deletions src/Database/Drivers/OdbcDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ class OdbcDriver implements Nette\Database\ISupplementalDriver
{
use Nette\SmartObject;

public function initialize(Nette\Database\Connection $connection, array $options)
{
}


public function convertException(\PDOException $e)
{
return Nette\Database\DriverException::from($e);
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Drivers/PgSqlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class PgSqlDriver implements Nette\Database\ISupplementalDriver
private $connection;


public function __construct(Nette\Database\Connection $connection, array $options)
public function initialize(Nette\Database\Connection $connection, array $options)
{
$this->connection = $connection;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Drivers/SqliteDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class SqliteDriver implements Nette\Database\ISupplementalDriver
private $fmtDateTime;


public function __construct(Nette\Database\Connection $connection, array $options)
public function initialize(Nette\Database\Connection $connection, array $options)
{
$this->connection = $connection;
$this->fmtDateTime = $options['formatDateTime'] ?? 'U';
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Drivers/SqlsrvDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class SqlsrvDriver implements Nette\Database\ISupplementalDriver
private $version;


public function __construct(Nette\Database\Connection $connection, array $options)
public function initialize(Nette\Database\Connection $connection, array $options)
{
$this->connection = $connection;
$this->version = $connection->getPdo()->getAttribute(\PDO::ATTR_SERVER_VERSION);
Expand Down
6 changes: 6 additions & 0 deletions src/Database/ISupplementalDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ interface ISupplementalDriver
SUPPORT_SUBSELECT = 'subselect',
SUPPORT_SCHEMA = 'schema';

/**
* Initializes connection.
* @return void
*/
function initialize(Connection $connection, array $options);

/**
* @return DriverException
*/
Expand Down

0 comments on commit b4c5cd1

Please sign in to comment.