From a3c38a27c70c71b521f65370ec87c34d10eaa3ac Mon Sep 17 00:00:00 2001 From: Michal Sieciechowicz Date: Mon, 1 Mar 2021 16:06:02 +0100 Subject: [PATCH 01/18] fixes --- app/Model/Job.php | 17 +++++++---------- app/Query/IJobQuery.php | 2 +- app/Query/JobQuery.php | 4 ++-- composer.json | 5 +++-- src/Fufle/ORM/Model.php | 33 +++++++++++++++++++-------------- src/Fufle/ORM/Query.php | 6 ++++-- tests/ModelTests.php | 12 ++++++------ 7 files changed, 42 insertions(+), 37 deletions(-) diff --git a/app/Model/Job.php b/app/Model/Job.php index 911d4b7..391ffc3 100644 --- a/app/Model/Job.php +++ b/app/Model/Job.php @@ -1,22 +1,19 @@ GetLast10()); + return self::QueryAll(self::QueryModel()->GetLast10()); } } \ No newline at end of file diff --git a/app/Query/IJobQuery.php b/app/Query/IJobQuery.php index ea0fb0b..6b44286 100644 --- a/app/Query/IJobQuery.php +++ b/app/Query/IJobQuery.php @@ -1,6 +1,6 @@ Get(), + static::QueryModel()->Get(), [$id]); } - + protected static function Query(string $sql, array|object $params = []) { - self::Check(); return ConnectionManager::Query( $sql, $params, get_called_class()); } - + protected static function QueryAll(string $sql, array|object $params = []) { - self::Check(); return ConnectionManager::QueryAll( $sql, $params, @@ -46,6 +53,4 @@ abstract class Model { } static::Initialize(); } - - abstract public static function Initialize(); } \ No newline at end of file diff --git a/src/Fufle/ORM/Query.php b/src/Fufle/ORM/Query.php index 2052a56..a920ebb 100644 --- a/src/Fufle/ORM/Query.php +++ b/src/Fufle/ORM/Query.php @@ -4,10 +4,12 @@ namespace Fufle\ORM; class Query { private string $table; private string $primaryKey; + public function __construct(string $model) { - $this->table = $model::getTableName(); - $this->primaryKey = $model::getPrimaryKey(); + $this->table = $model::GetTableName(); + $this->primaryKey = $model::GetPrimaryKey(); } + public function Get(): string { return 'SELECT * FROM '.$this->table.' WHERE '.$this->primaryKey.' = ?'; } diff --git a/tests/ModelTests.php b/tests/ModelTests.php index 7510169..962e72a 100644 --- a/tests/ModelTests.php +++ b/tests/ModelTests.php @@ -1,19 +1,19 @@ Date: Mon, 1 Mar 2021 16:22:54 +0100 Subject: [PATCH 02/18] fix --- src/Fufle/ORM/Query.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Fufle/ORM/Query.php b/src/Fufle/ORM/Query.php index a920ebb..a499557 100644 --- a/src/Fufle/ORM/Query.php +++ b/src/Fufle/ORM/Query.php @@ -2,8 +2,8 @@ namespace Fufle\ORM; class Query { - private string $table; - private string $primaryKey; + protected string $table; + protected string $primaryKey; public function __construct(string $model) { $this->table = $model::GetTableName(); -- 2.39.5 From a3d8bb6131000cf1f8f6a2db51372bf51c9422d1 Mon Sep 17 00:00:00 2001 From: Michal Sieciechowicz Date: Mon, 1 Mar 2021 16:25:31 +0100 Subject: [PATCH 03/18] fixes --- src/Fufle/ORM/Model.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/Fufle/ORM/Model.php b/src/Fufle/ORM/Model.php index 7418b7a..f9c67ca 100644 --- a/src/Fufle/ORM/Model.php +++ b/src/Fufle/ORM/Model.php @@ -46,11 +46,4 @@ abstract class Model { $params, get_called_class()); } - - public static function Check() { - if (static::$table === null) { - static::$table = basename(str_replace('\\', '/', get_called_class())) . 's'; - } - static::Initialize(); - } } \ No newline at end of file -- 2.39.5 From 9204f70e505baf3f89738f0e00ee00b5371db7f5 Mon Sep 17 00:00:00 2001 From: Michal Sieciechowicz Date: Wed, 3 Mar 2021 13:41:02 +0100 Subject: [PATCH 04/18] 0.2.2 --- app/Model/Job.php | 2 +- src/Fufle/Database/ConnectionManager.php | 13 +++++++---- src/Fufle/Database/QueryData.php | 29 ++++++++++++++++++++++++ src/Fufle/ORM/Model.php | 13 +++++++++++ 4 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 src/Fufle/Database/QueryData.php diff --git a/app/Model/Job.php b/app/Model/Job.php index 391ffc3..b1bf6e6 100644 --- a/app/Model/Job.php +++ b/app/Model/Job.php @@ -16,4 +16,4 @@ class Job extends BaseModel { public static function GetLast10() { return self::QueryAll(self::QueryModel()->GetLast10()); } -} \ No newline at end of file +} diff --git a/src/Fufle/Database/ConnectionManager.php b/src/Fufle/Database/ConnectionManager.php index 3731217..d1e4ecb 100644 --- a/src/Fufle/Database/ConnectionManager.php +++ b/src/Fufle/Database/ConnectionManager.php @@ -3,6 +3,7 @@ namespace Fufle\Database; use PDO; +use Fufle\Database\QueryData; class ConnectionManager { private static $connection; @@ -12,15 +13,19 @@ class ConnectionManager { } public static function Query(string $query, array|object $params = [], string $output = 'stdObject') { - $stmt = self::$connection->prepare($query); - $stmt->execute($params); + $data = new QueryData($query, $params); + $data->normalize(); + $stmt = self::$connection->prepare($data->query); + $stmt->execute($data->params); $stmt->setFetchMode(PDO::FETCH_CLASS, $output); return $stmt->fetch(); } public static function QueryAll(string $query, array|object $params = [], string $output = 'stdObject') { - $stmt = self::$connection->prepare($query); - $stmt->execute($params); + $data = new QueryData($query, $params); + $data->normalize(); + $stmt = self::$connection->prepare($data->query); + $stmt->execute($data->params); $stmt->setFetchMode(PDO::FETCH_CLASS, $output); return $stmt->fetchAll(); } diff --git a/src/Fufle/Database/QueryData.php b/src/Fufle/Database/QueryData.php new file mode 100644 index 0000000..3c96740 --- /dev/null +++ b/src/Fufle/Database/QueryData.php @@ -0,0 +1,29 @@ +params; + $replaces = []; + foreach($params as $name => $param) { + if (is_array($param)) { + $replaces2 = []; + foreach($param as $i => $p) { + $params[$name.$i.'x'] = $p; + $replaces[] = ':'.$name.$i.'x'; + } + unset($params[$name]); + $this->query = str_replace(':'.$name, implode(', ', $replaces), $this->query); + } + } + $this->params = $params; + } +} \ No newline at end of file diff --git a/src/Fufle/ORM/Model.php b/src/Fufle/ORM/Model.php index f9c67ca..12200d3 100644 --- a/src/Fufle/ORM/Model.php +++ b/src/Fufle/ORM/Model.php @@ -9,6 +9,19 @@ abstract class Model { protected static ?string $table = null; private static ?IQuery $query = null; + protected static array $fields = []; + + public function toArray(): array { + $array = []; + $fields = static::$fields; + foreach($fields as $field) { + if ($this->{$field} ?? null !== null) { + $array[$field] = $this->{$field}; + } + } + return $array; + } + protected static function QueryModel() { if (self::$query === null && self::class !== static::class) { self::$query = static::QueryModel(); -- 2.39.5 From 54113fffc086a6571e661a508070245f6c8191a2 Mon Sep 17 00:00:00 2001 From: Dariusz Date: Sun, 7 Mar 2021 01:15:16 +0100 Subject: [PATCH 05/18] connectors --- app/Model/Job.php | 2 +- app/Query/JobQuery.php | 2 +- src/Fufle/Database/ConnectionManager.php | 32 ------------ src/Fufle/Database/Connector/IConnector.php | 0 .../Database/Connector/PostgresConnector.php | 0 src/Fufle/ORM/Database/ConnectionManager.php | 52 +++++++++++++++++++ .../ORM/Database/Connector/IConnector.php | 9 ++++ .../Database/Connector/PostgresConnector.php | 11 ++++ src/Fufle/ORM/Database/Credentials.php | 15 ++++++ src/Fufle/{ => ORM}/Database/QueryData.php | 2 +- src/Fufle/ORM/Model.php | 4 +- src/Fufle/ORM/Query.php | 2 +- tests/ModelTests.php | 13 ++++- 13 files changed, 105 insertions(+), 39 deletions(-) delete mode 100644 src/Fufle/Database/ConnectionManager.php delete mode 100644 src/Fufle/Database/Connector/IConnector.php delete mode 100644 src/Fufle/Database/Connector/PostgresConnector.php create mode 100644 src/Fufle/ORM/Database/ConnectionManager.php create mode 100644 src/Fufle/ORM/Database/Connector/IConnector.php create mode 100644 src/Fufle/ORM/Database/Connector/PostgresConnector.php create mode 100644 src/Fufle/ORM/Database/Credentials.php rename src/Fufle/{ => ORM}/Database/QueryData.php (95%) diff --git a/app/Model/Job.php b/app/Model/Job.php index b1bf6e6..27e0a4e 100644 --- a/app/Model/Job.php +++ b/app/Model/Job.php @@ -9,7 +9,7 @@ use Fufle\ORM\Model as BaseModel; class Job extends BaseModel { public int $id; public float $budget; - public static function QueryModel() { + public static function SetQueryModel() { return new JobQuery( static::class ); } diff --git a/app/Query/JobQuery.php b/app/Query/JobQuery.php index 8f064e9..9f9df4c 100644 --- a/app/Query/JobQuery.php +++ b/app/Query/JobQuery.php @@ -7,6 +7,6 @@ use Fufle\ORM\Query as BaseQuery; class JobQuery extends BaseQuery implements IJobQuery { public function GetLast10(): string { - return "select * from jobs order by id desc limit 10"; + return "SELECT * from jobs order by id desc limit 10"; } } diff --git a/src/Fufle/Database/ConnectionManager.php b/src/Fufle/Database/ConnectionManager.php deleted file mode 100644 index d1e4ecb..0000000 --- a/src/Fufle/Database/ConnectionManager.php +++ /dev/null @@ -1,32 +0,0 @@ -normalize(); - $stmt = self::$connection->prepare($data->query); - $stmt->execute($data->params); - $stmt->setFetchMode(PDO::FETCH_CLASS, $output); - return $stmt->fetch(); - } - - public static function QueryAll(string $query, array|object $params = [], string $output = 'stdObject') { - $data = new QueryData($query, $params); - $data->normalize(); - $stmt = self::$connection->prepare($data->query); - $stmt->execute($data->params); - $stmt->setFetchMode(PDO::FETCH_CLASS, $output); - return $stmt->fetchAll(); - } -} \ No newline at end of file diff --git a/src/Fufle/Database/Connector/IConnector.php b/src/Fufle/Database/Connector/IConnector.php deleted file mode 100644 index e69de29..0000000 diff --git a/src/Fufle/Database/Connector/PostgresConnector.php b/src/Fufle/Database/Connector/PostgresConnector.php deleted file mode 100644 index e69de29..0000000 diff --git a/src/Fufle/ORM/Database/ConnectionManager.php b/src/Fufle/ORM/Database/ConnectionManager.php new file mode 100644 index 0000000..54935ef --- /dev/null +++ b/src/Fufle/ORM/Database/ConnectionManager.php @@ -0,0 +1,52 @@ +driverEquals($driver)) { + $credentials = new Credentials($host, $port, $database, $user, $password); + self::$connectionString = $c->getConnectionString($credentials); + self::ConnectWithString(self::$connectionString); + return; + } + } + throw new Exception('Driver not found'); + } + + public static function ConnectWithString(string $connectionString) { + self::$connection = new PDO($connectionString); + } + + public static function Query(string $query, array|object $params = [], string $output = 'stdObject') { + $data = new QueryData($query, $params); + $data->normalize(); + $stmt = self::$connection->prepare($data->query); + $stmt->execute($data->params); + $stmt->setFetchMode(PDO::FETCH_CLASS, $output); + return $stmt->fetch(); + } + + public static function QueryAll(string $query, array|object $params = [], string $output = 'stdObject') { + $data = new QueryData($query, $params); + $data->normalize(); + $stmt = self::$connection->prepare($data->query); + $stmt->execute($data->params); + $stmt->setFetchMode(PDO::FETCH_CLASS, $output); + return $stmt->fetchAll(); + } +} \ No newline at end of file diff --git a/src/Fufle/ORM/Database/Connector/IConnector.php b/src/Fufle/ORM/Database/Connector/IConnector.php new file mode 100644 index 0000000..0fac25d --- /dev/null +++ b/src/Fufle/ORM/Database/Connector/IConnector.php @@ -0,0 +1,9 @@ + Date: Sun, 7 Mar 2021 01:49:33 +0100 Subject: [PATCH 06/18] rename --- composer.json | 4 ++-- {app => demo}/Model/Job.php | 0 {app => demo}/Query/IJobQuery.php | 0 {app => demo}/Query/JobQuery.php | 0 4 files changed, 2 insertions(+), 2 deletions(-) rename {app => demo}/Model/Job.php (100%) rename {app => demo}/Query/IJobQuery.php (100%) rename {app => demo}/Query/JobQuery.php (100%) diff --git a/composer.json b/composer.json index 5d26955..64a22b3 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "fufle/sibase2", + "name": "fufle/micro-orm", "description": "MicroORM for php8", "type": "orm", "require": { @@ -17,7 +17,7 @@ "autoload": { "psr-4": { "Fufle\\": "src/Fufle/", - "Fufle\\Demo\\": "app/" + "Fufle\\Demo\\": "demo/" } } } diff --git a/app/Model/Job.php b/demo/Model/Job.php similarity index 100% rename from app/Model/Job.php rename to demo/Model/Job.php diff --git a/app/Query/IJobQuery.php b/demo/Query/IJobQuery.php similarity index 100% rename from app/Query/IJobQuery.php rename to demo/Query/IJobQuery.php diff --git a/app/Query/JobQuery.php b/demo/Query/JobQuery.php similarity index 100% rename from app/Query/JobQuery.php rename to demo/Query/JobQuery.php -- 2.39.5 From d9da5559c535581385e0cec256a579f09b722422 Mon Sep 17 00:00:00 2001 From: Dariusz Date: Sun, 7 Mar 2021 01:53:29 +0100 Subject: [PATCH 07/18] NS --- tests/ModelTests.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ModelTests.php b/tests/ModelTests.php index 5feebdf..9fb0622 100644 --- a/tests/ModelTests.php +++ b/tests/ModelTests.php @@ -2,7 +2,7 @@ require_once __DIR__ . '/../vendor/autoload.php'; use Fufle\Demo\Model\Job; -use Fufle\Database\ConnectionManager; +use Fufle\ORM\Database\ConnectionManager; //$dns = 'pgsql:host=localhost;port=5432;dbname=dynamic;user=dynamic;password=password123'; $params = [ -- 2.39.5 From d32c7a0b928f5da1239349090cd8ff9d55470aa0 Mon Sep 17 00:00:00 2001 From: Dariusz Date: Sun, 7 Mar 2021 09:39:13 +0100 Subject: [PATCH 08/18] use --- tests/ModelTests.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/ModelTests.php b/tests/ModelTests.php index 9fb0622..2456249 100644 --- a/tests/ModelTests.php +++ b/tests/ModelTests.php @@ -3,6 +3,7 @@ require_once __DIR__ . '/../vendor/autoload.php'; use Fufle\Demo\Model\Job; use Fufle\ORM\Database\ConnectionManager; +use Fufle\ORM\Database\Connectors\PostgresConnector; //$dns = 'pgsql:host=localhost;port=5432;dbname=dynamic;user=dynamic;password=password123'; $params = [ -- 2.39.5 From 3c436125030d3aea0a0ee87e7e411de0171357c7 Mon Sep 17 00:00:00 2001 From: Dariusz Date: Sun, 7 Mar 2021 09:52:45 +0100 Subject: [PATCH 09/18] rename --- src/Fufle/ORM/Database/{Connector => Connectors}/IConnector.php | 0 .../ORM/Database/{Connector => Connectors}/PostgresConnector.php | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/Fufle/ORM/Database/{Connector => Connectors}/IConnector.php (100%) rename src/Fufle/ORM/Database/{Connector => Connectors}/PostgresConnector.php (100%) diff --git a/src/Fufle/ORM/Database/Connector/IConnector.php b/src/Fufle/ORM/Database/Connectors/IConnector.php similarity index 100% rename from src/Fufle/ORM/Database/Connector/IConnector.php rename to src/Fufle/ORM/Database/Connectors/IConnector.php diff --git a/src/Fufle/ORM/Database/Connector/PostgresConnector.php b/src/Fufle/ORM/Database/Connectors/PostgresConnector.php similarity index 100% rename from src/Fufle/ORM/Database/Connector/PostgresConnector.php rename to src/Fufle/ORM/Database/Connectors/PostgresConnector.php -- 2.39.5 From a026facb7cb72a6d21f05ac79afc4e304278e163 Mon Sep 17 00:00:00 2001 From: Dariusz Date: Sun, 7 Mar 2021 09:55:06 +0100 Subject: [PATCH 10/18] iface --- src/Fufle/ORM/Database/Connectors/IConnector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Fufle/ORM/Database/Connectors/IConnector.php b/src/Fufle/ORM/Database/Connectors/IConnector.php index 0fac25d..c382824 100644 --- a/src/Fufle/ORM/Database/Connectors/IConnector.php +++ b/src/Fufle/ORM/Database/Connectors/IConnector.php @@ -4,6 +4,6 @@ namespace Fufle\ORM\Database\Connectors; use Fufle\ORM\Database\Credentials; -class IConnector { +interface IConnector { public function getConnectionString(Credentials $credentials); } \ No newline at end of file -- 2.39.5 From 9c6c34f8709236f6615965d325c1b0a965a6e8ae Mon Sep 17 00:00:00 2001 From: Dariusz Date: Sun, 7 Mar 2021 10:54:11 +0100 Subject: [PATCH 11/18] eq --- src/Fufle/ORM/Database/Connectors/IConnector.php | 1 + src/Fufle/ORM/Database/Connectors/PostgresConnector.php | 3 +++ 2 files changed, 4 insertions(+) diff --git a/src/Fufle/ORM/Database/Connectors/IConnector.php b/src/Fufle/ORM/Database/Connectors/IConnector.php index c382824..1b63255 100644 --- a/src/Fufle/ORM/Database/Connectors/IConnector.php +++ b/src/Fufle/ORM/Database/Connectors/IConnector.php @@ -6,4 +6,5 @@ use Fufle\ORM\Database\Credentials; interface IConnector { public function getConnectionString(Credentials $credentials); + public function driverEquals(string $driver); } \ No newline at end of file diff --git a/src/Fufle/ORM/Database/Connectors/PostgresConnector.php b/src/Fufle/ORM/Database/Connectors/PostgresConnector.php index a42dec9..db72b9b 100644 --- a/src/Fufle/ORM/Database/Connectors/PostgresConnector.php +++ b/src/Fufle/ORM/Database/Connectors/PostgresConnector.php @@ -8,4 +8,7 @@ class PostgresConnector implements IConnector { public function getConnectionString(Credentials $credentials) { return ""; } + public function driverEquals(string $driver) { + return $driver === 'pgsql'; + } } \ No newline at end of file -- 2.39.5 From 661406db67d4d34357de70b142f3de9813e2049f Mon Sep 17 00:00:00 2001 From: Dariusz Date: Sun, 7 Mar 2021 10:55:23 +0100 Subject: [PATCH 12/18] nullsafe --- src/Fufle/ORM/Database/Credentials.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Fufle/ORM/Database/Credentials.php b/src/Fufle/ORM/Database/Credentials.php index fbdb52b..47493ac 100644 --- a/src/Fufle/ORM/Database/Credentials.php +++ b/src/Fufle/ORM/Database/Credentials.php @@ -6,10 +6,10 @@ class Credentials { public function __construct( public string $host, - public int $port = null, - public string $database = null, - public string $user = null, - public string $password = null) { + public ?int $port = null, + public ?string $database = null, + public ?string $user = null, + public ?string $password = null) { } } \ No newline at end of file -- 2.39.5 From 3f9758c4032bd78628d60ab26d3ca0c7dcd23398 Mon Sep 17 00:00:00 2001 From: Dariusz Date: Sun, 7 Mar 2021 11:06:39 +0100 Subject: [PATCH 13/18] fdn --- src/Fufle/ORM/Database/Connectors/PostgresConnector.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Fufle/ORM/Database/Connectors/PostgresConnector.php b/src/Fufle/ORM/Database/Connectors/PostgresConnector.php index db72b9b..fec017f 100644 --- a/src/Fufle/ORM/Database/Connectors/PostgresConnector.php +++ b/src/Fufle/ORM/Database/Connectors/PostgresConnector.php @@ -5,8 +5,8 @@ namespace Fufle\ORM\Database\Connectors; use Fufle\ORM\Database\Credentials; class PostgresConnector implements IConnector { - public function getConnectionString(Credentials $credentials) { - return ""; + public function getConnectionString(Credentials $c) { + return "pgsql:host={$c->host};port={$c->port};dbname={$c->database};user={$c->user};password={$c->password}"; } public function driverEquals(string $driver) { return $driver === 'pgsql'; -- 2.39.5 From b9d1d1601a2e83974137258ae502193013debc11 Mon Sep 17 00:00:00 2001 From: Dariusz Date: Sun, 7 Mar 2021 11:12:43 +0100 Subject: [PATCH 14/18] d --- tests/ModelTests.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ModelTests.php b/tests/ModelTests.php index 2456249..cbee908 100644 --- a/tests/ModelTests.php +++ b/tests/ModelTests.php @@ -12,7 +12,7 @@ $params = [ 5432, 'dynamic_dev', 'dynamic', - 'password123', + 'Pass@Dyna21', ]; ConnectionManager::RegisterConnector(new PostgresConnector()); ConnectionManager::Connect(...$params); -- 2.39.5 From 1c886fb38505814bb39d890adefc4d4598e0ccfe Mon Sep 17 00:00:00 2001 From: Dariusz Date: Sun, 7 Mar 2021 11:17:21 +0100 Subject: [PATCH 15/18] model --- demo/Model/Job.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/demo/Model/Job.php b/demo/Model/Job.php index 27e0a4e..f3cb9ca 100644 --- a/demo/Model/Job.php +++ b/demo/Model/Job.php @@ -5,11 +5,12 @@ namespace Fufle\Demo\Model; use Fufle\Demo\Query\IJobQuery; use Fufle\Demo\Query\JobQuery; use Fufle\ORM\Model as BaseModel; +use Fufle\ORM\IQuery; class Job extends BaseModel { public int $id; public float $budget; - public static function SetQueryModel() { + public static function SetQueryModel(): IQuery { return new JobQuery( static::class ); } -- 2.39.5 From 1920374639c5566f46368d00c38764fd905cb43f Mon Sep 17 00:00:00 2001 From: Dariusz Date: Sun, 7 Mar 2021 11:20:52 +0100 Subject: [PATCH 16/18] ns --- src/Fufle/ORM/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Fufle/ORM/Model.php b/src/Fufle/ORM/Model.php index f99500c..1698375 100644 --- a/src/Fufle/ORM/Model.php +++ b/src/Fufle/ORM/Model.php @@ -2,7 +2,7 @@ namespace Fufle\ORM; -use Fufle\Database\ConnectionManager; +use Fufle\ORM\Database\ConnectionManager; abstract class Model { protected static string $primaryKey = 'id'; -- 2.39.5 From fbf2aaae0737b239333e8bd31900c168e839e80d Mon Sep 17 00:00:00 2001 From: Dariusz Date: Sun, 7 Mar 2021 11:30:13 +0100 Subject: [PATCH 17/18] 0.2.3 --- src/Fufle/ORM/Database/Connectors/PostgresConnector.php | 5 +++++ tests/ModelTests.php | 9 +++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Fufle/ORM/Database/Connectors/PostgresConnector.php b/src/Fufle/ORM/Database/Connectors/PostgresConnector.php index fec017f..046be98 100644 --- a/src/Fufle/ORM/Database/Connectors/PostgresConnector.php +++ b/src/Fufle/ORM/Database/Connectors/PostgresConnector.php @@ -11,4 +11,9 @@ class PostgresConnector implements IConnector { public function driverEquals(string $driver) { return $driver === 'pgsql'; } + + public static function Connect(string $host, int $port, string $database, string $user, string $password) { + ConnectionManager::RegisterConnector(new PostgresConnector()); + ConnectionManager::Connect('pgsql', $host, $port, $database, $user, $password); + } } \ No newline at end of file diff --git a/tests/ModelTests.php b/tests/ModelTests.php index cbee908..9028c9d 100644 --- a/tests/ModelTests.php +++ b/tests/ModelTests.php @@ -2,20 +2,21 @@ require_once __DIR__ . '/../vendor/autoload.php'; use Fufle\Demo\Model\Job; -use Fufle\ORM\Database\ConnectionManager; +//use Fufle\ORM\Database\ConnectionManager; use Fufle\ORM\Database\Connectors\PostgresConnector; //$dns = 'pgsql:host=localhost;port=5432;dbname=dynamic;user=dynamic;password=password123'; $params = [ - 'pgsql', +// 'pgsql', 'localhost', 5432, 'dynamic_dev', 'dynamic', 'Pass@Dyna21', ]; -ConnectionManager::RegisterConnector(new PostgresConnector()); -ConnectionManager::Connect(...$params); +PostgresConnector::Connect(...$params); +//ConnectionManager::RegisterConnector(new PostgresConnector()); +//ConnectionManager::Connect(...$params); echo " "; -- 2.39.5 From 37599e8cf60a3d64e501ceda100c7a195ae9c7e3 Mon Sep 17 00:00:00 2001 From: Dariusz Date: Sun, 7 Mar 2021 11:34:29 +0100 Subject: [PATCH 18/18] fix --- src/Fufle/ORM/Database/Connectors/IConnector.php | 1 + src/Fufle/ORM/Database/Connectors/PostgresConnector.php | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Fufle/ORM/Database/Connectors/IConnector.php b/src/Fufle/ORM/Database/Connectors/IConnector.php index 1b63255..02b34e5 100644 --- a/src/Fufle/ORM/Database/Connectors/IConnector.php +++ b/src/Fufle/ORM/Database/Connectors/IConnector.php @@ -7,4 +7,5 @@ use Fufle\ORM\Database\Credentials; interface IConnector { public function getConnectionString(Credentials $credentials); public function driverEquals(string $driver); + public static function Connect(string $host, int $port, string $database, string $user, string $password); } \ No newline at end of file diff --git a/src/Fufle/ORM/Database/Connectors/PostgresConnector.php b/src/Fufle/ORM/Database/Connectors/PostgresConnector.php index 046be98..d5540d1 100644 --- a/src/Fufle/ORM/Database/Connectors/PostgresConnector.php +++ b/src/Fufle/ORM/Database/Connectors/PostgresConnector.php @@ -3,6 +3,7 @@ namespace Fufle\ORM\Database\Connectors; use Fufle\ORM\Database\Credentials; +use Fufle\ORM\Database\ConnectionManager; class PostgresConnector implements IConnector { public function getConnectionString(Credentials $c) { -- 2.39.5