14
14
use Flat3 \Lodata \Helper \Flysystem ;
15
15
use Flat3 \Lodata \Helper \DBAL ;
16
16
use Flat3 \Lodata \Helper \Symfony ;
17
+ use Illuminate \Database \ConnectionInterface ;
17
18
use Illuminate \Foundation \Application ;
18
19
use Illuminate \Support \Facades \Route ;
19
20
use Symfony \Component \HttpKernel \Kernel ;
20
21
21
22
/**
22
23
* Service Provider
23
- *
24
- * https://<server>:<port>/<prefix>/<service-uri>/$metadata
25
- *
26
24
* @link https://laravel.com/docs/8.x/providers
27
25
* @package Flat3\Lodata
28
26
*/
29
27
class ServiceProvider extends \Illuminate \Support \ServiceProvider
30
28
{
29
+ /**
30
+ * Get the endpoint of the OData service document
31
+ * @return string
32
+ */
33
+ public static function endpoint (): string
34
+ {
35
+ return url (self ::route ()).'/ ' ;
36
+ }
37
+
38
+ /**
39
+ * Get the configured route prefix
40
+ * @return string
41
+ */
42
+ public static function route (): string
43
+ {
44
+ return rtrim (config ('lodata.prefix ' ), '/ ' );
45
+ }
46
+
31
47
/**
32
48
* Service provider registration method
33
49
*/
@@ -44,32 +60,16 @@ public function boot()
44
60
if ($ this ->app ->runningInConsole ()) {
45
61
$ this ->publishes ([__DIR__ .'/../config.php ' => config_path ('lodata.php ' )], 'config ' );
46
62
}
47
- $ this ->bootServices (new Endpoint ('' ));
48
- }
49
-
50
- private function bootServices (Endpoint $ service ): void
51
- {
52
- // register the $service, which is a singleton, with the container; this allows us
53
- // to fulfill all old ServiceProvider::route() and ServiceProvider::endpoint()
54
- // calls with app()->make(ODataService::class)->route() or
55
- // app()->make(ODataService::class)->endpoint()
56
- $ this ->app ->instance (Endpoint::class, $ service );
57
-
58
- $ this ->app ->bind (DBAL ::class, function (Application $ app , array $ args ) {
59
- return version_compare (InstalledVersions::getVersion ('doctrine/dbal ' ), '4.0.0 ' , '>= ' ) ? new DBAL \DBAL4 ($ args ['connection ' ]) : new DBAL \DBAL3 ($ args ['connection ' ]);
60
- });
61
63
62
64
$ this ->loadJsonTranslationsFrom (__DIR__ .'/../lang ' );
63
65
64
- // next instantiate and discover the global Model
65
- $ model = $ service ->discover (new Model ());
66
- assert ($ model instanceof Model);
67
-
68
- // and register it with the container
69
- $ this ->app ->instance (Model::class, $ model );
66
+ $ this ->app ->singleton (Model::class, function () {
67
+ return new Model ();
68
+ });
70
69
71
- // register alias
72
- $ this ->app ->alias (Model::class, 'lodata.model ' );
70
+ $ this ->app ->bind ('lodata.model ' , function ($ app ) {
71
+ return $ app ->make (Model::class);
72
+ });
73
73
74
74
$ this ->app ->bind (Response::class, function () {
75
75
return Kernel::VERSION_ID < 60000 ? new Symfony \Response5 () : new Symfony \Response6 ();
@@ -79,7 +79,11 @@ private function bootServices(Endpoint $service): void
79
79
return class_exists ('League\Flysystem\Adapter\Local ' ) ? new Flysystem \Flysystem1 () : new Flysystem \Flysystem3 ();
80
80
});
81
81
82
- $ route = $ service ->route ();
82
+ $ this ->app ->bind (DBAL ::class, function (Application $ app , array $ args ) {
83
+ return version_compare (InstalledVersions::getVersion ('doctrine/dbal ' ), '4.0.0 ' , '>= ' ) ? new DBAL \DBAL4 ($ args ['connection ' ]) : new DBAL \DBAL3 ($ args ['connection ' ]);
84
+ });
85
+
86
+ $ route = self ::route ();
83
87
$ middleware = config ('lodata.middleware ' , []);
84
88
85
89
Route::get ("{$ route }/_lodata/odata.pbids " , [PBIDS ::class, 'get ' ]);
0 commit comments