|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Noitran\RQL; |
|
6
|
|
|
|
|
7
|
|
|
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider; |
|
8
|
|
|
use Noitran\RQL\Contracts\Processor\ProcessorInterface; |
|
9
|
|
|
use Noitran\RQL\Services\RQLService; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class ServiceProvider. |
|
13
|
|
|
*/ |
|
14
|
|
|
class ServiceProvider extends IlluminateServiceProvider |
|
15
|
|
|
{ |
|
16
|
12 |
|
public function boot(): void |
|
17
|
|
|
{ |
|
18
|
12 |
|
$this->publishConfig(); |
|
19
|
12 |
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Register the service provider. |
|
23
|
|
|
*/ |
|
24
|
12 |
|
public function register(): void |
|
25
|
|
|
{ |
|
26
|
12 |
|
$this->registerConfig(); |
|
27
|
12 |
|
$this->registerService(); |
|
28
|
12 |
|
$this->bindProcessor(); |
|
29
|
12 |
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @return string |
|
33
|
|
|
*/ |
|
34
|
|
|
protected function getConfigPath(): string |
|
35
|
|
|
{ |
|
36
|
|
|
return __DIR__ . '/../config/repositories.php'; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
12 |
|
protected function publishConfig(): void |
|
40
|
|
|
{ |
|
41
|
12 |
|
$configPath = __DIR__ . '/../config/rql.php'; |
|
42
|
12 |
|
if (\function_exists('config_path')) { |
|
43
|
12 |
|
$publishPath = config_path('rql.php'); |
|
44
|
|
|
} else { |
|
45
|
|
|
$publishPath = base_path('config/rql.php'); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
12 |
|
$this->publishes([$configPath => $publishPath], 'config'); |
|
49
|
12 |
|
} |
|
50
|
|
|
|
|
51
|
12 |
|
protected function registerConfig(): void |
|
52
|
|
|
{ |
|
53
|
12 |
|
$configPath = __DIR__ . '/../config/rql.php'; |
|
54
|
12 |
|
$this->mergeConfigFrom($configPath, 'rql'); |
|
55
|
12 |
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Bind the RQL service as singleton. |
|
59
|
|
|
*/ |
|
60
|
12 |
|
protected function registerService(): void |
|
61
|
|
|
{ |
|
62
|
12 |
|
$this->app->singleton(RQLService::class); |
|
63
|
12 |
|
$this->app->alias(RQLService::class, 'rql'); |
|
64
|
12 |
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Bind ORM implementation to Processor. |
|
68
|
|
|
*/ |
|
69
|
12 |
|
protected function bindProcessor(): void |
|
70
|
|
|
{ |
|
71
|
|
|
$this->app->bind(ProcessorInterface::class, function () { |
|
72
|
12 |
|
return rql()->getProcessor(); |
|
73
|
12 |
|
}); |
|
74
|
12 |
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|