Skip to content

Commit f1fd518

Browse files
27pchrislmgerzabek
authored andcommitted
WIP rebased
1 parent d5f9a33 commit f1fd518

File tree

1 file changed

+30
-26
lines changed

1 file changed

+30
-26
lines changed

src/ServiceProvider.php

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,36 @@
1414
use Flat3\Lodata\Helper\Flysystem;
1515
use Flat3\Lodata\Helper\DBAL;
1616
use Flat3\Lodata\Helper\Symfony;
17+
use Illuminate\Database\ConnectionInterface;
1718
use Illuminate\Foundation\Application;
1819
use Illuminate\Support\Facades\Route;
1920
use Symfony\Component\HttpKernel\Kernel;
2021

2122
/**
2223
* Service Provider
23-
*
24-
* https://<server>:<port>/<prefix>/<service-uri>/$metadata
25-
*
2624
* @link https://laravel.com/docs/8.x/providers
2725
* @package Flat3\Lodata
2826
*/
2927
class ServiceProvider extends \Illuminate\Support\ServiceProvider
3028
{
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+
3147
/**
3248
* Service provider registration method
3349
*/
@@ -44,32 +60,16 @@ public function boot()
4460
if ($this->app->runningInConsole()) {
4561
$this->publishes([__DIR__.'/../config.php' => config_path('lodata.php')], 'config');
4662
}
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-
});
6163

6264
$this->loadJsonTranslationsFrom(__DIR__.'/../lang');
6365

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+
});
7069

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+
});
7373

7474
$this->app->bind(Response::class, function () {
7575
return Kernel::VERSION_ID < 60000 ? new Symfony\Response5() : new Symfony\Response6();
@@ -79,7 +79,11 @@ private function bootServices(Endpoint $service): void
7979
return class_exists('League\Flysystem\Adapter\Local') ? new Flysystem\Flysystem1() : new Flysystem\Flysystem3();
8080
});
8181

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();
8387
$middleware = config('lodata.middleware', []);
8488

8589
Route::get("{$route}/_lodata/odata.pbids", [PBIDS::class, 'get']);

0 commit comments

Comments
 (0)