1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Flugg\Responder; |
4
|
|
|
|
5
|
|
|
use Flugg\Responder\Contracts\ErrorFactory as ErrorFactoryContract; |
6
|
|
|
use Flugg\Responder\Contracts\ErrorSerializer as ErrorSerializerContract; |
7
|
|
|
use Flugg\Responder\Contracts\Responder as ResponderContract; |
8
|
|
|
use Flugg\Responder\Contracts\ResponseFactory as ResponseFactoryContract; |
9
|
|
|
use Flugg\Responder\Contracts\Transformer as TransformerContract; |
10
|
|
|
use Flugg\Responder\Contracts\TransformFactory; |
11
|
|
|
use Flugg\Responder\Http\Responses\ErrorResponseBuilder; |
12
|
|
|
use Flugg\Responder\Http\Responses\Factories\LaravelResponseFactory; |
13
|
|
|
use Flugg\Responder\Http\Responses\SuccessResponseBuilder; |
14
|
|
|
use Flugg\Responder\Pagination\CursorFactory; |
15
|
|
|
use Flugg\Responder\Pagination\PaginatorFactory; |
16
|
|
|
use Flugg\Responder\Serializers\ErrorSerializer; |
17
|
|
|
use Illuminate\Contracts\Routing\ResponseFactory; |
18
|
|
|
use Illuminate\Http\Request; |
19
|
|
|
use Illuminate\Support\ServiceProvider as BaseServiceProvider; |
20
|
|
|
use League\Fractal\Manager; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* A service provider class responsible for bootstrapping the parts of the Laravel package. |
24
|
|
|
* |
25
|
|
|
* @package flugger/laravel-responder |
26
|
|
|
* @author Alexander Tømmerås <[email protected]> |
27
|
|
|
* @license The MIT License |
28
|
|
|
*/ |
29
|
|
|
class LaravelServiceProvider extends BaseServiceProvider |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* Indicates if loading of the provider is deferred. |
33
|
|
|
* |
34
|
|
|
* @var bool |
35
|
|
|
*/ |
36
|
|
|
protected $defer = false; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Register the service provider. |
40
|
|
|
* |
41
|
|
|
* @return void |
42
|
|
|
*/ |
43
|
|
|
public function register() |
44
|
|
|
{ |
45
|
|
|
$this->app->bind(ResponseFactoryContract::class, function ($app) { |
46
|
|
|
$factory = new LaravelResponseFactory($app[ResponseFactory::class]); |
47
|
|
|
|
48
|
|
|
foreach ($this->app->config['responder.decorators'] as $decorator) { |
49
|
|
|
$factory = new $decorator($factory); |
50
|
|
|
}; |
51
|
|
|
|
52
|
|
|
return $factory; |
53
|
|
|
}); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Bootstrap the application events. |
58
|
|
|
* |
59
|
|
|
* @return void |
60
|
|
|
*/ |
61
|
|
View Code Duplication |
public function boot() |
|
|
|
|
62
|
|
|
{ |
63
|
|
|
$this->publishes([ |
64
|
|
|
__DIR__ . '/../resources/config/responder.php' => config_path('responder.php') |
65
|
|
|
], 'config'); |
66
|
|
|
$this->publishes([ |
67
|
|
|
__DIR__ . '/../resources/lang/en/errors.php' => base_path('resources/lang/en/errors.php') |
68
|
|
|
], 'lang'); |
69
|
|
|
} |
70
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.