Last active
June 8, 2017 10:22
-
-
Save mouson/59656936ed16f27ff7bc6b320f58c157 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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