Skip to content

Commit 9f4f841

Browse files
committed
feat: Added support for Discriminator attribute
1 parent c0e6811 commit 9f4f841

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

src/Mapper/Domain/Modules/Extender/Strategy/DiscriminatorExtender.php

+12-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PBaszak\UltraMapper\Blueprint\Application\Model\Assets\ClassBlueprint;
88
use PBaszak\UltraMapper\Blueprint\Application\Model\Assets\PropertyBlueprint;
99
use PBaszak\UltraMapper\Blueprint\Application\Model\Blueprint;
10+
use PBaszak\UltraMapper\Mapper\Application\Attribute\Discriminator;
1011
use PBaszak\UltraMapper\Mapper\Application\Model\Context;
1112
use PBaszak\UltraMapper\Mapper\Domain\Model\Process;
1213
use PBaszak\UltraMapper\Mapper\Domain\Modules\Extender\Contract\ExtenderStrategyInterface;
@@ -18,21 +19,26 @@ class DiscriminatorExtender implements ExtenderStrategyInterface
1819

1920
public function extend(Blueprint $blueprint, Process $process, Context $context): bool
2021
{
21-
$this->extended = false;
2222
$this->blueprint = $blueprint;
23+
$this->extended = false;
2324

24-
array_walk(
25-
$blueprint->blueprints,
26-
fn (ClassBlueprint $classBlueprint) => $this->handleClassBlueprint($classBlueprint, $process, $context)
27-
);
25+
foreach ($process->processes as $processType) {
26+
array_walk(
27+
$blueprint->blueprints,
28+
fn (ClassBlueprint $classBlueprint) => $this->handleClassBlueprint($classBlueprint, $processType, $context)
29+
);
30+
}
2831

2932
return $this->extended;
3033
}
3134

32-
private function handleClassBlueprint(ClassBlueprint $blueprint, Process $process, Context $context): void
35+
private function handleClassBlueprint(ClassBlueprint $blueprint, string $process, Context $context): void
3336
{
3437
/** @var PropertyBlueprint $property */
3538
foreach ($blueprint->properties as $property) {
39+
if (empty($discriminatorAttr = $property->getAttributes(Discriminator::class, $process))) {
40+
continue;
41+
}
3642
}
3743
}
3844
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PBaszak\UltraMapper\Tests\Mapper\Unit\Domain\Modules\Checker;
6+
7+
use PHPUnit\Framework\Attributes\Group;
8+
use PHPUnit\Framework\TestCase;
9+
10+
#[Group('unit')]
11+
class DiscriminatorExtenderTest extends TestCase
12+
{
13+
}

0 commit comments

Comments
 (0)