Skip to content

Instantly share code, notes, and snippets.

@mouson
Last active June 8, 2017 10:22
Show Gist options
  • Save mouson/59656936ed16f27ff7bc6b320f58c157 to your computer and use it in GitHub Desktop.
Save mouson/59656936ed16f27ff7bc6b320f58c157 to your computer and use it in GitHub Desktop.
<?php
namespace MyDB;
use Illuminate\Support\ServiceProvider;
use MyDB\Connectors\MyDBConnector as Connector;
class MyDBServiceProvider extends ServiceProvider
{
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = false;
public function boot()
{
$this->publishes([
__DIR__ . '/../../config/mydb.php' => config_path('/mydb.php'),
], 'mydb');
}
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->mergeConfigFrom(__DIR__ . '/../../config/mydb.php', 'database.connections');
MyDBConnection::resolverFor('mydb', function ($connection, $database, $prefix, $config) {
$connector = new Connector();
$connection = $connector->connect($config);
$db = new MyDBConnection($connection, $config["database"], $config["prefix"], $config);
return $db;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment