-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathFileMakerConnectionServiceProvider.php
70 lines (60 loc) · 2.26 KB
/
FileMakerConnectionServiceProvider.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
namespace GearboxSolutions\EloquentFileMaker\Providers;
use GearboxSolutions\EloquentFileMaker\Commands\FMModelMakeCommand;
use GearboxSolutions\EloquentFileMaker\Middleware\EndSession;
use GearboxSolutions\EloquentFileMaker\Services\FileMakerConnection;
use Illuminate\Contracts\Http\Kernel;
use Illuminate\Support\ServiceProvider;
class FileMakerConnectionServiceProvider extends ServiceProvider
{
/**
* Register services.
*
* @return void
*/
public function register()
{
// extend DatabaseResolver to handle 'filemaker' as a driver and return a FileMakerConnection
$this->app->resolving('db', function ($db) {
$db->extend('filemaker', function ($config, $connectionName) {
$config['name'] = $connectionName;
return new FileMakerConnection($connectionName, $config['database'], $config['prefix'], $config);
});
});
// register the FM facade
$this->app->singleton('fm', function ($app) {
return $app['db'];
});
$this->app->bind('fm.connection', function ($app) {
return $app['fm']->connection();
});
$this->app->bind(FileMakerConnection::class, function ($app) {
return $app['fm.connection'];
});
app('router')->aliasMiddleware('fm.end-session', EndSession::class);
if ($this->app->runningInConsole()) {
$this->commands([
FMModelMakeCommand::class,
]);
}
}
/**
* Bootstrap services.
*
* @return void
*/
public function boot(Kernel $kernel)
{
// add the middleware to the global middleware so that we always end the FileMaker session
$kernel->pushMiddleware(EndSession::class);
$this->publishes([
__DIR__ . '/../config/eloquent-filemaker.php' => config_path('eloquent-filemaker.php'),
], 'eloquent-filemaker-config');
$this->publishes([
__DIR__ . '/../Commands/stubs/fm.model.stub' => base_path('stubs/model.stub'),
], 'eloquent-filemaker-override-model');
$this->publishes([
__DIR__ . '/../Commands/stubs/fm.model.stub' => base_path('stubs/fm.model.stub'),
], 'eloquent-filemaker-stubs');
}
}