1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace LaravelFreelancerNL\Aranguent; |
6
|
|
|
|
7
|
|
|
use Illuminate\Support\ServiceProvider; |
8
|
|
|
use LaravelFreelancerNL\Aranguent\Eloquent\Model; |
9
|
|
|
use LaravelFreelancerNL\Aranguent\Eloquent\ModelInspector; |
10
|
|
|
use LaravelFreelancerNL\Aranguent\Schema\Grammar as SchemaGrammar; |
11
|
|
|
use Illuminate\Database\Eloquent\ModelInspector as IlluminateModelInspector; |
12
|
|
|
|
13
|
|
|
class AranguentServiceProvider extends ServiceProvider |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* Components to register on the provider. |
17
|
|
|
* |
18
|
|
|
* @var array<string> |
19
|
|
|
*/ |
20
|
|
|
protected $components = [ |
21
|
|
|
'Migration', |
22
|
|
|
]; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Bootstrap services. |
26
|
|
|
* |
27
|
|
|
* @return void |
28
|
|
|
*/ |
29
|
498 |
|
public function boot() |
30
|
|
|
{ |
31
|
|
|
/** @phpstan-ignore offsetAccess.nonOffsetAccessible */ |
32
|
498 |
|
if (isset($this->app['db'])) { |
33
|
498 |
|
Model::setConnectionResolver($this->app['db']); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** @phpstan-ignore offsetAccess.nonOffsetAccessible */ |
37
|
498 |
|
if (isset($this->app['events'])) { |
38
|
498 |
|
Model::setEventDispatcher($this->app['events']); |
39
|
|
|
} |
40
|
|
|
|
41
|
498 |
|
$this->publishes([ |
42
|
498 |
|
__DIR__ . '/../config/arangodb.php' => config_path('arangodb.php'), |
43
|
498 |
|
]); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Register services. |
48
|
|
|
* |
49
|
|
|
* @return void |
50
|
|
|
*/ |
51
|
498 |
|
public function register() |
52
|
|
|
{ |
53
|
|
|
|
54
|
498 |
|
$this->mergeConfigFrom( |
55
|
498 |
|
__DIR__ . '/../config/arangodb.php', |
56
|
498 |
|
'arangodb', |
57
|
498 |
|
); |
58
|
|
|
|
59
|
498 |
|
$this->app->singleton(\Illuminate\Database\Migrations\Migrator::class, function ($app) { |
60
|
498 |
|
return $app['migrator']; |
61
|
498 |
|
}); |
62
|
|
|
|
63
|
498 |
|
$this->app->extend(IlluminateModelInspector::class, function () { |
64
|
4 |
|
return new ModelInspector($this->app); |
65
|
498 |
|
}); |
66
|
|
|
|
67
|
498 |
|
$this->app->resolving( |
68
|
498 |
|
'db', |
69
|
498 |
|
function ($db) { |
70
|
498 |
|
$db->extend( |
71
|
498 |
|
'arangodb', |
72
|
498 |
|
function ($config, $name) { |
73
|
498 |
|
$config['name'] = $name; |
74
|
498 |
|
$connection = new Connection($config); |
75
|
498 |
|
$connection->setSchemaGrammar(new SchemaGrammar($connection)); |
76
|
|
|
|
77
|
498 |
|
return $connection; |
78
|
498 |
|
}, |
79
|
498 |
|
); |
80
|
498 |
|
}, |
81
|
498 |
|
); |
82
|
|
|
|
83
|
498 |
|
$this->app->resolving( |
84
|
498 |
|
function () { |
85
|
498 |
|
if (class_exists('Illuminate\Foundation\AliasLoader')) { |
86
|
498 |
|
$loader = \Illuminate\Foundation\AliasLoader::getInstance(); |
87
|
498 |
|
$loader->alias('Eloquent', 'LaravelFreelancerNL\Aranguent\Eloquent\Model'); |
88
|
|
|
} |
89
|
498 |
|
}, |
90
|
498 |
|
); |
91
|
|
|
|
92
|
498 |
|
$this->app->register('LaravelFreelancerNL\Aranguent\Providers\MigrationServiceProvider'); |
93
|
498 |
|
$this->app->register('LaravelFreelancerNL\Aranguent\Providers\CommandServiceProvider'); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|