Skip to content

Commit 44347d6

Browse files
committed
Introduced Interface for ServiceEndpoints
1 parent a67da0f commit 44347d6

File tree

3 files changed

+23
-80
lines changed

3 files changed

+23
-80
lines changed

src/Endpoint.php

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,14 @@
22

33
namespace Flat3\Lodata;
44

5-
class Endpoint
5+
use Flat3\Lodata\Interfaces\ServiceEndpointInterface;
6+
7+
class Endpoint implements ServiceEndpointInterface
68
{
7-
/**
8-
* @var string $serviceUri the &lt;service-uri> of the <code>Flat3\Lodata\Model</code>.
9-
*/
109
protected $serviceUri;
1110

12-
/**
13-
* @var string $route the route prefix configured in <code>'lodata.prefix'</code>
14-
*/
1511
protected $route;
1612

17-
/**
18-
* @var string $endpoint the full url to the ODataService endpoint
19-
*/
2013
protected $endpoint;
2114

2215
public function __construct(string $serviceUri)
@@ -31,10 +24,6 @@ public function __construct(string $serviceUri)
3124
$this->endpoint = url($this->route) . '/';
3225
}
3326

34-
/**
35-
* @return string the path within the odata URI space, like in
36-
* https://<server>:<port>/<config('lodata.prefix')>/<service-uri>/$metadata
37-
*/
3827
public function endpoint(): string
3928
{
4029
return $this->endpoint;
@@ -45,29 +34,18 @@ public function route(): string
4534
return $this->route;
4635
}
4736

48-
/**
49-
* This method is intended to be overridden by subclasses.
50-
*
51-
* The value of the function will be presented in the Schema Namespace attribute,
52-
* https://docs.oasis-open.org/odata/odata-csdl-xml/v4.01/odata-csdl-xml-v4.01.html#sec_Schema
53-
*
54-
* @return string
55-
*/
56-
public function getNamespace(): string
37+
public function namespace(): string
5738
{
58-
// override this function to set Schema Namespace attribute
5939
return config('lodata.namespace');
6040
}
6141

62-
/**
63-
* This method is intended to be overridden by subclasses.
64-
*
65-
* Discovers Schema and Annotations of the `$metadata` file for
66-
* the service.
67-
*/
42+
public function cachedMetadataXMLPath(): ?string
43+
{
44+
return null;
45+
}
46+
6847
public function discover(Model $model): Model
6948
{
70-
// override this function to register all of your $metadata capabilities
7149
return $model;
7250
}
7351
}

src/Interfaces/ServiceEndpointInterface.php

Lines changed: 13 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,68 +5,33 @@
55
use Flat3\Lodata\Model;
66

77
/**
8-
* Interface for defining a modular OData service endpoint in Laravel.
8+
* Interface for defining a custom OData service endpoint.
99
*
10-
* Implementers of this interface represent individually addressable OData services.
11-
* Each mounted under its own URI segment and backed by a schema model.
12-
*
13-
* This enables clean separation of business domains and supports multi-endpoint
14-
* discovery for modular application design.
15-
*
16-
* Configuration versus Declaration
17-
* --------------------------------
18-
* The public URI segment used to expose a service is NOT determined by the
19-
* implementing class itself, but by the service map in `config/lodata.php`:
20-
*
21-
* ```php
22-
* 'endpoints' => [
23-
* 'users' => \App\OData\UsersEndpoint::class,
24-
* 'budgets' => \App\OData\BudgetsEndpoint::class,
25-
* ]
26-
* ```
27-
*
28-
* This keeps the routing surface under application control, and avoids
29-
* conflicts when two modules declare the same internal segment.
30-
*
31-
* To implement an endpoint:
32-
* - Extend `Flat3\Lodata\Endpoint` or implement this interface directly
33-
* - Register the class in `config/lodata.php` under a unique segment key
34-
* - Define the `discover()` method to expose entities via OData
10+
* Implementers can use this interface to expose a specific service under a custom path,
11+
* define its namespace, route behavior, and optionally provide a statically generated
12+
* $metadata document.
3513
*/
3614
interface ServiceEndpointInterface
3715
{
38-
/**
39-
* Returns the ServiceURI segment name for this OData endpoint.
40-
*
41-
* This value is used in routing and metadata resolution. It Must be globally unique.
42-
*
43-
* @return string The segment (path identifier) of the endpoint
44-
*/
45-
public function serviceUri(): string;
4616

4717
/**
48-
* Returns the fully qualified URL for this OData endpoint.
18+
* Returns the relative endpoint identifier within the OData service URI space.
4919
*
50-
* This includes the application host, port, and the configured segment,
51-
* https://<server>:<port>/<config('lodata.prefix')>/<service-uri>/,
52-
* Example: https://example.com/odata/users/
20+
* This is the part that appears between the configured Lodata prefix and
21+
* the `$metadata` segment, e.g.:
22+
* https://<server>:<port>/<config('lodata.prefix')>/<endpoint>/$metadata
5323
*
54-
* This URL forms the base of the OData service space, and is used for navigation links
55-
* and metadata discovery.
56-
*
57-
* @return string The full URL of the service endpoint
24+
* @return string The relative OData endpoint path
5825
*/
5926
public function endpoint(): string;
6027

6128
/**
62-
* Returns the internal Laravel route path for this OData service endpoint.
63-
*
64-
* This is the relative URI path that Laravel uses to match incoming requests,
65-
* typically composed of the configured Lodata prefix and the service segment.
29+
* Returns the full request route to this service endpoint.
6630
*
67-
* Example: "odata/users"
31+
* This typically resolves to the route path used by Laravel to handle
32+
* incoming requests for this specific service instance.
6833
*
69-
* @return string Relative route path for the endpoint
34+
* @return string The full HTTP route to the endpoint
7035
*/
7136
public function route(): string;
7237

src/Model.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public function getTypeDefinition(string $name): ?Type
199199
*/
200200
public static function getNamespace(): string
201201
{
202-
return app(Endpoint::class)->getNamespace();
202+
return app(Endpoint::class)->namespace();
203203
}
204204

205205
/**

0 commit comments

Comments
 (0)