Skip to content

Commit

Permalink
Merge pull request #22 from InitPHP/v3.0
Browse files Browse the repository at this point in the history
v3.0
  • Loading branch information
muhammetsafak authored Dec 9, 2023
2 parents b3748c0 + 3c6eb38 commit 641abb0
Show file tree
Hide file tree
Showing 30 changed files with 341 additions and 5,341 deletions.
214 changes: 65 additions & 149 deletions README.md

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "initphp/database",
"description": "InitPHP DB (QueryBuilder, DBAL and ORM) Library",
"description": "InitPHP DataBase (QueryBuilder, DBAL and ORM) Library",
"type": "library",
"license": "MIT",
"autoload": {
Expand All @@ -23,10 +23,11 @@
],
"minimum-stability": "stable",
"require": {
"php": ">=7.4",
"ext-pdo": "*"
"php": ">=8.0",
"ext-pdo": "*",
"initorm/orm": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "9.5"
"phpunit/phpunit": "^10.4"
}
}
52 changes: 52 additions & 0 deletions src/DB.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

declare(strict_types=1);
namespace InitPHP\Database;

use InitORM\Database\Exceptions\DatabaseException;
use InitORM\Database\Interfaces\DatabaseInterface;
use InitORM\DBAL\Connection\Interfaces\ConnectionInterface;

/**
* @mixin \InitORM\Database\Facade\DB
*/
class DB
{

private static DatabaseInterface $db;

public function __call($name, $arguments)
{
return self::getDatabase()->{$name}(...$arguments);
}

public static function __callStatic($name, $arguments)
{
return self::getDatabase()->{$name}(...$arguments);
}

public static function createImmutable(array|ConnectionInterface $connection): void
{
self::$db = self::connect($connection);
}

/**
* @param array|ConnectionInterface $connection
* @return DatabaseInterface
*/
public static function connect(array|ConnectionInterface $connection): DatabaseInterface
{
return new Database($connection);
}

public static function getDatabase(): DatabaseInterface
{
if (!isset(self::$db)) {
throw new DatabaseException('To create an immutable, first use the "createImmutable()" method.');
}

return self::$db;
}


}
Loading

0 comments on commit 641abb0

Please sign in to comment.