forked from gothinkster/slim-php-realworld-example-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEloquentServiceProvider.php
48 lines (38 loc) · 1.3 KB
/
EloquentServiceProvider.php
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
<?php
namespace Conduit\Services\Database;
use Illuminate\Database\Capsule\Manager;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
class EloquentServiceProvider implements ServiceProviderInterface
{
/**
* Registers services on the given container.
*
* This method should only be used to configure services and parameters.
* It should not get services.
*
* @param Container $pimple A container instance
*/
public function register(Container $pimple)
{
$capsule = new Manager();
$config = $pimple['settings']['database'];
$capsule->addConnection([
'driver' => $config['driver'],
'host' => $config['host'],
'database' => $config['database'],
'username' => $config['username'],
'password' => $config['password'],
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
]);
// Make this Capsule instance available globally via static methods... (optional)
$capsule->setAsGlobal();
// Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher())
$capsule->bootEloquent();
$pimple['db'] = function ($c) use ($capsule) {
return $capsule;
};
}
}