CastWith
This commit is contained in:
parent
bef42b3352
commit
afb47c1977
7 changed files with 56 additions and 26 deletions
|
|
@ -4,6 +4,8 @@ declare(strict_types=1);
|
|||
|
||||
namespace Icefox\DTO\Support;
|
||||
|
||||
use Icefox\DTO\Attributes\CastWith;
|
||||
use Icefox\DTO\Config;
|
||||
use Icefox\DTO\Attributes\FromMapper;
|
||||
use Icefox\DTO\ParameterMeta;
|
||||
use Illuminate\Support\Facades\App;
|
||||
|
|
@ -139,7 +141,7 @@ class RuleFactory
|
|||
}
|
||||
|
||||
if ($type instanceof ReflectionNamedType && $name = $type->getName()) {
|
||||
if ($globalRules = config('dto.rules.' . $name)) {
|
||||
if ($globalRules = Config::getRules($name)) {
|
||||
foreach ($globalRules($parameter->reflection, $parameter->tag->getType()) as $scopedPrefix => $values) {
|
||||
$realPrefix = $root . $scopedPrefix;
|
||||
$rules[$realPrefix] = array_values(array_unique(array_merge($rules[$realPrefix] ?? [], $values)));
|
||||
|
|
@ -166,7 +168,7 @@ class RuleFactory
|
|||
}
|
||||
}
|
||||
|
||||
foreach ($parameter->reflection->getAttributes(FromMapper::class) as $attr) {
|
||||
foreach ($parameter->reflection->getAttributes(CastWith::class) as $attr) {
|
||||
$mapperClass = $attr->newInstance()->class;
|
||||
if (method_exists($mapperClass, 'rules')) {
|
||||
$subRules = App::call("$mapperClass@rules");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue