PHP code example of biberlabs / ddd-embeddables

1. Go to this page and download the library: Download biberlabs/ddd-embeddables 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/ */

    

biberlabs / ddd-embeddables example snippets




namespace MyApp\Entity;

use Doctrine\ORM\Mapping as ORM;
use DDD\Embeddable\EmailAddress;

/**
 * @ORM\Entity
 */
class User {

    /**
     * @ORM\Embedded(class="DDD\Embeddable\EmailAddress")
     */
    private $email;

    // Returns an EmailAddress instance, not a string
    public function getEmail();

    // Use type-hinting if you need a setter
    public function setEmail(EmailAddress $email);
}

$username  = $user->getEmail()->getLocalpart();

$blacklist = ['spam4me.io', 'foo.com'];
if(in_array($user->getEmail()->getDomain(), $blacklist)) {
   // ...
}

if($company->hasMap()) {
    $latLng = $company->getAddress()->getGeoPoint()->toArray();
    //..
}

class Company
{
    // ...
       
    /**
     * Returns a boolean TRUE if the geolocation of the company is known,
     * FALSE otherwise.
     *
     * @return bool
     */
    public function hasMap()
    {
        return $this->getAddress()->getGeoPoint() !== null;
    }
}

PHPUnit 9.5.25 #StandWithUkraine

................................................................. 65 / 75 ( 86%)
..........                                                        75 / 75 (100%)

Time: 00:00.037, Memory: 6.00 MB

OK (75 tests, 124 assertions)