feat: DTO에 Ignore 추가

This commit is contained in:
2022-05-28 16:12:54 +09:00
parent cb3982e57c
commit 7464629597
3 changed files with 51 additions and 0 deletions
+11
View File
@@ -0,0 +1,11 @@
<?php
namespace sammo\DTO\Attr;
#[\Attribute(\Attribute::TARGET_PROPERTY)]
class Ignore
{
public function __construct()
{
}
}
+11
View File
@@ -32,6 +32,13 @@ abstract class DTO
$param = $params[$name] ?? null;
if(key_exists(Attr\Ignore::class, $attrs)){
if($param !== null){
throw new \Exception("Property {$name} is ignored but has a constructor parameter");
}
continue;
}
if (key_exists(Attr\DefaultValueGenerator::class, $attrs)){
/** @var Attr\DefaultValueGenerator */
$defaultValueSetter = $attrs[Attr\DefaultValueGenerator::class]->newInstance();
@@ -113,6 +120,10 @@ abstract class DTO
$attrs = Util\Util::getAttrs($property);
$name = $property->getName();
if(key_exists(Attr\Ignore::class, $attrs)){
continue;
}
if (key_exists(Attr\RawName::class, $attrs)) {
$rawAttr = $attrs[Attr\RawName::class];
$attr = new Attr\RawName(...$rawAttr->getArguments());