1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Flugg\Responder; |
4
|
|
|
|
5
|
|
|
use Flugg\Responder\Console\MakeTransformer; |
6
|
|
|
use Flugg\Responder\Contracts\Manager as ManagerContract; |
7
|
|
|
use Flugg\Responder\Contracts\Responder as ResponderContract; |
8
|
|
|
use Flugg\Responder\Factories\ErrorResponseFactory; |
9
|
|
|
use Flugg\Responder\Factories\SuccessResponseFactory; |
10
|
|
|
use Illuminate\Foundation\Application as Laravel; |
11
|
|
|
use Illuminate\Support\ServiceProvider as BaseServiceProvider; |
12
|
|
|
use Laravel\Lumen\Application as Lumen; |
13
|
|
|
use League\Fractal\Manager; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* The Laravel Responder service provider. This is where the package is bootstrapped. |
17
|
|
|
* |
18
|
|
|
* @package Laravel Responder |
19
|
|
|
* @author Alexander Tømmerås <[email protected]> |
20
|
|
|
* @license The MIT License |
21
|
|
|
*/ |
22
|
|
|
class ResponderServiceProvider extends BaseServiceProvider |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Indicates if loading of the provider is deferred. |
26
|
|
|
* |
27
|
|
|
* @var bool |
28
|
|
|
*/ |
29
|
|
|
protected $defer = false; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Bootstrap the application events. |
33
|
|
|
* |
34
|
|
|
* @return void |
35
|
|
|
*/ |
36
|
|
|
public function boot() |
37
|
|
|
{ |
38
|
|
|
if ( $this->app instanceof Laravel && $this->app->runningInConsole() ) { |
39
|
|
|
$this->bootLaravelApplication(); |
40
|
|
|
|
41
|
|
|
} elseif ( $this->app instanceof Lumen ) { |
|
|
|
|
42
|
|
|
$this->bootLumenApplication(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
$this->mergeConfigFrom( __DIR__ . '/../resources/config/responder.php', 'responder' ); |
46
|
|
|
|
47
|
|
|
$this->commands( [ |
48
|
|
|
MakeTransformer::class |
49
|
|
|
] ); |
50
|
|
|
|
51
|
|
|
include __DIR__ . '/helpers.php'; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Bootstrap the Laravel application. |
57
|
|
|
* |
58
|
|
|
* @return void |
59
|
|
|
*/ |
60
|
|
|
protected function bootLaravelApplication() |
61
|
|
|
{ |
62
|
|
|
$this->publishes( [ |
63
|
|
|
__DIR__ . '/../resources/config/responder.php' => config_path( 'responder.php' ) |
64
|
|
|
], 'config' ); |
65
|
|
|
|
66
|
|
|
$this->publishes( [ |
67
|
|
|
__DIR__ . '/../resources/lang/en/errors.php' => resource_path( 'lang/en/errors.php' ) |
68
|
|
|
], 'lang' ); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Bootstrap the Lumen application. |
73
|
|
|
* |
74
|
|
|
* @return void |
75
|
|
|
*/ |
76
|
|
|
protected function bootLumenApplication() |
77
|
|
|
{ |
78
|
|
|
$this->app->configure( 'responder' ); |
|
|
|
|
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Register the service provider. |
84
|
|
|
* |
85
|
|
|
* @return void |
86
|
|
|
*/ |
87
|
|
|
public function register() |
88
|
|
|
{ |
89
|
|
|
$this->app->singleton( ResponderContract::class, function ( $app ) { |
90
|
|
|
$statusCodes = $app->config->get( 'responder.status_code' ); |
91
|
|
|
$successFactory = new SuccessResponseFactory( $statusCodes ); |
92
|
|
|
$errorFactory = new ErrorResponseFactory( $statusCodes ); |
93
|
|
|
|
94
|
|
|
return ( new Responder( $successFactory, $errorFactory ) ); |
95
|
|
|
} ); |
96
|
|
|
|
97
|
|
|
$this->app->singleton( ManagerContract::class, function ( $app ) { |
98
|
|
|
$serializerClass = $app->config->get( 'responder.serializer' );; |
|
|
|
|
99
|
|
|
$serializer = new $serializerClass; |
100
|
|
|
|
101
|
|
|
return ( new Manager() )->setSerializer( new $serializer ); |
102
|
|
|
} ); |
103
|
|
|
|
104
|
|
|
$this->app->alias( ResponderContract::class, 'responder' ); |
105
|
|
|
$this->app->alias( ManagerContract::class, 'responder.manager' ); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Get the services provided by the provider. |
110
|
|
|
* |
111
|
|
|
* @return array |
112
|
|
|
*/ |
113
|
|
|
public function provides() |
114
|
|
|
{ |
115
|
|
|
return [ 'responder', 'responder.manager' ]; |
116
|
|
|
} |
117
|
|
|
} |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.