forked from nette/database
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.php
More file actions
69 lines (53 loc) · 1.71 KB
/
bootstrap.php
File metadata and controls
69 lines (53 loc) · 1.71 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
<?php
declare(strict_types=1);
// The Nette Tester command-line runner can be
// invoked through the command: ../vendor/bin/tester .
if (@!include __DIR__ . '/../vendor/autoload.php') {
echo 'Install Nette Tester using `composer install`';
exit(1);
}
// configure environment
Tester\Environment::setup();
Tester\Environment::setupFunctions();
date_default_timezone_set('Europe/Prague');
function getTempDir(): string
{
$dir = __DIR__ . '/tmp';
@mkdir($dir);
return $dir;
}
function connectToDB(array $options = []): Nette\Database\Explorer
{
$args = Tester\Environment::loadData() + ['username' => null, 'password' => null, 'options' => []];
$args['options'] = $options + $args['options'];
if ($args['dsn'] !== 'sqlite::memory:') {
Tester\Environment::lock($args['dsn'], getTempDir());
}
$explorer = new Nette\Database\Explorer($args['dsn'], $args['username'], $args['password'], $args['options']);
$connection->connect();
$driverName = $explorer->getConnection()->getNativeConnection()->getAttribute(PDO::ATTR_DRIVER_NAME);
$explorer->setCache(new Nette\Caching\Cache(new Nette\Caching\Storages\MemoryStorage));
echo "Driver: $driverName\n";
$GLOBALS['driverName'] = $driverName;
return $explorer;
}
/** Replaces [] with driver-specific quotes */
function reformat($s): string
{
$driverName = $GLOBALS['driverName'];
if (is_array($s)) {
if (isset($s[$driverName])) {
return $s[$driverName];
}
$s = $s[0];
}
if ($driverName === 'mysql') {
return strtr($s, '[]', '``');
} elseif ($driverName === 'pgsql') {
return strtr($s, '[]', '""');
} elseif ($driverName === 'sqlsrv' || $driverName === 'sqlite') {
return $s;
} else {
trigger_error("Unsupported driver $driverName", E_USER_WARNING);
}
}