Skip to content

Commit 0296a8b

Browse files
committed
fix: separated mapper modules
1 parent df40b7a commit 0296a8b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+346
-298
lines changed

src/Blueprint/Application/Model/Assets/AttributeBlueprint.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
class AttributeBlueprint implements Normalizable
1212
{
13-
public ClassBlueprint|PropertyBlueprint $parent;
13+
public ClassBlueprint|ParameterBlueprint|PropertyBlueprint $parent;
1414

1515
/** @var class-string */
1616
public string $class;
@@ -20,7 +20,7 @@ class AttributeBlueprint implements Normalizable
2020
public false|string $filePath;
2121
public false|string $fileHash;
2222

23-
public static function create(\ReflectionAttribute $attribute, ClassBlueprint|PropertyBlueprint $parent): self
23+
public static function create(\ReflectionAttribute $attribute, ClassBlueprint|ParameterBlueprint|PropertyBlueprint $parent): self
2424
{
2525
$instance = new self();
2626
$instance->parent = $parent;

src/Blueprint/Application/Model/Type.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function getAllClassTypes(): array
5757
{
5858
$classTypes = [];
5959
$function = function ($type) use (&$classTypes) {
60-
if (class_exists($type)) {
60+
if (class_exists($type, false) || interface_exists($type, false)) {
6161
$classTypes[] = $type;
6262
}
6363
};

src/Build/Application/Model/Assets/ClassCard.php

-12
This file was deleted.

src/Build/Application/Model/Assets/ConstructorCard.php

-11
This file was deleted.

src/Build/Application/Model/Assets/ParameterCard.php

-9
This file was deleted.

src/Build/Application/Model/Assets/PropertyCard.php

-18
This file was deleted.

src/Build/Application/Model/Briefcase.php

-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99

1010
class Briefcase
1111
{
12-
/** @var Assets\ClassCard[] */
13-
public array $classes = [];
14-
1512
public function __construct(
1613
public Blueprint $origin,
1714
public TypeInterface $from,

src/Mapper/Application/Contract/ModificatorInterface.php

-34
This file was deleted.

src/Mapper/Application/Modifier/JMSSerializer.php

-11
This file was deleted.

src/Mapper/Application/Modifier/SymfonySerializer.php

-11
This file was deleted.

src/Mapper/Application/Modifier/SymfonyValidator.php

-11
This file was deleted.

src/Mapper/Application/Modifier/UltraMapper.php

-11
This file was deleted.

src/Mapper/Application/Service/Mapper.php

+18-9
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@
88
use PBaszak\UltraMapper\Blueprint\Application\Model\Blueprint;
99
use PBaszak\UltraMapper\Build\Application\Contract\BuilderInterface;
1010
use PBaszak\UltraMapper\Mapper\Application\Contract\MapperInterface;
11-
use PBaszak\UltraMapper\Mapper\Application\Contract\ModificatorInterface;
1211
use PBaszak\UltraMapper\Mapper\Application\Contract\TypeInterface;
1312
use PBaszak\UltraMapper\Mapper\Application\Model\Context;
1413
use PBaszak\UltraMapper\Mapper\Application\Model\Envelope;
1514
use PBaszak\UltraMapper\Mapper\Domain\Contract\ClassMapperInterface;
15+
use PBaszak\UltraMapper\Mapper\Domain\Modules;
1616
use PBaszak\UltraMapper\Mapper\Domain\Resolver\MapperResolver;
1717
use PBaszak\UltraMapper\Mapper\Domain\Resolver\ProcessResolver;
18-
use PBaszak\UltraMapper\Mapper\Domain\Service\Matcher;
1918

2019
class Mapper implements MapperInterface
2120
{
@@ -38,10 +37,16 @@ class Mapper implements MapperInterface
3837
public bool $throwExceptionWhenMappingError = false;
3938

4039
public function __construct(
41-
protected BlueprintInterface $blueprint,
42-
protected BuilderInterface $build,
4340
protected MapperResolver $mapperResolver,
44-
protected ModificatorInterface $modificator,
41+
protected BlueprintInterface $blueprint,
42+
43+
// Build module - required for the mapper creation
44+
protected BuilderInterface $builder,
45+
// blueprint preparation modules - required for the mapper creation
46+
protected Modules\Checker\Contract\CheckerInterface $checker,
47+
protected Modules\Extender\Contract\ExtenderInterface $extender,
48+
protected Modules\Matcher\Contract\MatcherInterface $matcher,
49+
protected Modules\Modificator\Contract\ModificatorInterface $modificator,
4550
) {
4651
}
4752

@@ -78,13 +83,17 @@ protected function getMapper(
7883
$processType = (new ProcessResolver())->resolve($from, $to);
7984

8085
foreach ($blueprints as $processUse => $blueprint) {
81-
$this->modificator->prepareBlueprint($blueprint, $processType, $processUse);
82-
}
86+
do {
87+
$hasExtended = $this->extender->extend($blueprint, $processType, $context);
88+
$hasModified = $this->modificator->modify($blueprint, $processType, $context, $processUse);
89+
} while ($hasExtended || $hasModified);
8390

84-
(new Matcher())->matchBlueprints($context, $processType, ...$blueprints);
91+
$this->checker->check($blueprint, $processType, $context);
92+
}
8593

86-
// modify blueprints
94+
$this->matcher->matchBlueprints($context, $processType, ...$blueprints);
8795

96+
// not implemented yet
8897
// $build = $this->build->build(
8998
// $shortName,
9099
// $blueprints,

src/Mapper/Application/Service/Modificator.php

-38
This file was deleted.

src/Mapper/Application/Type/ClassObjectType.php

+2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ class ClassObjectType implements TypeInterface
3030
* @param bool $canUseDirectProperty Requires public properties. If the property is not public, it will be ignored.
3131
* @param bool $canUseConstructor Requires the parameters with the same name as the properties. You can use
3232
* #[TargetProperty] attribute on parameters to map them to the properties.
33+
* Recommended for the creation of the objects from the incoming data.
3334
* @param bool $canUseGettersAndSetters #[Accessor] attribute ignores this flag. If `true`, then
3435
* UltraMapper will search for the getter and setter methods.
3536
* @param bool $canUseReflectionClass Probably the slowest option but the most universal. Still is fast enough.
37+
* Recommended for recreation of the objects from persistence.
3638
*/
3739
public function __construct(
3840
/** @var class-string|null */

src/Mapper/Domain/Matcher/Contract/BlueprintExtenderInterface.php

-18
This file was deleted.

src/Mapper/Domain/Matcher/Exception/BlueprintCheckerException.php

-11
This file was deleted.

src/Mapper/Domain/Matcher/Exception/BlueprintExtenderException.php

-11
This file was deleted.

src/Mapper/Domain/Matcher/Service/DiscriminatorService.php

-28
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PBaszak\UltraMapper\Mapper\Domain\Modules\Checker;
6+
7+
use PBaszak\UltraMapper\Blueprint\Application\Model\Blueprint;
8+
use PBaszak\UltraMapper\Mapper\Application\Model\Context;
9+
use PBaszak\UltraMapper\Mapper\Domain\Model\Process;
10+
11+
class Checker implements Contract\CheckerInterface
12+
{
13+
/**
14+
* @param array<Contract\CheckerStrategyInterface> $strategies
15+
*/
16+
public function __construct(
17+
private array $strategies
18+
) {
19+
}
20+
21+
public function check(Blueprint $blueprint, Process $process, Context $context): void
22+
{
23+
foreach ($this->strategies as $strategy) {
24+
$strategy->check($blueprint, $process, $context);
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)