-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathConnections.php
More file actions
57 lines (43 loc) · 1.68 KB
/
Connections.php
File metadata and controls
57 lines (43 loc) · 1.68 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
<?php
declare(strict_types=1);
namespace Tests\Concerns;
use Illuminate\Database\Schema\Builder;
use Illuminate\Support\Facades\Schema;
use Tests\Configurations\BaseConfiguration;
use Tests\Configurations\Manager;
trait Connections
{
protected $source_connection = 'foo_db';
protected $target_connection = 'bar_db';
abstract protected function defaultSourceConnectionName(): string;
abstract protected function defaultTargetConnectionName(): string;
/**
* @return Builder|\Illuminate\Database\Schema\MySqlBuilder|\Illuminate\Database\Schema\PostgresBuilder
*/
protected function sourceConnection(): Builder
{
return Schema::connection($this->source_connection);
}
/**
* @return Builder|\Illuminate\Database\Schema\MySqlBuilder|\Illuminate\Database\Schema\PostgresBuilder
*/
protected function targetConnection(): Builder
{
return Schema::connection($this->target_connection);
}
protected function setDatabaseConnections($app): void
{
$this->setDatabaseConnection($app, $this->source_connection, $this->defaultSourceConnectionName());
$this->setDatabaseConnection($app, $this->target_connection, $this->defaultTargetConnectionName());
}
protected function setDatabaseConnection($app, string $connection, string $default_connection): void
{
$configurator = $this->getConfigurator($default_connection);
$configurator->setDatabase($connection);
$app->config->set('database.connections.' . $connection, $configurator->toArray());
}
protected function getConfigurator(string $driver): BaseConfiguration
{
return Manager::make()->get($driver);
}
}