| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Models\Connection; |
| 4 |
|
| 5 |
use FluentCart\App\Models\Model; |
| 6 |
use FluentCart\Framework\Database\DatabaseManager; |
| 7 |
use FluentCart\Database\Overrides\DbConnection; |
| 8 |
use FluentCart\Framework\Database\ConnectionResolver; |
| 9 |
|
| 10 |
class ConnectionManager |
| 11 |
{ |
| 12 |
public static function connect(&$app) |
| 13 |
{ |
| 14 |
|
| 15 |
$resolver = new ConnectionResolver([ |
| 16 |
'mysql' => new DbConnection( |
| 17 |
$GLOBALS['wpdb'], |
| 18 |
$app->config->get('database') |
| 19 |
), |
| 20 |
'sqlite' => new DbConnection( |
| 21 |
$GLOBALS['wpdb'] |
| 22 |
), |
| 23 |
]); |
| 24 |
|
| 25 |
$resolver->setDefaultConnection('mysql'); |
| 26 |
|
| 27 |
Model::setConnectionResolver($resolver); |
| 28 |
|
| 29 |
Model::setEventDispatcher($app['events']); |
| 30 |
|
| 31 |
$app->singleton('db', function ($app) use ($resolver) { |
| 32 |
return new DatabaseManager($resolver); |
| 33 |
}); |
| 34 |
} |
| 35 |
} |
| 36 |
|