Skip to content

Commit

Permalink
Merge pull request #52 from skipperbent/v3-development
Browse files Browse the repository at this point in the history
Version 3.6.0
  • Loading branch information
skipperbent authored Jan 16, 2018
2 parents 8ca1468 + 864c9fb commit e139d0b
Show file tree
Hide file tree
Showing 9 changed files with 262 additions and 190 deletions.
2 changes: 1 addition & 1 deletion src/Pecee/Pixie/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function __construct($adapter, array $adapterConfig)
* Returns an instance of Query Builder
*
* @return QueryBuilderHandler
* @throws Exception
* @throws \Pecee\Pixie\Exception
*/
public function getQueryBuilder()
{
Expand Down
12 changes: 0 additions & 12 deletions src/Pecee/Pixie/ConnectionAdapters/Exception.php

This file was deleted.

86 changes: 48 additions & 38 deletions src/Pecee/Pixie/ConnectionAdapters/Mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,58 @@
namespace Pecee\Pixie\ConnectionAdapters;

use PDO;
use Pecee\Pixie\Exception;

/**
* Class Mysql
*
* @package Pecee\Pixie\ConnectionAdapters
*/
class Mysql extends BaseAdapter {
/**
* @param array $config
*
* @return PDO
* @throws Exception
*/
protected function doConnect(array $config) {
if (extension_loaded('pdo_mysql') === false) {
throw new Exception(sprintf('%s library not loaded', 'pdo_mysql'));
}

$connectionString = "mysql:dbname={$config['database']}";

if (isset($config['host']) === true) {
$connectionString .= ";host={$config['host']}";
}

if (isset($config['port']) === true) {
$connectionString .= ";port={$config['port']}";
}

if (isset($config['unix_socket']) === true) {
$connectionString .= ";unix_socket={$config['unix_socket']}";
}

$connection = new PDO($connectionString, $config['username'], $config['password'], $config['options']);

if (isset($config['charset']) === true) {
$connection->prepare("SET NAMES '{$config['charset']}'")->execute();
}

return $connection;
}

public function getQueryAdapterClass() {
return \Pecee\Pixie\QueryBuilder\Adapters\Mysql::class;
}
class Mysql extends BaseAdapter
{
/**
* @param array $config
*
* @return PDO
* @throws Exception
*/
protected function doConnect(array $config)
{
if (extension_loaded('pdo_mysql') === false) {
throw new Exception(sprintf('%s library not loaded', 'pdo_mysql'));
}

$connectionString = "mysql:dbname={$config['database']}";

if (isset($config['host']) === true) {
$connectionString .= ";host={$config['host']}";
}

if (isset($config['port']) === true) {
$connectionString .= ";port={$config['port']}";
}

if (isset($config['unix_socket']) === true) {
$connectionString .= ";unix_socket={$config['unix_socket']}";
}

try {

$connection = new PDO($connectionString, $config['username'], $config['password'], $config['options']);

if (isset($config['charset']) === true) {
$connection->prepare("SET NAMES '{$config['charset']}'")->execute();
}

} catch (\PDOException $e) {
throw new Exception($e->getMessage(), $e->getCode());
}

return $connection;
}

public function getQueryAdapterClass()
{
return \Pecee\Pixie\QueryBuilder\Adapters\Mysql::class;
}
}
84 changes: 47 additions & 37 deletions src/Pecee/Pixie/ConnectionAdapters/Pgsql.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,58 @@
namespace Pecee\Pixie\ConnectionAdapters;

use PDO;
use Pecee\Pixie\Exception;

/**
* Class Pgsql
*
* @package Pecee\Pixie\ConnectionAdapters
*/
class Pgsql extends BaseAdapter {
/**
* @param array $config
*
* @return PDO
* @throws Exception
*/
protected function doConnect(array $config) {
if (extension_loaded('pdo_pgsql') === false) {
throw new Exception(sprintf('%s library not loaded', 'pdo_pgsql'));
}

$connectionString = "pgsql:host={$config['host']};dbname={$config['database']}";

if (isset($config['port']) === true) {
$connectionString .= ";port={$config['port']}";
}

/**
* @var \PDO $connection
*/
$connection = new PDO($connectionString, $config['username'], $config['password'], $config['options']);

if (isset($config['charset']) === true) {
$connection->prepare("SET NAMES '{$config['charset']}'")->execute();
}

if (isset($config['schema']) === true) {
$connection->prepare("SET search_path TO '{$config['schema']}'")->execute();
}

return $connection;
}

public function getQueryAdapterClass() {
return \Pecee\Pixie\QueryBuilder\Adapters\Pgsql::class;
}
class Pgsql extends BaseAdapter
{
/**
* @param array $config
*
* @return PDO
* @throws Exception
*/
protected function doConnect(array $config)
{
if (extension_loaded('pdo_pgsql') === false) {
throw new Exception(sprintf('%s library not loaded', 'pdo_pgsql'));
}

$connectionString = "pgsql:host={$config['host']};dbname={$config['database']}";

if (isset($config['port']) === true) {
$connectionString .= ";port={$config['port']}";
}

try {

/**
* @var \PDO $connection
*/
$connection = new PDO($connectionString, $config['username'], $config['password'], $config['options']);

if (isset($config['charset']) === true) {
$connection->prepare("SET NAMES '{$config['charset']}'")->execute();
}

if (isset($config['schema']) === true) {
$connection->prepare("SET search_path TO '{$config['schema']}'")->execute();
}

} catch (\PDOException $e) {
throw new Exception($e->getMessage(), $e->getCode());
}

return $connection;
}

public function getQueryAdapterClass()
{
return \Pecee\Pixie\QueryBuilder\Adapters\Pgsql::class;
}

}
42 changes: 25 additions & 17 deletions src/Pecee/Pixie/ConnectionAdapters/Sqlite.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,39 @@
namespace Pecee\Pixie\ConnectionAdapters;

use PDO;
use Pecee\Pixie\Exception;

/**
* Class Sqlite
*
* @package Pecee\Pixie\ConnectionAdapters
*/
class Sqlite extends BaseAdapter {
/**
* @param array $config
*
* @return PDO
* @throws Exception
*/
public function doConnect(array $config) {
if (extension_loaded('pdo_sqlite') === false) {
throw new Exception(sprintf('%s library not loaded', 'pdo_sqlite'));
}
class Sqlite extends BaseAdapter
{
/**
* @param array $config
*
* @return PDO
* @throws \Pecee\Pixie\Exception
*/
public function doConnect(array $config)
{
if (extension_loaded('pdo_sqlite') === false) {
throw new Exception(sprintf('%s library not loaded', 'pdo_sqlite'));
}

$connectionString = 'sqlite:' . $config['database'];
$connectionString = 'sqlite:' . $config['database'];

return new PDO($connectionString, null, null, $config['options']);
}
try {
return new PDO($connectionString, null, null, $config['options']);
} catch (\PDOException $e) {
throw new Exception($e->getMessage(), $e->getCode());
}
}

public function getQueryAdapterClass() {
return \Pecee\Pixie\QueryBuilder\Adapters\Sqlite::class;
}
public function getQueryAdapterClass()
{
return \Pecee\Pixie\QueryBuilder\Adapters\Sqlite::class;
}

}
23 changes: 22 additions & 1 deletion src/Pecee/Pixie/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,32 @@

namespace Pecee\Pixie;

use Pecee\Pixie\QueryBuilder\QueryObject;

/**
* Class Exception
*
* @package Pecee\Pixie
*/
class Exception extends \Exception {
class Exception extends \Exception
{

protected $query;

public function __construct(string $message = '', int $code = 0, QueryObject $query = null)
{
parent::__construct($message, $code);
$this->query = $query;
}

/**
* Get query-object
*
* @return QueryObject
*/
public function getQuery()
{
return $this->query;
}

}
Loading

0 comments on commit e139d0b

Please sign in to comment.