Skip to content

Commit 064b21a

Browse files
committed
feat: created idea of checkers and extenders for matcher
1 parent b95d730 commit 064b21a

6 files changed

+103
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PBaszak\UltraMapper\Mapper\Domain\Matcher\Contract;
6+
7+
use PBaszak\UltraMapper\Blueprint\Application\Model\Blueprint;
8+
use PBaszak\UltraMapper\Mapper\Application\Model\Context;
9+
use PBaszak\UltraMapper\Mapper\Domain\Matcher\Exception\BlueprintCheckerException;
10+
use PBaszak\UltraMapper\Mapper\Domain\Model\Process;
11+
12+
interface BlueprintCheckerInterface
13+
{
14+
/**
15+
* @throws BlueprintCheckerException
16+
*/
17+
public function check(Blueprint $blueprint, Process $process, Context $context): void;
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PBaszak\UltraMapper\Mapper\Domain\Matcher\Contract;
6+
7+
use PBaszak\UltraMapper\Blueprint\Application\Model\Blueprint;
8+
use PBaszak\UltraMapper\Mapper\Application\Model\Context;
9+
use PBaszak\UltraMapper\Mapper\Domain\Matcher\Exception\BlueprintExtenderException;
10+
use PBaszak\UltraMapper\Mapper\Domain\Model\Process;
11+
12+
interface BlueprintExtenderInterface
13+
{
14+
/**
15+
* @throws BlueprintExtenderException
16+
*/
17+
public function extend(Blueprint $blueprint, Process $process, Context $context): void;
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PBaszak\UltraMapper\Mapper\Domain\Matcher\Exception;
6+
7+
use PBaszak\UltraMapper\Shared\Application\Exception\UltraMapperException;
8+
9+
class BlueprintCheckerException extends UltraMapperException
10+
{
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PBaszak\UltraMapper\Mapper\Domain\Matcher\Exception;
6+
7+
use PBaszak\UltraMapper\Shared\Application\Exception\UltraMapperException;
8+
9+
class BlueprintExtenderException extends UltraMapperException
10+
{
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PBaszak\UltraMapper\Mapper\Domain\Matcher\Extender;
6+
7+
use PBaszak\UltraMapper\Blueprint\Application\Model\Assets\ClassBlueprint;
8+
use PBaszak\UltraMapper\Blueprint\Application\Model\Assets\PropertyBlueprint;
9+
use PBaszak\UltraMapper\Blueprint\Application\Model\Blueprint;
10+
use PBaszak\UltraMapper\Mapper\Application\Model\Context;
11+
use PBaszak\UltraMapper\Mapper\Domain\Matcher\Contract\BlueprintExtenderInterface;
12+
use PBaszak\UltraMapper\Mapper\Domain\Model\Process;
13+
14+
class DiscriminatorExtender implements BlueprintExtenderInterface
15+
{
16+
private Blueprint $blueprint;
17+
18+
public function extend(Blueprint $blueprint, Process $process, Context $context): void
19+
{
20+
$this->blueprint = $blueprint;
21+
22+
array_walk(
23+
$blueprint->blueprints,
24+
fn (ClassBlueprint $classBlueprint) => $this->handleClassBlueprint($classBlueprint, $process, $context)
25+
);
26+
}
27+
28+
private function handleClassBlueprint(ClassBlueprint $blueprint, Process $process, Context $context): void
29+
{
30+
/** @var PropertyBlueprint $property */
31+
foreach ($blueprint->properties as $property) {
32+
33+
}
34+
}
35+
}

src/Mapper/Domain/Matcher/Matcher.php

+10
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use PBaszak\UltraMapper\Mapper\Domain\Matcher\Contract\ClassMatchingStrategy;
1414
use PBaszak\UltraMapper\Mapper\Domain\Matcher\Contract\MatcherInterface;
1515
use PBaszak\UltraMapper\Mapper\Domain\Matcher\Contract\PropertyMatchingStrategy;
16+
use PBaszak\UltraMapper\Mapper\Domain\Matcher\Service\DiscriminatorService;
1617
use PBaszak\UltraMapper\Mapper\Domain\Matcher\Service\LoopDetector;
1718
use PBaszak\UltraMapper\Mapper\Domain\Model\Process;
1819
use Symfony\Component\Uid\Uuid;
@@ -52,6 +53,7 @@ public function matchBlueprints(
5253
Blueprint $target
5354
): void {
5455
$blueprints = [$origin, $source, $target];
56+
5557
$this->checkForLoop($context, $process, $blueprints);
5658
$this->addLinks(...$blueprints);
5759
array_walk($blueprints, fn (Blueprint $blueprint): ClassBlueprint => $blueprint->blueprints[$blueprint->root]);
@@ -221,6 +223,14 @@ protected function isPropertyIgnored(Context $context, Process $process, Propert
221223
return false;
222224
}
223225

226+
/**
227+
* @param Blueprint[] $blueprints
228+
*/
229+
protected function checkForMultipleClasses(Context $context, Process $process, array $blueprints): void
230+
{
231+
array_walk($blueprints, fn (Blueprint $blueprint) => (new DiscriminatorService())->checkBlueprint($blueprint, $process));
232+
}
233+
224234
/**
225235
* @param Blueprint[] $blueprints
226236
*/

0 commit comments

Comments
 (0)