PHP code example of wazum / nullable-embeddable-bundle
1. Go to this page and download the library: Download wazum/nullable-embeddable-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
wazum / nullable-embeddable-bundle example snippets
use Doctrine\ORM\Mapping as ORM;
#[ORM\Embeddable]
final class EmailAddress
{
#[ORM\Column(type: 'string', length: 255, nullable: true)]
public readonly ?string $address = null;
// ... constructor and methods
}
use Wazum\NullableEmbeddableBundle\Attribute\ContainsNullableEmbeddable;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
#[ContainsNullableEmbeddable]
class User
{
#[ORM\Embedded(class: EmailAddress::class)]
private ?EmailAddress $emailAddress = null;
// ... constructor and methods
}
use Wazum\NullableEmbeddableBundle\Attribute\ContainsNullableEmbeddable;
use Wazum\NullableEmbeddableBundle\Attribute\NullableEmbedded;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
#[ContainsNullableEmbeddable]
class User
{
#[ORM\Embedded(class: EmailAddress::class)]
#[NullableEmbedded]
private $emailAddress = null;
// ... constructor and methods
}
$user = new User(
emailAddress: new EmailAddress(address: null)
);
$entityManager->persist($user);
$entityManager->flush();
$entityManager->clear();
// When reloading:
$user = $entityManager->find(User::class, $user->getId());
$user->getEmailAddress(); // Returns null, not an EmailAddress instance with null values
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.