| 148 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
declare(strict_types=1);
|
|
|
4 |
|
|
|
5 |
namespace NunoMaduro\Collision\Adapters\Laravel;
|
|
|
6 |
|
|
|
7 |
use Illuminate\Contracts\Debug\ExceptionHandler as ExceptionHandlerContract;
|
|
|
8 |
use Illuminate\Support\ServiceProvider;
|
|
|
9 |
use NunoMaduro\Collision\Adapters\Laravel\Commands\TestCommand;
|
|
|
10 |
use NunoMaduro\Collision\Contracts\Provider as ProviderContract;
|
|
|
11 |
use NunoMaduro\Collision\Handler;
|
|
|
12 |
use NunoMaduro\Collision\Provider;
|
|
|
13 |
use NunoMaduro\Collision\SolutionsRepositories\NullSolutionsRepository;
|
|
|
14 |
use NunoMaduro\Collision\Writer;
|
|
|
15 |
|
|
|
16 |
/**
|
|
|
17 |
* @internal
|
|
|
18 |
*
|
|
|
19 |
* @final
|
|
|
20 |
*/
|
|
|
21 |
class CollisionServiceProvider extends ServiceProvider
|
|
|
22 |
{
|
|
|
23 |
/**
|
|
|
24 |
* {@inheritdoc}
|
|
|
25 |
*
|
|
|
26 |
* @var bool
|
|
|
27 |
*/
|
|
|
28 |
protected $defer = true;
|
|
|
29 |
|
|
|
30 |
/**
|
|
|
31 |
* Boots application services.
|
|
|
32 |
*
|
|
|
33 |
* @return void
|
|
|
34 |
*/
|
|
|
35 |
public function boot()
|
|
|
36 |
{
|
|
|
37 |
$this->commands([
|
|
|
38 |
TestCommand::class,
|
|
|
39 |
]);
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
/**
|
|
|
43 |
* {@inheritdoc}
|
|
|
44 |
*/
|
|
|
45 |
public function register()
|
|
|
46 |
{
|
|
|
47 |
if ($this->app->runningInConsole() && ! $this->app->runningUnitTests()) {
|
|
|
48 |
$this->app->bind(ProviderContract::class, function () {
|
|
|
49 |
// @phpstan-ignore-next-line
|
|
|
50 |
if ($this->app->has(\Spatie\Ignition\Contracts\SolutionProviderRepository::class)) {
|
|
|
51 |
/** @var \Spatie\Ignition\Contracts\SolutionProviderRepository $solutionProviderRepository */
|
|
|
52 |
$solutionProviderRepository = $this->app->get(\Spatie\Ignition\Contracts\SolutionProviderRepository::class);
|
|
|
53 |
|
|
|
54 |
$solutionsRepository = new IgnitionSolutionsRepository($solutionProviderRepository);
|
|
|
55 |
} else {
|
|
|
56 |
$solutionsRepository = new NullSolutionsRepository();
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
$writer = new Writer($solutionsRepository);
|
|
|
60 |
$handler = new Handler($writer);
|
|
|
61 |
|
|
|
62 |
return new Provider(null, $handler);
|
|
|
63 |
});
|
|
|
64 |
|
|
|
65 |
/** @var \Illuminate\Contracts\Debug\ExceptionHandler $appExceptionHandler */
|
|
|
66 |
$appExceptionHandler = $this->app->make(ExceptionHandlerContract::class);
|
|
|
67 |
|
|
|
68 |
$this->app->singleton(
|
|
|
69 |
ExceptionHandlerContract::class,
|
|
|
70 |
function ($app) use ($appExceptionHandler) {
|
|
|
71 |
return new ExceptionHandler($app, $appExceptionHandler);
|
|
|
72 |
}
|
|
|
73 |
);
|
|
|
74 |
}
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
/**
|
|
|
78 |
* {@inheritdoc}
|
|
|
79 |
*/
|
|
|
80 |
public function provides()
|
|
|
81 |
{
|
|
|
82 |
return [ProviderContract::class];
|
|
|
83 |
}
|
|
|
84 |
}
|