diff --git a/src/Attributes/LodataProperty.php b/src/Attributes/LodataProperty.php index 63c5bd7db..67e8f6c44 100644 --- a/src/Attributes/LodataProperty.php +++ b/src/Attributes/LodataProperty.php @@ -6,6 +6,7 @@ use Flat3\Lodata\Annotation\Core\V1\Computed; use Flat3\Lodata\Annotation\Core\V1\Description; +use Flat3\Lodata\Annotation\Core\V1\Immutable; use Flat3\Lodata\DeclaredProperty; use Flat3\Lodata\EntitySet; use Flat3\Lodata\Property; @@ -18,6 +19,7 @@ abstract class LodataProperty protected ?string $source = null; protected bool $key = false; protected bool $computed = false; + protected bool $immutable = false; protected bool $nullable = true; protected ?int $maxLength = null; protected ?int $precision = null; @@ -38,13 +40,15 @@ public function __construct( $scale = null, $alternativeKey = false, $searchable = false, - $filterable = true + $filterable = true, + ?bool $immutable = false ) { $this->name = $name; $this->description = $description; $this->source = $source; $this->key = $key; $this->computed = $computed; + $this->immutable = $immutable; $this->nullable = $nullable; $this->maxLength = $maxLength; $this->precision = $precision; @@ -84,6 +88,11 @@ public function isComputed(): bool return $this->computed; } + public function isImmutable(): bool + { + return $this->immutable; + } + public function isNullable(): bool { return $this->nullable && !$this->key; @@ -158,6 +167,10 @@ public function addProperty(EntitySet $entitySet): Property $property->addAnnotation(new Computed); } + if ($this->isImmutable()) { + $property->addAnnotation(new Immutable); + } + if ($this->hasMaxLength()) { $property->setMaxLength($this->getMaxLength()); } @@ -178,4 +191,4 @@ public function addProperty(EntitySet $entitySet): Property } abstract public function getType(): Type; -} \ No newline at end of file +} diff --git a/src/Drivers/EloquentEntitySet.php b/src/Drivers/EloquentEntitySet.php index 3a8560585..122adfb58 100644 --- a/src/Drivers/EloquentEntitySet.php +++ b/src/Drivers/EloquentEntitySet.php @@ -151,9 +151,7 @@ public function getModelByKey(PropertyValue $key): ?Model */ public function getTable(): string { - $model = $this->getModel(); - - return $model->getTable(); + return $this->getModel()->getTable(); } /** @@ -168,7 +166,7 @@ public function getConnection(): ConnectionInterface /** * Read an Eloquent model * @param PropertyValue $key Model key - * @return Entity|null Entity + * @return Entity Entity */ public function read(PropertyValue $key): Entity { @@ -258,6 +256,10 @@ public function delete(PropertyValue $key): void { $model = $this->getModelByKey($key); + if (null === $model) { + throw new NotFoundException('entity_not_found', 'Entity not found'); + } + try { $model->delete(); } catch (Exception $e) { diff --git a/src/GeneratedProperty.php b/src/GeneratedProperty.php index 4915b4965..e078d18bf 100644 --- a/src/GeneratedProperty.php +++ b/src/GeneratedProperty.php @@ -16,7 +16,7 @@ abstract class GeneratedProperty extends Property /** * Generate the property value for this property on the provided entity * @param ComplexValue $value Entity this property is generated on - * @return PropertyValue + * @return Primitive|scalar|null */ abstract public function invoke(ComplexValue $value);