-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(transformer): fix property transformer with adder and remover met…
- Loading branch information
Showing
6 changed files
with
130 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AutoMapper\Tests\Fixtures\Issue111; | ||
|
||
class Colour | ||
{ | ||
public function __construct( | ||
public string $name | ||
) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AutoMapper\Tests\Fixtures\Issue111; | ||
|
||
use AutoMapper\Transformer\PropertyTransformer\PropertyTransformerInterface; | ||
|
||
class ColourTransformer implements PropertyTransformerInterface | ||
{ | ||
public function transform(mixed $value, object|array $source, array $context): mixed | ||
{ | ||
$colours = []; | ||
|
||
foreach ($value as $colour) { | ||
$colours[] = new Colour($colour); | ||
} | ||
|
||
return $colours; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AutoMapper\Tests\Fixtures\Issue111; | ||
|
||
class Foo | ||
{ | ||
private array $colours = []; | ||
|
||
public function getColours(): array | ||
{ | ||
return $this->colours; | ||
} | ||
|
||
public function addColour(Colour $colour): void | ||
{ | ||
$this->colours[] = $colour; | ||
} | ||
|
||
public function removeColour(Colour $colour): void | ||
{ | ||
$key = array_search($colour, $this->colours, true); | ||
|
||
if ($key !== false) { | ||
unset($this->colours[$key]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AutoMapper\Tests\Fixtures\Issue111; | ||
|
||
use AutoMapper\Attribute\MapTo; | ||
|
||
class FooDto | ||
{ | ||
#[MapTo(target: Foo::class, transformer: ColourTransformer::class)] | ||
public array $colours = []; | ||
} |