-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.php
More file actions
84 lines (63 loc) · 2.4 KB
/
init.php
File metadata and controls
84 lines (63 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
use Illuminate\Database\Events\QueryExecuted;
use Illuminate\Events\Dispatcher;
use Illuminate\Container\Container;
use Illuminate\Database\Capsule\Manager;
require __DIR__ . '/vendor/autoload.php';
$ioc = new Container;
$manager = new Manager($ioc);
$dispatcher = new Dispatcher($ioc);
$manager->setEventDispatcher($dispatcher);
$manager->bootEloquent();
$manager->setAsGlobal();
$connections = [
'mysql' => [
'driver' => 'mysql',
'host' => '127.0.0.1',
'database' => 'homestead',
'username' => 'homestead',
'password' => 'secret',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
'sqlite' => [
'driver' => 'sqlite',
'database' => ':memory:'
],
];
$manager->addConnection($connections['sqlite']);
////////////////////////////////////////////////
if ('cli' !== PHP_SAPI) {
$manager->connection()->listen(function (QueryExecuted $queryExecuted) {
$sql = $queryExecuted->sql;
$bindings = $queryExecuted->bindings;
if (
starts_with($sql, ['truncate', 'create', 'delete', 'drop', 'alter'])
|| str_contains($sql, ['sqlite_master', 'information_schema', 'INFORMATION_SCHEMA'])
) {
return;
}
$sql = str_replace(array('%', '?'), array('%%', '%s'), $sql);
$sql = vsprintf($sql, $bindings);
SqlFormatter::$pre_attributes = 'style="background:#18171b;color:#1299da;padding:5px;"';
SqlFormatter::$word_attributes = 'style="color:white;"';
SqlFormatter::$backtick_quote_attributes = 'style="color: #56db3a;"';
$sql = SqlFormatter::format($sql);
$time_now = (new DateTime)->format('H:i:s');;
$log = "";
//$log = $time_now . ' | ' . $time . 'ms | ';
$log .= $sql . PHP_EOL;
echo '<p>' . $log . '</p>';
});
print_r(str_replace('Example', '', studly_case(pathinfo($_SERVER['PHP_SELF'], PATHINFO_FILENAME))));
}
if ($manager->getConnection()->getDriverName() == 'sqlite') {
include 'prepare/migrate.php';
} else{
$manager->connection()->statement(
"S" . "ELECT Concat('TRUNCATE TABLE ',table_schema,'.',TABLE_NAME, ';')
FROM INFORMATION_SCHEMA.TABLES where table_schema in ('homestead')"
);
}