1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Scrawler\Arca\Facade; |
5
|
|
|
|
6
|
|
|
use Scrawler\Arca\Manager\TableManager; |
7
|
|
|
use Scrawler\Arca\Manager\RecordManager; |
8
|
|
|
use Scrawler\Arca\Manager\ModelManager; |
9
|
|
|
use Scrawler\Arca\Database as DB; |
10
|
|
|
|
11
|
|
|
class Database |
12
|
|
|
{ |
13
|
|
|
private static $database; |
14
|
|
|
|
15
|
|
|
public static function connect(array $connectionParams) |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
if (self::$database == null) { |
19
|
|
|
$connection = \Doctrine\DBAL\DriverManager::getConnection($connectionParams); |
20
|
|
|
self::$database = new DB($connection); |
21
|
|
|
self::$database->setManagers(new TableManager(self::$database), new RecordManager(self::$database), new ModelManager(self::$database)); |
22
|
|
|
return self::$database; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
return self::$database; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
private static function getDB() |
29
|
|
|
{ |
30
|
|
|
return self::$database; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public static function create($name) |
34
|
|
|
{ |
35
|
|
|
return self::getDB()->create($name); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public static function get($table, $id) |
39
|
|
|
{ |
40
|
|
|
return self::getDB()->get($table, $id); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public static function getOne($table, $id) |
44
|
|
|
{ |
45
|
|
|
return self::getDB()->getOne($table, $id); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public static function exec($sql) |
49
|
|
|
{ |
50
|
|
|
return self::getDB()->exec($sql); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public static function delete($model){ |
54
|
|
|
return self::getDB()->delete($model); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public static function find($table, $id) |
58
|
|
|
{ |
59
|
|
|
return self::getDB()->find($table, $id); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
} |