Skip to content

Commit

Permalink
Add skip_null_values documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Korbeil committed Mar 5, 2021
1 parent a2a6461 commit 42e919f
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions components/AutoMapper.rst
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,37 @@ This will use automatically the TransformerFactory.

.. _`an example in the AutoMapper tests files`: https://github.com/janephp/janephp/tree/next/src/AutoMapper/Tests/Fixtures/Transformer

Skip null values
~~~~~~~~~~~~~~~~

This context option allows us to ignore ``null`` values from source attributes. So if we use that option and our target
object has a value, it will keep it.

Here is a quick example::

class Input
{
public ?string $name = null;
}

class MyEntity
{
private string $name;
public function setName(string $name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}

$myEntity = new MyEntity();
$myEntity->setName('foobar');
$input = new Input();

$autoMapper->map($input, $myEntity, ['skip_null_values' => true]);
echo $myEntity->getName(); // "foobar"

Implementation
--------------

Expand Down

0 comments on commit 42e919f

Please sign in to comment.