feat: DTO에 DefaultValue, DefaultValueGenerator 추가

This commit is contained in:
2022-05-28 15:53:06 +09:00
parent 08eae297fd
commit cb3982e57c
5 changed files with 150 additions and 13 deletions
+16
View File
@@ -0,0 +1,16 @@
<?php
namespace sammo\DTO\Attr;
#[\Attribute(\Attribute::TARGET_PROPERTY)]
class DefaultValue
{
public function __construct(public readonly null|bool|int|float|string|array $defaultValue)
{
}
public function getDefaultValue(): mixed
{
return $this->defaultValue;
}
}
@@ -0,0 +1,20 @@
<?php
namespace sammo\DTO\Attr;
#[\Attribute(\Attribute::TARGET_PROPERTY)]
class DefaultValueGenerator
{
public function __construct(public readonly string $generator)
{
if (!is_callable($generator)) {
throw new \Exception("$generator is not a callable");
}
}
public function getDefaultValue(): mixed
{
$generator = $this->generator;
return $generator();
}
}