Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HydratorStrategy extract empty value #42

Closed
eugene-borovov opened this issue Dec 5, 2020 · 2 comments · Fixed by #43
Closed

HydratorStrategy extract empty value #42

eugene-borovov opened this issue Dec 5, 2020 · 2 comments · Fixed by #43
Milestone

Comments

@eugene-borovov
Copy link
Contributor

Should we return NULL if the value is empty?

if (! $value instanceof $this->objectClassName) {

@froschdesign
Copy link
Member

This would be a BC break because the behaviour is changed.

But you are welcome to create a pull request.

See also #37

@eugene-borovov
Copy link
Contributor Author

I do not want something break )))
I decorated strategy with null check

use Laminas\Hydrator\Strategy\StrategyInterface;

class NullableStrategy implements StrategyInterface
{
    /** @var StrategyInterface */
    private $strategy;

    public function __construct(StrategyInterface $strategy)
    {
        $this->strategy = $strategy;
    }

    public function extract($value, ?object $object = null)
    {
        if ($value === null) {
            return null;
        }

        return $this->strategy->extract($value, $object);
    }

    public function hydrate($value, ?array $data = null)
    {
        if ($value === '' || $value === null) {
            return null;
        }

        return $this->strategy->hydrate($value, $data);
    }
}

@weierophinney weierophinney linked a pull request Dec 16, 2020 that will close this issue
@weierophinney weierophinney added this to the 4.1.0 milestone Dec 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants