Skip to content

Commit

Permalink
Merge pull request #17 from skipperbent/v3-development
Browse files Browse the repository at this point in the history
Version 3.3.0
  • Loading branch information
skipperbent authored Nov 24, 2017
2 parents 460be50 + 50c7aaa commit cace42f
Show file tree
Hide file tree
Showing 21 changed files with 389 additions and 165 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"sqlite"
],
"license": "MIT",
"minimum-stability": "dev",
"minimum-stability": "stable",
"authors": [
{
"name": "Simon Sessingø",
Expand All @@ -35,7 +35,7 @@
],
"require": {
"php": ">=5.4.0",
"usmanhalalit/viocon": "1.0.*@dev"
"usmanhalalit/viocon": "1.0.1"
},
"require-dev": {
"phpunit/phpunit": "^4.8",
Expand Down
4 changes: 2 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
syntaxCheck="false">
<testsuites>
<testsuite name="Pixie Test Suite">
<directory>tests/Pixie/</directory>
<directory>tests/Pecee/Pixie/</directory>
</testsuite>
</testsuites>
</phpunit>
</phpunit>
15 changes: 11 additions & 4 deletions src/Pecee/Pixie/Connection.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
<?php

namespace Pecee\Pixie;

use Pecee\Pixie\QueryBuilder\QueryBuilderHandler;
use Viocon\Container;

/**
* Class Connection
*
* @package Pecee\Pixie
*/
class Connection
{

Expand All @@ -13,6 +19,7 @@ class Connection
protected $container;

/**
* Name of DB adapter (i.e. Mysql, Pgsql, Sqlite)
* @var string
*/
protected $adapter;
Expand All @@ -38,9 +45,9 @@ class Connection
protected $eventHandler;

/**
* @param string $adapter
* @param array $adapterConfig
* @param Container $container
* @param string $adapter
* @param array $adapterConfig
* @param Container|null $container
*/
public function __construct($adapter, array $adapterConfig, Container $container = null)
{
Expand Down Expand Up @@ -103,7 +110,7 @@ public function getPdoInstance()
}

/**
* @param $adapter
* @param string $adapter
*
* @return static
*/
Expand Down
6 changes: 6 additions & 0 deletions src/Pecee/Pixie/ConnectionAdapters/BaseAdapter.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
<?php

namespace Pecee\Pixie\ConnectionAdapters;

use Viocon\Container;

/**
* Class BaseAdapter
*
* @package Pecee\Pixie\ConnectionAdapters
*/
abstract class BaseAdapter
{
/**
Expand Down
13 changes: 13 additions & 0 deletions src/Pecee/Pixie/ConnectionAdapters/Exception.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Pecee\Pixie\ConnectionAdapters;

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

}
13 changes: 12 additions & 1 deletion src/Pecee/Pixie/ConnectionAdapters/Mysql.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
<?php

namespace Pecee\Pixie\ConnectionAdapters;

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

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

if (isset($config['host'])) {
Expand Down
13 changes: 12 additions & 1 deletion src/Pecee/Pixie/ConnectionAdapters/Pgsql.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
<?php

namespace Pecee\Pixie\ConnectionAdapters;

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

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

if (isset($config['port'])) {
Expand Down
11 changes: 11 additions & 0 deletions src/Pecee/Pixie/ConnectionAdapters/Sqlite.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
<?php

namespace Pecee\Pixie\ConnectionAdapters;

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

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

return $this->container->build(
Expand Down
31 changes: 21 additions & 10 deletions src/Pecee/Pixie/EventHandler.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
<?php

namespace Pecee\Pixie;

use Pecee\Pixie\QueryBuilder\QueryBuilderHandler;
use Pecee\Pixie\QueryBuilder\Raw;

/**
* Class EventHandler
*
* @package Pecee\Pixie
*/
class EventHandler
{
/**
Expand All @@ -25,14 +31,14 @@ public function getEvents()
}

/**
* @param $event
* @param $table
* @param string $event
* @param string|null $table
*
* @return callable|null
*/
public function getEvent($event, $table = null)
{
$table ?: ':any';
$table = $table ?: ':any';

if ($table instanceof Raw) {
return null;
Expand All @@ -54,8 +60,8 @@ public function getEvent($event, $table = null)
}

/**
* @param $event
* @param string $table
* @param string $event
* @param string $table
* @param \Closure $action
*
* @return void
Expand All @@ -68,7 +74,7 @@ public function registerEvent($event, $table, \Closure $action)
}

/**
* @param $event
* @param string $event
* @param string $table
*
* @return void
Expand All @@ -81,13 +87,18 @@ public function removeEvent($event, $table = null)

/**
* @param QueryBuilderHandler $queryBuilder
* @param $event
* @param string $event
*
* @return mixed
*/
public function fireEvents($queryBuilder, $event)
{
/**
* @var $table string
*/

$statements = $queryBuilder->getStatements();
$tables = isset($statements['tables']) ? $statements['tables'] : [];
$tables = isset($statements['tables']) ? $statements['tables'] : [];

// Events added with :any will be fired in case of any table,
// we are adding :any as a fake table at the beginning.
Expand All @@ -105,7 +116,7 @@ public function fireEvents($queryBuilder, $event)
unset($handlerParams[1]); // we do not need $event
// Add to fired list
$this->firedEvents[] = $eventId;
$result = call_user_func_array($action, $handlerParams);
$result = call_user_func_array($action, $handlerParams);
if ($result !== null) {
return $result;
}
Expand All @@ -114,4 +125,4 @@ public function fireEvents($queryBuilder, $event)

return null;
}
}
}
5 changes: 5 additions & 0 deletions src/Pecee/Pixie/Exception.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<?php
namespace Pecee\Pixie;

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

Expand Down
Loading

0 comments on commit cace42f

Please sign in to comment.