26
26
use CloudCreativity \JsonApi \Repositories \EncoderOptionsRepository ;
27
27
use CloudCreativity \JsonApi \Repositories \EncodersRepository ;
28
28
use CloudCreativity \JsonApi \Repositories \SchemasRepository ;
29
+ use CloudCreativity \JsonApi \Services \EnvironmentService ;
29
30
use Illuminate \Contracts \Config \Repository ;
30
31
use Illuminate \Contracts \Http \Kernel ;
31
32
use Illuminate \Routing \Router ;
41
42
use Neomerx \JsonApi \Exceptions \RendererContainer ;
42
43
use Neomerx \JsonApi \Factories \Factory ;
43
44
use Neomerx \JsonApi \Responses \Responses ;
45
+ use Request ;
44
46
45
47
/**
46
48
* Class ServiceProvider
@@ -52,7 +54,7 @@ class ServiceProvider extends BaseServiceProvider
52
54
/**
53
55
* @var bool
54
56
*/
55
- protected $ defer = true ;
57
+ protected $ defer = false ;
56
58
57
59
/**
58
60
* @param Router $router
@@ -61,7 +63,9 @@ class ServiceProvider extends BaseServiceProvider
61
63
public function boot (Router $ router , Kernel $ kernel )
62
64
{
63
65
// Allow publishing of config file
64
- $ this ->publishes (__DIR__ . '/config/json-api.php ' , config_path ('json-api.php ' ));
66
+ $ this ->publishes ([
67
+ __DIR__ . '/../config/json-api.php ' => config_path ('json-api.php ' ),
68
+ ]);
65
69
66
70
// Add Json Api middleware to the router.
67
71
$ router ->middleware (M::JSON_API , BootJsonApi::class);
@@ -84,41 +88,44 @@ public function register()
84
88
{
85
89
$ container = $ this ->app ;
86
90
91
+ // Environment
92
+ $ container ->singleton (EnvironmentService::class);
93
+
87
94
// Factory
88
- $ container ->alias (ParametersFactoryInterface::class, FactoryInterface::class);
89
95
$ container ->singleton (FactoryInterface::class, Factory::class);
96
+ $ container ->singleton (ParametersFactoryInterface::class, Factory::class);
90
97
91
98
// Encoders Repository
92
99
$ container ->singleton (EncodersRepositoryInterface::class, EncodersRepository::class);
93
100
$ container ->singleton (SchemasRepositoryInterface::class, SchemasRepository::class);
94
101
$ container ->singleton (EncoderOptionsRepositoryInterface::class, EncoderOptionsRepository::class);
95
102
$ container ->resolving (EncodersRepositoryInterface::class, function (ConfigurableInterface $ repository ) {
96
- $ repository ->configure ($ this ->getConfig (C::ENCODERS , []));
103
+ $ repository ->configure (( array ) $ this ->getConfig (C::ENCODERS , []));
97
104
});
98
105
$ container ->resolving (EncoderOptionsRepositoryInterface::class, function (EncoderOptionsRepositoryInterface $ repository ) {
99
106
$ repository ->addModifier (function (MutableConfigInterface $ config ) {
100
107
$ key = EncoderOptionsRepositoryInterface::URL_PREFIX ;
101
108
if (!$ config ->has ($ key )) {
102
- $ config ->set ($ key , \ Request::getSchemeAndHttpHost ());
109
+ $ config ->set ($ key , Request::getSchemeAndHttpHost ());
103
110
};
104
111
});
105
112
});
106
113
107
114
// Decoders Repository
108
115
$ container ->singleton (DecodersRepositoryInterface::class, DecodersRepository::class);
109
116
$ container ->resolving (DecodersRepositoryInterface::class, function (ConfigurableInterface $ repository ) {
110
- $ repository ->configure ($ this ->getConfig (C::DECODERS , []));
117
+ $ repository ->configure (( array ) $ this ->getConfig (C::DECODERS , []));
111
118
});
112
119
113
120
// Codec Matcher Repository
114
121
$ container ->singleton (CodecMatcherRepositoryInterface::class, CodecMatcherRepository::class);
115
122
$ container ->resolving (CodecMatcherRepositoryInterface::class, function (ConfigurableInterface $ repository ) {
116
- $ repository ->configure ($ this ->getConfig (C::CODEC_MATCHER , []));
123
+ $ repository ->configure (( array ) $ this ->getConfig (C::CODEC_MATCHER , []));
117
124
});
118
125
119
126
// Laravel Integration
120
- $ container ->alias (CurrentRequestInterface::class, LaravelIntegration::class);
121
- $ container ->alias (NativeResponsesInterface::class, LaravelIntegration::class);
127
+ $ container ->singleton (CurrentRequestInterface::class, LaravelIntegration::class);
128
+ $ container ->singleton (NativeResponsesInterface::class, LaravelIntegration::class);
122
129
$ container ->singleton (ResponsesInterface::class, Responses::class);
123
130
124
131
// Exception Thrower
@@ -128,7 +135,7 @@ public function register()
128
135
$ container ->singleton (RendererInterface::class, StandardRenderer::class);
129
136
$ container ->singleton (RendererContainerInterface::class, RendererContainer::class);
130
137
$ container ->resolving (RendererInterface::class, function (ConfigurableInterface $ renderer ) {
131
- $ renderer ->configure ($ this ->getConfig (C::EXCEPTIONS ));
138
+ $ renderer ->configure (( array ) $ this ->getConfig (C::EXCEPTIONS ));
132
139
});
133
140
$ container ->resolving (RendererContainerInterface::class, function (RendererContainerInterface $ rendererContainer ) use ($ container ) {
134
141
/** @var ResponsesInterface $response */
@@ -141,28 +148,6 @@ public function register()
141
148
});
142
149
}
143
150
144
- /**
145
- * @return array
146
- */
147
- public function provides ()
148
- {
149
- return [
150
- ParametersFactoryInterface::class,
151
- FactoryInterface::class,
152
- SchemasRepositoryInterface::class,
153
- EncoderOptionsRepositoryInterface::class,
154
- EncodersRepositoryInterface::class,
155
- DecodersRepositoryInterface::class,
156
- CodecMatcherRepositoryInterface::class,
157
- CurrentRequestInterface::class,
158
- NativeResponsesInterface::class,
159
- ResponsesInterface::class,
160
- ExceptionThrowerInterface::class,
161
- RendererInterface::class,
162
- RendererContainerInterface::class,
163
- ];
164
- }
165
-
166
151
/**
167
152
* @param $key
168
153
* @param $default
@@ -174,7 +159,7 @@ protected function getConfig($key, $default = null)
174
159
$ config = $ this ->app ->make ('config ' );
175
160
$ key = sprintf ('%s.%s ' , C::NAME , $ key );
176
161
177
- return ( array ) $ config ->get ($ key , $ default );
162
+ return $ config ->get ($ key , $ default );
178
163
}
179
164
180
165
}
0 commit comments