Skip to content

Possibility to have both constructors and setters called #89

Closed Answered by romm
magnetik asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @magnetik, this library recommends objects immutability so it wont allow automatic setters calls; however if for some reason you need this kind of operation, you can use the object binding like below (there is no documentation yet because I'm not sure the current implementation will make it to v1.0):

(new \CuyZ\Valinor\MapperBuilder())
    ->bind(function (string $string, int $int, float $float): SomeClassWithSetter {
        $class = new SomeClassWithSetter($string, $int);
        $class->setFloat($float);

        return $class;
    })
    ->mapper()
    ->map(SomeClassWithSetter::class, [/* … */]);

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@magnetik
Comment options

@romm
Comment options

Answer selected by magnetik
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants