Completed
Push — master ( c09367...ed3a3e )
by Vladimir
02:46
created

ChannelServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 13
ccs 0
cts 9
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Foundation\Providers;
6
7
use FondBot\Framework\Application;
8
use FondBot\Channels\ChannelManager;
9
use FondBot\Contracts\Channels\Manager;
10
use Illuminate\Support\ServiceProvider;
11
12
/**
13
 * @property Application $app
14
 */
15
class ChannelServiceProvider extends ServiceProvider
16
{
17
    /**
18
     * Register application services.
19
     */
20
    public function register(): void
21
    {
22
        $this->registerManager();
23
    }
24
25
    /**
26
     * Boot application services.
27
     */
28
    public function boot(): void
29
    {
30
        /** @var ChannelManager $manager */
31
        $manager = $this->app[Manager::class];
32
33
        $manager->register(
34
            collect($this->channels())
35
                ->mapWithKeys(function (array $parameters, string $name) {
36
                    return [$name => $parameters];
37
                })
38
                ->toArray()
39
        );
40
    }
41
42
    /**
43
     * Define bot channels.
44
     *
45
     * @return array
46
     */
47
    protected function channels(): array
48
    {
49
        return [];
50
    }
51
52
    private function registerManager(): void
53
    {
54
        $this->app->singleton(Manager::class, function () {
55
            return new ChannelManager($this->app);
56
        });
57
58
        $this->app->alias(Manager::class, ChannelManager::class);
59
    }
60
}
61