CollisionServiceProvider.php
2.1 KB
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
<?php
declare(strict_types=1);
namespace NunoMaduro\Collision\Adapters\Laravel;
use Illuminate\Contracts\Debug\ExceptionHandler as ExceptionHandlerContract;
use Illuminate\Support\ServiceProvider;
use NunoMaduro\Collision\Adapters\Laravel\Commands\TestCommand;
use NunoMaduro\Collision\Contracts\Provider as ProviderContract;
use NunoMaduro\Collision\Handler;
use NunoMaduro\Collision\Provider;
use NunoMaduro\Collision\SolutionsRepositories\NullSolutionsRepository;
use NunoMaduro\Collision\Writer;
/**
* @internal
*
* @final
*/
class CollisionServiceProvider extends ServiceProvider
{
/**
* {@inheritdoc}
*
* @var bool
*/
protected $defer = true;
/**
* Boots application services.
*
* @return void
*/
public function boot()
{
$this->commands([
TestCommand::class,
]);
}
/**
* {@inheritdoc}
*/
public function register()
{
if ($this->app->runningInConsole() && !$this->app->runningUnitTests()) {
$this->app->bind(ProviderContract::class, function () {
if ($this->app->has(\Facade\IgnitionContracts\SolutionProviderRepository::class)) {
$solutionsRepository = new IgnitionSolutionsRepository(
$this->app->get(\Facade\IgnitionContracts\SolutionProviderRepository::class)
);
} else {
$solutionsRepository = new NullSolutionsRepository();
}
$writer = new Writer($solutionsRepository);
$handler = new Handler($writer);
return new Provider(null, $handler);
});
$appExceptionHandler = $this->app->make(ExceptionHandlerContract::class);
$this->app->singleton(
ExceptionHandlerContract::class,
function ($app) use ($appExceptionHandler) {
return new ExceptionHandler($app, $appExceptionHandler);
}
);
}
}
/**
* {@inheritdoc}
*/
public function provides()
{
return [ProviderContract::class];
}
}