Skip to content

Commit ed2b2b3

Browse files
committed
Integrating Endpoint Handling
1 parent 23c1232 commit ed2b2b3

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

src/Endpoint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Endpoint
2121

2222
public function __construct(string $serviceUri)
2323
{
24-
$this->serviceUri = rtrim($serviceUri, '/');
24+
$this->serviceUri = trim($serviceUri, '/');
2525

2626
$prefix = rtrim(config('lodata.prefix'), '/');
2727
$this->route = ('' === $serviceUri)

src/ServiceProvider.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Flat3\Lodata\Helper\Flysystem;
1515
use Flat3\Lodata\Helper\DBAL;
1616
use Flat3\Lodata\Helper\Symfony;
17-
use Illuminate\Database\ConnectionInterface;
1817
use Illuminate\Foundation\Application;
1918
use Illuminate\Support\Facades\Route;
2019
use Symfony\Component\HttpKernel\Kernel;
@@ -51,13 +50,12 @@ public function boot()
5150
$segments = explode('/', request()->path());
5251

5352
// we only kick off operation when path prefix is configured in lodata.php
54-
// as all requests share the same root configuration
53+
// and bypass all other routes for performance
5554
if ($segments[0] === config('lodata.prefix')) {
5655

5756
// next look up the configured service endpoints
5857
$serviceUris = config('lodata.endpoints', []);
5958

60-
$service = null;
6159
if (0 === sizeof($serviceUris)) {
6260
// when no locators are defined, fallback to global mode; this will
6361
// ensure compatibility with prior versions of this package
@@ -68,10 +66,9 @@ public function boot()
6866
$service = new $clazz($segments[1]);
6967
}
7068
else {
71-
// when no service definition is configured for the path segment,
72-
// we abort with an error condition; typically a dev working on
73-
// setting up his project
74-
abort('No odata service endpoint defined for path ' . $segments[1]);
69+
// when no service definition could be found for the path segment,
70+
// we assume global scope
71+
$service = new Endpoint('');
7572
}
7673

7774
$this->bootServices($service);
@@ -87,6 +84,10 @@ private function bootServices($service): void
8784
// app()->make(ODataService::class)->endpoint()
8885
$this->app->instance(Endpoint::class, $service);
8986

87+
$this->app->bind(DBAL::class, function (Application $app, array $args) {
88+
return version_compare(InstalledVersions::getVersion('doctrine/dbal'), '4.0.0', '>=') ? new DBAL\DBAL4($args['connection']) : new DBAL\DBAL3($args['connection']);
89+
});
90+
9091
$this->loadJsonTranslationsFrom(__DIR__.'/../lang');
9192

9293
// next instantiate and discover the global Model
@@ -109,10 +110,6 @@ private function bootServices($service): void
109110
return class_exists('League\Flysystem\Adapter\Local') ? new Flysystem\Flysystem1() : new Flysystem\Flysystem3();
110111
});
111112

112-
$this->app->bind(DBAL::class, function (Application $app, array $args) {
113-
return version_compare(InstalledVersions::getVersion('doctrine/dbal'), '4.0.0', '>=') ? new DBAL\DBAL4($args['connection']) : new DBAL\DBAL3($args['connection']);
114-
});
115-
116113
$route = $service->route();
117114
$middleware = config('lodata.middleware', []);
118115

0 commit comments

Comments
 (0)