Skip to content

Commit

Permalink
Fix Dto
Browse files Browse the repository at this point in the history
  • Loading branch information
cesurapp committed Dec 15, 2023
1 parent a3f2034 commit 4ae3159
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions src/AbstractClass/ApiDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
/**
* Data Transfer Object for Validation.
*/
#[\AllowDynamicProperties]
abstract class ApiDto
{
public string|null $id = null;

protected bool $auto = true;

protected array $validated = [];
Expand All @@ -33,7 +32,7 @@ public function __construct(protected Request $request, protected ValidatorInter

// Append ID for Edit Request
if ($this->request->isMethod('PUT')) {
$this->id = $this->request->attributes->get('id', $this->request->attributes->get('uid'));
$this->id = $this->request->attributes->get('id'); // @phpstan-ignore-line
}

// Run Validate
Expand All @@ -52,7 +51,7 @@ public function getRequest(): Request
*
* @throws ValidationException
*/
final public function validate(bool $throw = false): bool
final public function validate(bool $throw = true): bool
{
// Start Validated
$this->beforeValidated();
Expand Down Expand Up @@ -130,18 +129,6 @@ public function initObject(string $object): mixed
return $object;
}

public function getId(): ?string
{
return $this->id;
}

public function setId(string $id): self
{
$this->id = $id;

return $this;
}

private function initProperties(array $fields): void
{
$refClass = new \ReflectionClass(static::class);
Expand Down Expand Up @@ -188,4 +175,11 @@ private function initProperties(array $fields): void
}
}
}

public function setProp(string $propName, mixed $value): self
{
$this->{$propName} = $value;

return $this;
}
}

0 comments on commit 4ae3159

Please sign in to comment.