1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of Collision. |
5
|
|
|
* |
6
|
|
|
* (c) Nuno Maduro <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace NunoMaduro\Collision\Adapters\Laravel; |
13
|
|
|
|
14
|
|
|
use Illuminate\Contracts\Debug\ExceptionHandler as ExceptionHandlerContract; |
15
|
|
|
use Illuminate\Support\ServiceProvider; |
16
|
|
|
use NunoMaduro\Collision\Contracts\Provider as ProviderContract; |
17
|
|
|
use NunoMaduro\Collision\Handler; |
18
|
|
|
use NunoMaduro\Collision\Provider; |
19
|
|
|
use NunoMaduro\Collision\SolutionsRepositories\NullSolutionsRepository; |
20
|
|
|
use NunoMaduro\Collision\Writer; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* This is an Collision Laravel Adapter Service Provider implementation. |
24
|
|
|
* |
25
|
|
|
* Registers the Error Handler on Laravel. |
26
|
|
|
* |
27
|
|
|
* @author Nuno Maduro <[email protected]> |
28
|
|
|
*/ |
29
|
|
|
class CollisionServiceProvider extends ServiceProvider |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* {@inheritdoc} |
33
|
|
|
* |
34
|
|
|
* @var bool |
35
|
|
|
*/ |
36
|
|
|
protected $defer = true; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* {@inheritdoc} |
40
|
|
|
*/ |
41
|
3 |
|
public function register() |
42
|
|
|
{ |
43
|
3 |
|
if ($this->app->runningInConsole() && ! $this->app->runningUnitTests()) { |
44
|
|
|
$this->app->bind(ProviderContract::class, function () { |
45
|
|
|
if ($this->app->has(\Facade\IgnitionContracts\SolutionProviderRepository::class)) { |
46
|
|
|
$solutionsRepository = new IgnitionSolutionsRepository( |
47
|
|
|
$this->app->get(\Facade\IgnitionContracts\SolutionProviderRepository::class) |
48
|
|
|
); |
49
|
|
|
} else { |
50
|
|
|
$solutionsRepository = new NullSolutionsRepository(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
$writer = new Writer($solutionsRepository); |
54
|
|
|
$handler = new Handler($writer); |
55
|
|
|
|
56
|
|
|
return new Provider(null, $handler); |
57
|
1 |
|
}); |
58
|
|
|
|
59
|
1 |
|
$appExceptionHandler = $this->app->make(ExceptionHandlerContract::class); |
60
|
|
|
|
61
|
1 |
|
$this->app->singleton( |
62
|
1 |
|
ExceptionHandlerContract::class, |
63
|
|
|
function ($app) use ($appExceptionHandler) { |
64
|
1 |
|
return new ExceptionHandler($app, $appExceptionHandler); |
65
|
1 |
|
} |
66
|
|
|
); |
67
|
|
|
} |
68
|
3 |
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* {@inheritdoc} |
72
|
|
|
*/ |
73
|
1 |
|
public function provides() |
74
|
|
|
{ |
75
|
1 |
|
return [ProviderContract::class]; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|