This repository has been archived by the owner on May 8, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFlasherCliServiceProvider.php
106 lines (90 loc) · 2.89 KB
/
FlasherCliServiceProvider.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
/*
* This file is part of the PHPFlasher package.
* (c) Younes KHOUBZA <[email protected]>
*/
namespace Flasher\Cli\Laravel;
use Flasher\Cli\Prime\CliFactory;
use Flasher\Cli\Prime\EventListener\RenderListener;
use Flasher\Cli\Prime\Notify;
use Flasher\Cli\Prime\Presenter\CliPresenter;
use Flasher\Prime\EventDispatcher\EventDispatcherInterface;
use Flasher\Prime\FlasherInterface;
use Flasher\Prime\Response\ResponseManagerInterface;
use Illuminate\Container\Container;
use Illuminate\Support\ServiceProvider;
final class FlasherCliServiceProvider extends ServiceProvider
{
/**
* @return void
*/
public function boot()
{
$this->processConfiguration();
$this->registerRenderListener();
$this->registerPresenter();
}
/**
* {@inheritdoc}
*/
public function register()
{
$this->registerNotifierFactory();
$this->registerNotifier();
}
/**
* @return void
*/
private function processConfiguration()
{
$name = 'flasher_cli';
$config = $this->app->make('config');
$config->set($name, $config->get($name, array())); // @phpstan-ignore-line
}
/**
* @return void
*/
private function registerNotifierFactory()
{
$this->app->singleton('flasher.cli', function (Container $app) {
return new CliFactory($app->make('flasher.storage_manager')); // @phpstan-ignore-line
});
$this->app->alias('flasher.cli', 'Flasher\Cli\Prime\CliFactory');
}
/**
* @return void
*/
private function registerNotifier()
{
$this->app->singleton('flasher.notify', function (Container $app) {
/** @phpstan-ignore-next-line */
$title = $app->make('config')->get('flasher_cli.title', null);
$icons = $app->make('config')->get('flasher_cli.icons', array()); // @phpstan-ignore-line
return new Notify($title, $icons);
});
$this->app->alias('flasher.notify', 'Flasher\Cli\Prime\Notify');
$this->app->alias('flasher.notify', 'Flasher\Cli\Prime\NotifyInterface');
}
/**
* @return void
*/
private function registerRenderListener()
{
/** @var FlasherInterface $flasher */
$flasher = $this->app->make('flasher');
$this->app->extend('flasher.event_dispatcher', function (EventDispatcherInterface $dispatcher) use ($flasher) {
$dispatcher->addSubscriber(new RenderListener($flasher));
return $dispatcher;
});
}
/**
* @return void
*/
private function registerPresenter()
{
$this->app->extend('flasher.response_manager', function (ResponseManagerInterface $manager, Container $app) {
$manager->addPresenter(CliPresenter::NAME, new CliPresenter($app->make('flasher.notify'))); // @phpstan-ignore-line
return $manager;
});
}
}