Skip to content

Commit bedc6e9

Browse files
committed
Back to Endpoint discovery only
1 parent 4faa16a commit bedc6e9

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;
@@ -34,7 +33,6 @@
3433
use Flat3\Lodata\Helper\JSON;
3534
use Flat3\Lodata\Helper\PropertyValue;
3635
use Flat3\Lodata\Helper\PropertyValues;
37-
use Flat3\Lodata\Interfaces\AnnotationFactoryInterface;
3836
use Flat3\Lodata\Interfaces\EntitySet\ComputeInterface;
3937
use Flat3\Lodata\Interfaces\EntitySet\CountInterface;
4038
use Flat3\Lodata\Interfaces\EntitySet\CreateInterface;
@@ -116,8 +114,7 @@ public function __construct(string $model, ?EntityType $entityType = null)
116114

117115
$name = self::convertClassName($model);
118116
if (!$entityType) {
119-
$identifier = app(Endpoint::class)->getNamespace().'.'.EntityType::convertClassName($model);
120-
$entityType = new EntityType($identifier);
117+
$entityType = new EntityType(EntityType::convertClassName($model));
121118
}
122119

123120
parent::__construct($name, $entityType);
@@ -869,28 +866,30 @@ public function discover(): self
869866
}
870867

871868
/** @var ReflectionMethod $reflectionMethod */
872-
foreach (Discovery::getReflectedMethods($this->model) as $reflectionMethod)
873-
foreach ($reflectionMethod->getAttributes() as $attribute) {
874-
875-
$instance = $attribute->newInstance();
876-
if ($instance instanceof LodataRelationship) {
877-
$relationshipMethod = $reflectionMethod->getName();
878-
879-
try {
880-
$this->discoverRelationship(
881-
$relationshipMethod,
882-
$instance->getName(),
883-
$instance->getDescription(),
884-
$instance->isNullable()
885-
);
886-
} catch (ConfigurationException $e) {
887-
}
888-
}
889-
else if ($instance instanceof AnnotationFactoryInterface) {
890-
$this->addAnnotation($instance->toAnnotation());
891-
}
869+
foreach (Discovery::getReflectedMethods($this->model) as $reflectionMethod) {
870+
/** @var LodataRelationship $relationshipInstance */
871+
$relationshipInstance = Discovery::getFirstMethodAttributeInstance(
872+
$reflectionMethod,
873+
LodataRelationship::class
874+
);
875+
876+
if (!$relationshipInstance) {
877+
continue;
892878
}
893879

880+
$relationshipMethod = $reflectionMethod->getName();
881+
882+
try {
883+
$this->discoverRelationship(
884+
$relationshipMethod,
885+
$relationshipInstance->getName(),
886+
$relationshipInstance->getDescription(),
887+
$relationshipInstance->isNullable()
888+
);
889+
} catch (ConfigurationException $e) {
890+
}
891+
}
892+
894893
return $this;
895894
}
896895
}

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)