|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace ReliqArts\Logistiq\Utility; |
|
6
|
|
|
|
|
7
|
|
|
use Illuminate\Config\Repository as ConfigRepository; |
|
8
|
|
|
use Illuminate\Contracts\Support\DeferrableProvider; |
|
9
|
|
|
use ReliqArts\Logistiq\Utility\Contracts\ConfigProvider as ConfigProviderContract; |
|
10
|
|
|
use ReliqArts\Logistiq\Utility\Contracts\EventDispatcher as EventDispatcherContract; |
|
11
|
|
|
use ReliqArts\Logistiq\Utility\Contracts\Logger as LoggerContract; |
|
12
|
|
|
use ReliqArts\Logistiq\Utility\Services\ConfigProvider; |
|
13
|
|
|
use ReliqArts\Logistiq\Utility\Services\EventDispatcher; |
|
14
|
|
|
use ReliqArts\Logistiq\Utility\Services\Logger; |
|
15
|
|
|
use ReliqArts\Logistiq\Utility\Services\StreamHandler; |
|
16
|
|
|
use ReliqArts\ServiceProvider as ReliqArtsServiceProvider; |
|
17
|
|
|
use ReliqArts\Services\ConfigProvider as ReliqArtsConfigProvider; |
|
18
|
|
|
|
|
19
|
|
|
final class ServiceProvider extends ReliqArtsServiceProvider implements DeferrableProvider |
|
20
|
|
|
{ |
|
21
|
|
|
protected const CONFIG_KEY = 'reliqarts-logistiq'; |
|
22
|
|
|
protected const ASSET_DIRECTORY = __DIR__ . '/../..'; |
|
23
|
|
|
protected const LOGGER_NAME = self::CONFIG_KEY . '-logger'; |
|
24
|
|
|
protected const LOG_FILENAME = self::CONFIG_KEY; |
|
25
|
|
|
|
|
26
|
|
|
public function boot() |
|
27
|
|
|
{ |
|
28
|
|
|
parent::boot(); |
|
29
|
|
|
|
|
30
|
|
|
$this->handleMigrations(); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function provides() |
|
34
|
|
|
{ |
|
35
|
|
|
return [ |
|
36
|
|
|
ConfigProviderContract::class, |
|
37
|
|
|
LoggerContract::class, |
|
38
|
|
|
EventDispatcherContract::class, |
|
39
|
|
|
]; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
protected function registerBindings(): void |
|
43
|
|
|
{ |
|
44
|
|
|
$this->app->singleton( |
|
45
|
|
|
ConfigProviderContract::class, |
|
46
|
|
|
function (): ConfigProviderContract { |
|
47
|
|
|
return new ConfigProvider( |
|
48
|
|
|
new ReliqArtsConfigProvider( |
|
49
|
|
|
resolve(ConfigRepository::class), |
|
50
|
|
|
$this->getConfigKey() |
|
51
|
|
|
) |
|
52
|
|
|
); |
|
53
|
|
|
} |
|
54
|
|
|
); |
|
55
|
|
|
|
|
56
|
|
|
$this->app->singleton( |
|
57
|
|
|
LoggerContract::class, |
|
58
|
|
|
function (): LoggerContract { |
|
59
|
|
|
$logger = new Logger($this->getLoggerName()); |
|
60
|
|
|
$logFile = storage_path(sprintf('logs/%s.log', $this->getLogFilename())); |
|
61
|
|
|
$logger->pushHandler(new StreamHandler($logFile, Logger::DEBUG)); |
|
62
|
|
|
|
|
63
|
|
|
return $logger; |
|
64
|
|
|
} |
|
65
|
|
|
); |
|
66
|
|
|
|
|
67
|
|
|
$this->app->singleton( |
|
68
|
|
|
EventDispatcherContract::class, |
|
69
|
|
|
EventDispatcher::class |
|
70
|
|
|
); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
private function handleMigrations() |
|
74
|
|
|
{ |
|
75
|
|
|
$this->loadMigrationsFrom(sprintf('%s/database/migrations', $this->getAssetDirectory())); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|