Skip to content

Commit 5da7eed

Browse files
committed
Back to Endpoint discovery only
1 parent 3a74af9 commit 5da7eed

File tree

9 files changed

+26
-99
lines changed

9 files changed

+26
-99
lines changed

src/Annotation.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use Flat3\Lodata\Type\Byte;
1414
use Flat3\Lodata\Type\Collection;
1515
use Flat3\Lodata\Type\Enum;
16-
use Flat3\Lodata\Type\PropertyPath;
1716
use Flat3\Lodata\Type\String_;
1817
use SimpleXMLElement;
1918

@@ -59,10 +58,6 @@ public function appendJsonValue($value)
5958
case $value instanceof Record:
6059
$record = (object) [];
6160

62-
if (method_exists($value, 'getTypeName') && $value->getTypeName()) {
63-
$record->{'@type'} = $value->getTypeName();
64-
}
65-
6661
/** @var PropertyValue $propertyValue */
6762
foreach ($value as $propertyValue) {
6863
$record->{$propertyValue->getProperty()->getName()} = $this->appendJsonValue($propertyValue->getPrimitive());
@@ -114,10 +109,6 @@ protected function appendXmlValue(SimpleXMLElement $element, $value)
114109
$element->addAttribute('Int', $value->toUrl());
115110
break;
116111

117-
case $value instanceof PropertyPath:
118-
$element->addAttribute('PropertyPath', $value->get());
119-
break;
120-
121112
case $value instanceof String_:
122113
$element->addAttribute('String', $value->get());
123114
break;
@@ -156,10 +147,6 @@ protected function appendXmlValue(SimpleXMLElement $element, $value)
156147
protected function appendXmlRecord(SimpleXMLElement $element, Record $record)
157148
{
158149
$recordElement = $element->addChild('Record');
159-
$identifier = $record->getIdentifier();
160-
if (!is_null($identifier)) {
161-
$recordElement->addAttribute('Type', $identifier->getQualifiedName());
162-
}
163150

164151
/** @var PropertyValue $propertyValue */
165152
foreach ($record as $propertyValue) {

src/Annotation/Capabilities/V1/Reference.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@ class Reference extends \Flat3\Lodata\Annotation\Reference
1212
{
1313
protected $uri = 'https://oasis-tcs.github.io/odata-vocabularies/vocabularies/Org.OData.Capabilities.V1';
1414
protected $namespace = 'Org.OData.Capabilities.V1';
15-
protected $alias = 'Capabilities';
1615
}

src/Annotation/Core/V1/Reference.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@ class Reference extends \Flat3\Lodata\Annotation\Reference
1212
{
1313
protected $uri = 'https://oasis-tcs.github.io/odata-vocabularies/vocabularies/Org.OData.Core.V1';
1414
protected $namespace = 'Org.OData.Core.V1';
15-
protected $alias = 'Core';
1615
}

src/Annotation/Record.php

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Flat3\Lodata\Annotation;
66

7-
use Flat3\Lodata\Helper\Identifier;
87
use Flat3\Lodata\Helper\ObjectArray;
98
use Flat3\Lodata\Interfaces\TypeInterface;
109
use Flat3\Lodata\Traits\HasComplexType;
@@ -17,31 +16,4 @@
1716
class Record extends ObjectArray implements TypeInterface
1817
{
1918
use HasComplexType;
20-
21-
/**
22-
* Resource identifier
23-
* @var Identifier $identifier
24-
*/
25-
protected $identifier;
26-
27-
/**
28-
* Get the identifier
29-
* @return Identifier Identifier
30-
*/
31-
public function getIdentifier(): ?Identifier
32-
{
33-
return $this->identifier;
34-
}
35-
36-
/**
37-
* Set the identifier
38-
* @param string|Identifier $identifier Identifier
39-
* @return $this
40-
*/
41-
public function setIdentifier($identifier): Record
42-
{
43-
$this->identifier = $identifier instanceof Identifier ? $identifier : new Identifier($identifier);
44-
45-
return $this;
46-
}
4719
}

src/Annotation/Reference.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,6 @@ class Reference
3333
*/
3434
protected $alias;
3535

36-
public function getUri(): string
37-
{
38-
return $this->uri;
39-
}
40-
41-
public function getNamespace(): string
42-
{
43-
return $this->namespace;
44-
}
45-
46-
public function getAlias(): string
47-
{
48-
return is_null($this->alias) ? $this->namespace : $this->alias;
49-
}
50-
5136
/**
5237
* Append this reference to the provided XML element
5338
* @param SimpleXMLElement $schema Schema

src/Drivers/EloquentEntitySet.php

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
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;
2423
use Flat3\Lodata\Entity;
2524
use Flat3\Lodata\EntitySet;
2625
use Flat3\Lodata\EntityType;
@@ -33,7 +32,6 @@
3332
use Flat3\Lodata\Helper\JSON;
3433
use Flat3\Lodata\Helper\PropertyValue;
3534
use Flat3\Lodata\Helper\PropertyValues;
36-
use Flat3\Lodata\Interfaces\AnnotationFactoryInterface;
3735
use Flat3\Lodata\Interfaces\EntitySet\ComputeInterface;
3836
use Flat3\Lodata\Interfaces\EntitySet\CountInterface;
3937
use Flat3\Lodata\Interfaces\EntitySet\CreateInterface;
@@ -112,8 +110,7 @@ public function __construct(string $model, ?EntityType $entityType = null)
112110

113111
$name = self::convertClassName($model);
114112
if (!$entityType) {
115-
$identifier = app(Endpoint::class)->getNamespace().'.'.EntityType::convertClassName($model);
116-
$entityType = new EntityType($identifier);
113+
$entityType = new EntityType(EntityType::convertClassName($model));
117114
}
118115

119116
parent::__construct($name, $entityType);
@@ -790,28 +787,30 @@ public function discover(): self
790787
}
791788

792789
/** @var ReflectionMethod $reflectionMethod */
793-
foreach (Discovery::getReflectedMethods($this->model) as $reflectionMethod)
794-
foreach ($reflectionMethod->getAttributes() as $attribute) {
795-
796-
$instance = $attribute->newInstance();
797-
if ($instance instanceof LodataRelationship) {
798-
$relationshipMethod = $reflectionMethod->getName();
799-
800-
try {
801-
$this->discoverRelationship(
802-
$relationshipMethod,
803-
$instance->getName(),
804-
$instance->getDescription(),
805-
$instance->isNullable()
806-
);
807-
} catch (ConfigurationException $e) {
808-
}
809-
}
810-
else if ($instance instanceof AnnotationFactoryInterface) {
811-
$this->addAnnotation($instance->toAnnotation());
812-
}
790+
foreach (Discovery::getReflectedMethods($this->model) as $reflectionMethod) {
791+
/** @var LodataRelationship $relationshipInstance */
792+
$relationshipInstance = Discovery::getFirstMethodAttributeInstance(
793+
$reflectionMethod,
794+
LodataRelationship::class
795+
);
796+
797+
if (!$relationshipInstance) {
798+
continue;
813799
}
814800

801+
$relationshipMethod = $reflectionMethod->getName();
802+
803+
try {
804+
$this->discoverRelationship(
805+
$relationshipMethod,
806+
$relationshipInstance->getName(),
807+
$relationshipInstance->getDescription(),
808+
$relationshipInstance->isNullable()
809+
);
810+
} catch (ConfigurationException $e) {
811+
}
812+
}
813+
815814
return $this;
816815
}
817816
}

src/Facades/Lodata.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
* @method static ComplexType getComplexType(Identifier|string $name) Get a complex type from the model
4747
* @method static Singleton getSingleton(Identifier|string $name) Get a singleton from the model
4848
* @method static IdentifierInterface add(IdentifierInterface $item) Add a named resource or type to the model
49-
* @method static Model addReference(Reference $reference) Add a reference to an external CSDL document
5049
* @method static Model drop(Identifier|string $key) Drop a named resource or type from the model
5150
* @method static EntityContainer getEntityContainer() Get the entity container
5251
* @method static string getNamespace() Get the namespace of this model

src/Helper/Identifier.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ final class Identifier
2626
*/
2727
private $namespace;
2828

29-
/**
30-
* @var string $alias
31-
*/
32-
private $alias;
33-
3429
public function __construct(string $identifier)
3530
{
3631
if (!Str::contains($identifier, '.')) {
@@ -43,14 +38,6 @@ public function __construct(string $identifier)
4338

4439
$this->name = Str::afterLast($identifier, '.');
4540
$this->namespace = Str::beforeLast($identifier, '.');
46-
47-
// NB dirty hack to derive alias from namespace
48-
if (preg_match('/\.([^.]+)\.V1$/', $this->namespace, $matches)) {
49-
$this->alias = $matches[1];
50-
}
51-
else {
52-
$this->alias = $this->namespace;
53-
}
5441
}
5542

5643
/**
@@ -111,7 +98,7 @@ public function setNamespace(string $namespace): self
11198
*/
11299
public function getQualifiedName(): string
113100
{
114-
return $this->alias.'.'.$this->name;
101+
return $this->namespace.'.'.$this->name;
115102
}
116103

117104
/**

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()->getName());
242+
$resourceElement->addAttribute('Name', $resource->getIdentifier()->getResolvedName($namespace));
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()->getName());
249+
$resourceElement->addAttribute('Name', $resource->getIdentifier()->getResolvedName($namespace));
250250
$resourceElement->addAttribute(
251251
'EntityType',
252252
$resource->getType()->getIdentifier()->getQualifiedName()

0 commit comments

Comments
 (0)