Getting closer to being usable.
This commit is contained in:
parent
39e1baf2f6
commit
94795f8de3
17 changed files with 143 additions and 13 deletions
|
|
@ -4,7 +4,7 @@ use \⌬\Config\⌬\⌬ as App;
|
|||
use \Example\BlogApp\Example\BlogApp;
|
||||
use \Gone\AppCore\Exceptions;
|
||||
use \⌬\Controllers\Abstracts\Model as AbstractModel;
|
||||
use \Gone\AppCore\Interfaces\ModelInterface as ModelInterface;
|
||||
use ⌬\Database\Interfaces\ModelInterface as ModelInterface;
|
||||
use \Example\BlogApp\Services;
|
||||
use \Example\BlogApp\Models;
|
||||
use \Example\BlogApp\TableGateways;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use \⌬\Config\⌬\⌬ as App;
|
|||
use \Example\BlogApp\Example\BlogApp;
|
||||
use \Gone\AppCore\Exceptions;
|
||||
use \⌬\Controllers\Abstracts\Model as AbstractModel;
|
||||
use \Gone\AppCore\Interfaces\ModelInterface as ModelInterface;
|
||||
use ⌬\Database\Interfaces\ModelInterface as ModelInterface;
|
||||
use \Example\BlogApp\Services;
|
||||
use \Example\BlogApp\Models;
|
||||
use \Example\BlogApp\TableGateways;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use \⌬\Config\⌬\⌬ as App;
|
|||
use \Example\BlogApp\Example\BlogApp;
|
||||
use \Gone\AppCore\Exceptions;
|
||||
use \⌬\Controllers\Abstracts\Model as AbstractModel;
|
||||
use \Gone\AppCore\Interfaces\ModelInterface as ModelInterface;
|
||||
use ⌬\Database\Interfaces\ModelInterface as ModelInterface;
|
||||
use \Example\BlogApp\Services;
|
||||
use \Example\BlogApp\Models;
|
||||
use \Example\BlogApp\TableGateways;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
namespace Example\BlogApp\Services\Base;
|
||||
|
||||
use ⌬\Controllers\Abstracts\Service as AbstractService;
|
||||
use Gone\AppCore\Interfaces\ServiceInterface as ServiceInterface;
|
||||
use ⌬\Database\Interfaces\ServiceInterface as ServiceInterface;
|
||||
use \Example\BlogApp\TableGateways;
|
||||
use \Example\BlogApp\Models;
|
||||
use Zend\Db\ResultSet\ResultSet;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
namespace Example\BlogApp\Services\Base;
|
||||
|
||||
use ⌬\Controllers\Abstracts\Service as AbstractService;
|
||||
use Gone\AppCore\Interfaces\ServiceInterface as ServiceInterface;
|
||||
use ⌬\Database\Interfaces\ServiceInterface as ServiceInterface;
|
||||
use \Example\BlogApp\TableGateways;
|
||||
use \Example\BlogApp\Models;
|
||||
use Zend\Db\ResultSet\ResultSet;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
namespace Example\BlogApp\Services\Base;
|
||||
|
||||
use ⌬\Controllers\Abstracts\Service as AbstractService;
|
||||
use Gone\AppCore\Interfaces\ServiceInterface as ServiceInterface;
|
||||
use ⌬\Database\Interfaces\ServiceInterface as ServiceInterface;
|
||||
use \Example\BlogApp\TableGateways;
|
||||
use \Example\BlogApp\Models;
|
||||
use Zend\Db\ResultSet\ResultSet;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
namespace Example\BlogApp\TableGateways\Base;
|
||||
use \⌬\Controllers\Abstracts\TableGateway as AbstractTableGateway;
|
||||
use \⌬\Controllers\Abstracts\Model;
|
||||
use \Gone\AppCore\Db;
|
||||
use \⌬\Database\Db;
|
||||
use \Example\BlogApp\TableGateways;
|
||||
use \Example\BlogApp\Models;
|
||||
use \Zend\Db\Adapter\AdapterInterface;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
namespace Example\BlogApp\TableGateways\Base;
|
||||
use \⌬\Controllers\Abstracts\TableGateway as AbstractTableGateway;
|
||||
use \⌬\Controllers\Abstracts\Model;
|
||||
use \Gone\AppCore\Db;
|
||||
use \⌬\Database\Db;
|
||||
use \Example\BlogApp\TableGateways;
|
||||
use \Example\BlogApp\Models;
|
||||
use \Zend\Db\Adapter\AdapterInterface;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
namespace Example\BlogApp\TableGateways\Base;
|
||||
use \⌬\Controllers\Abstracts\TableGateway as AbstractTableGateway;
|
||||
use \⌬\Controllers\Abstracts\Model;
|
||||
use \Gone\AppCore\Db;
|
||||
use \⌬\Database\Db;
|
||||
use \Example\BlogApp\TableGateways;
|
||||
use \Example\BlogApp\Models;
|
||||
use \Zend\Db\Adapter\AdapterInterface;
|
||||
|
|
|
|||
73
src/Db.php
Executable file
73
src/Db.php
Executable file
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
|
||||
namespace ⌬\Database;
|
||||
|
||||
use ⌬\Database\Exception\Exception as DbException;
|
||||
use ⌬\Configuration\DatabaseConfig;
|
||||
|
||||
class Db
|
||||
{
|
||||
private static $instance;
|
||||
|
||||
/** @var Adapter[] */
|
||||
private $pool = [];
|
||||
|
||||
public function __construct(DatabaseConfig $config)
|
||||
{
|
||||
$this->pool = $config->getAdapterPool();
|
||||
}
|
||||
|
||||
public function isMySQLConfigured() : bool
|
||||
{
|
||||
return count($this->getPool()) > 0;
|
||||
}
|
||||
|
||||
public static function clean()
|
||||
{
|
||||
self::$instance = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @throws DbException
|
||||
*
|
||||
* @return Adapter
|
||||
*/
|
||||
public function getDatabase($name)
|
||||
{
|
||||
if (isset($this->pool[$name])) {
|
||||
return $this->pool[$name];
|
||||
}
|
||||
throw new DbException("No Database connected called '{$name}'.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Adapter[]
|
||||
*/
|
||||
public function getDatabases()
|
||||
{
|
||||
return $this->pool;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DbConfig $dbConfig
|
||||
*
|
||||
* @return Db
|
||||
*/
|
||||
public static function getInstance(DbConfig $dbConfig = null)
|
||||
{
|
||||
if (!self::$instance instanceof Db && $dbConfig instanceof DbConfig) {
|
||||
self::$instance = new Db($dbConfig);
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Adapter[]
|
||||
*/
|
||||
public function getPool() : array
|
||||
{
|
||||
return $this->pool;
|
||||
}
|
||||
}
|
||||
|
|
@ -13,7 +13,7 @@ $namespace = isset($argv[4]) ? $argv[4] : "Gone";
|
|||
define("APP_NAMESPACE", $namespace);
|
||||
|
||||
try {
|
||||
$databaseConfigs = $scope::Container()->get(\Gone\AppCore\DbConfig::class);
|
||||
$databaseConfigs = $scope::Container()->get(\⌬\Database\DbConfig::class);
|
||||
}catch(\Gone\AppCore\Exceptions\DbConfigException $dbConfigException){
|
||||
$databaseConfigs = null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use \{{ app_container }} as App;
|
|||
use \{{ namespace }}\{{ namespace }};
|
||||
use \Gone\AppCore\Exceptions;
|
||||
use \⌬\Controllers\Abstracts\Model as AbstractModel;
|
||||
use \Gone\AppCore\Interfaces\ModelInterface as ModelInterface;
|
||||
use ⌬\Database\Interfaces\ModelInterface as ModelInterface;
|
||||
use \{{ namespace }}\Services;
|
||||
use \{{ namespace }}\Models;
|
||||
use \{{ namespace }}\TableGateways;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
namespace {{ namespace }}\TableGateways\Base;
|
||||
use \⌬\Controllers\Abstracts\TableGateway as AbstractTableGateway;
|
||||
use \⌬\Controllers\Abstracts\Model;
|
||||
use \Gone\AppCore\Db;
|
||||
use \⌬\Database\Db;
|
||||
use \{{ namespace }}\TableGateways;
|
||||
use \{{ namespace }}\Models;
|
||||
use \Zend\Db\Adapter\AdapterInterface;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
namespace {{ namespace }}\Services\Base;
|
||||
|
||||
use ⌬\Controllers\Abstracts\Service as AbstractService;
|
||||
use Gone\AppCore\Interfaces\ServiceInterface as ServiceInterface;
|
||||
use ⌬\Database\Interfaces\ServiceInterface as ServiceInterface;
|
||||
use \{{ namespace }}\TableGateways;
|
||||
use \{{ namespace }}\Models;
|
||||
use Zend\Db\ResultSet\ResultSet;
|
||||
|
|
|
|||
15
src/Interfaces/ModelInterface.php
Executable file
15
src/Interfaces/ModelInterface.php
Executable file
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
namespace ⌬\Database\Interfaces;
|
||||
|
||||
interface ModelInterface
|
||||
{
|
||||
public static function factory();
|
||||
|
||||
public function save();
|
||||
|
||||
public function destroy();
|
||||
|
||||
public function destroyThoroughly();
|
||||
|
||||
public function getListOfProperties();
|
||||
}
|
||||
30
src/Interfaces/ServiceInterface.php
Normal file
30
src/Interfaces/ServiceInterface.php
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
namespace ⌬\Database\Interfaces;
|
||||
|
||||
use Zend\Db\Sql\Expression;
|
||||
|
||||
interface ServiceInterface
|
||||
{
|
||||
/**
|
||||
* @param int|null $limit
|
||||
* @param int|null $offset
|
||||
* @param array|null $wheres
|
||||
* @param string|Expression| null $order
|
||||
* @param string|null $orderDirection
|
||||
*
|
||||
* @return ModelInterface[]
|
||||
*/
|
||||
public function getAll(
|
||||
int $limit = null,
|
||||
int $offset = null,
|
||||
array $wheres = null,
|
||||
$order = null,
|
||||
string $orderDirection = null
|
||||
);
|
||||
|
||||
public function getById(int $id);
|
||||
|
||||
public function getByField(string $field, $value);
|
||||
|
||||
public function getRandom();
|
||||
}
|
||||
12
src/ZendSql.php
Normal file
12
src/ZendSql.php
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
namespace ⌬\Database;
|
||||
|
||||
use Zend\Db\Adapter\AdapterInterface;
|
||||
|
||||
class ZendSql extends \Zend\Db\Sql\Sql
|
||||
{
|
||||
public function __construct(AdapterInterface $adapter, $table = null, $sqlPlatform = null)
|
||||
{
|
||||
parent::__construct($adapter, $table, $sqlPlatform);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue