Skip to content

Commit 3a74af9

Browse files
committed
Qualify model with Endpoint->getNamespace()
1 parent ed2b2b3 commit 3a74af9

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

src/Drivers/EloquentEntitySet.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Flat3\Lodata\Drivers\SQL\SQLOrderBy;
2121
use Flat3\Lodata\Drivers\SQL\SQLSchema;
2222
use Flat3\Lodata\Drivers\SQL\SQLWhere;
23+
use Flat3\Lodata\Endpoint;
2324
use Flat3\Lodata\Entity;
2425
use Flat3\Lodata\EntitySet;
2526
use Flat3\Lodata\EntityType;
@@ -111,7 +112,8 @@ public function __construct(string $model, ?EntityType $entityType = null)
111112

112113
$name = self::convertClassName($model);
113114
if (!$entityType) {
114-
$entityType = new EntityType(EntityType::convertClassName($model));
115+
$identifier = app(Endpoint::class)->getNamespace().'.'.EntityType::convertClassName($model);
116+
$entityType = new EntityType($identifier);
115117
}
116118

117119
parent::__construct($name, $entityType);

src/Endpoint.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,22 @@ public function route(): string
4646
}
4747

4848
/**
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
57+
{
58+
// override this function to set Schema Namespace attribute
59+
return config('lodata.namespace');
60+
}
61+
62+
/**
63+
* This method is intended to be overridden by subclasses.
64+
*
4965
* Discovers Schema and Annotations of the `$metadata` file for
5066
* the service.
5167
*/

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 config('lodata.namespace');
202+
return app(Endpoint::class)->getNamespace();
203203
}
204204

205205
/**

src/PathSegment/Metadata/XML.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,14 +239,14 @@ public function emitStream(Transaction $transaction): void
239239
case $resource instanceof Singleton:
240240
// https://docs.oasis-open.org/odata/odata-csdl-xml/v4.01/odata-csdl-xml-v4.01.html#_Toc38530395
241241
$resourceElement = $entityContainer->addChild('Singleton');
242-
$resourceElement->addAttribute('Name', $resource->getIdentifier()->getResolvedName($namespace));
242+
$resourceElement->addAttribute('Name', $resource->getIdentifier()->getName());
243243
$resourceElement->addAttribute('Type', $resource->getType()->getIdentifier()->getQualifiedName());
244244
break;
245245

246246
case $resource instanceof EntitySet:
247247
// https://docs.oasis-open.org/odata/odata-csdl-xml/v4.01/odata-csdl-xml-v4.01.html#sec_EntitySet
248248
$resourceElement = $entityContainer->addChild('EntitySet');
249-
$resourceElement->addAttribute('Name', $resource->getIdentifier()->getResolvedName($namespace));
249+
$resourceElement->addAttribute('Name', $resource->getIdentifier()->getName());
250250
$resourceElement->addAttribute(
251251
'EntityType',
252252
$resource->getType()->getIdentifier()->getQualifiedName()

0 commit comments

Comments
 (0)