Skip to content

Commit

Permalink
Eloquent properties can be annotated as immutable
Browse files Browse the repository at this point in the history
  • Loading branch information
yvo-niedrich committed Jul 17, 2024
1 parent 7177585 commit 10f265c
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/Attributes/LodataProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
Expand All @@ -178,4 +191,4 @@ public function addProperty(EntitySet $entitySet): Property
}

abstract public function getType(): Type;
}
}

0 comments on commit 10f265c

Please sign in to comment.