PHP code example of guikingone / symfony-uid-doctrine

1. Go to this page and download the library: Download guikingone/symfony-uid-doctrine 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/ */

    

guikingone / symfony-uid-doctrine example snippets


Doctrine\DBAL\Types\Type::addType('uuid', Guikingone\SymfonyUid\Doctrine\Uuid\UuidType::class);

Doctrine\DBAL\Types\Type::addType('ulid', Guikingone\SymfonyUid\Doctrine\Ulid\UlidType::class);

use Doctrine\ORM\Mapping as ORM;
use Guikingone\SymfonyUid\Doctrine\Uuid\UuidGenerator;

/**
 * @ORM\Entity
 * @ORM\Table(name="posts")
 */
class Post
{
    /**
     * @var Symfony\Component\Uid\Uuid
     *
     * @ORM\Id
     * @ORM\Column(type="uuid", unique=true)
     * @ORM\GeneratedValue(strategy="CUSTOM")
     * @ORM\CustomIdGenerator(class=UuidGenerator::class)
     */
    protected $id;

    public function getId(): Uuid
    {
        return $this->id;
    }
}

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Uid\Uuid;

/**
 * @ORM\Entity
 * @ORM\Table(name="posts")
 */
class Post
{
    /**
     * @var Symfony\Component\Uid\Uuid
     *
     * @ORM\Id
     * @ORM\Column(type="uuid", unique=true)
     */
    protected $id;

    public function __construct() 
    {
        $this->id = Uuid::v4();
    }

    public function getId(): Uuid
    {
        return $this->id;
    }
}

use Doctrine\ORM\Mapping as ORM;
use Guikingone\SymfonyUid\Doctrine\Ulid\UlidGenerator;

/**
 * @ORM\Entity
 * @ORM\Table(name="posts")
 */
class Post
{
    /**
     * @var Symfony\Component\Uid\Ulid
     *
     * @ORM\Id
     * @ORM\Column(type="ulid", unique=true)
     * @ORM\GeneratedValue(strategy="CUSTOM")
     * @ORM\CustomIdGenerator(class=UlidGenerator::class)
     */
    protected $id;

    public function getId(): Ulid
    {
        return $this->id;
    }
}

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Uid\Ulid;

/**
 * @ORM\Entity
 * @ORM\Table(name="posts")
 */
class Post
{
    /**
     * @var Symfony\Component\Uid\Ulid
     *
     * @ORM\Id
     * @ORM\Column(type="ulid", unique=true)
     */
    protected $id;

    public function __construct() 
    {
        $this->id = new Ulid();
    }

    public function getId(): Ulid
    {
        return $this->id;
    }
}