-
Notifications
You must be signed in to change notification settings - Fork 1
/
Provider.php
59 lines (48 loc) · 1.83 KB
/
Provider.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
<?php declare(strict_types = 1);
namespace LastDragon_ru\LaraASP\GraphQL;
use Illuminate\Contracts\Config\Repository;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Support\ServiceProvider;
use LastDragon_ru\LaraASP\Core\Concerns\ProviderWithConfig;
use LastDragon_ru\LaraASP\Core\Concerns\ProviderWithTranslations;
use LastDragon_ru\LaraASP\GraphQL\SearchBy\SearchByDirective;
use Nuwave\Lighthouse\Events\RegisterDirectiveNamespaces;
use function array_slice;
use function explode;
use function implode;
class Provider extends ServiceProvider {
use ProviderWithConfig;
use ProviderWithTranslations;
public function boot(Dispatcher $dispatcher): void {
$this->bootConfig([
'search_by.scalars',
'search_by.aliases',
]);
$this->bootDirectives($dispatcher);
}
public function register(): void {
parent::register();
$this->registerDirectives();
}
protected function bootDirectives(Dispatcher $dispatcher): void {
$dispatcher->listen(
RegisterDirectiveNamespaces::class,
static function (): string {
return implode('\\', array_slice(explode('\\', SearchByDirective::class), 0, -1));
},
);
}
protected function registerDirectives(): void {
$this->app->bind(SearchByDirective::class, function (): SearchByDirective {
$container = $this->app;
$config = $container->make(Repository::class);
$scalars = $config->get("{$this->getName()}.search_by.scalars");
$aliases = $config->get("{$this->getName()}.search_by.aliases");
$instance = new SearchByDirective($container, $scalars, $aliases);
return $instance;
});
}
protected function getName(): string {
return Package::Name;
}
}