vendor/symfony/doctrine-bridge/IdGenerator/UlidGenerator.php line 24

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Bridge\Doctrine\IdGenerator;
  11. use Doctrine\ORM\EntityManager;
  12. use Doctrine\ORM\EntityManagerInterface;
  13. use Doctrine\ORM\Id\AbstractIdGenerator;
  14. use Symfony\Component\Uid\Factory\UlidFactory;
  15. use Symfony\Component\Uid\Ulid;
  16. final class UlidGenerator extends AbstractIdGenerator
  17. {
  18.     private $factory;
  19.     public function __construct(UlidFactory $factory null)
  20.     {
  21.         $this->factory $factory;
  22.     }
  23.     /**
  24.      * doctrine/orm < 2.11 BC layer.
  25.      */
  26.     public function generate(EntityManager $em$entity): Ulid
  27.     {
  28.         return $this->generateId($em$entity);
  29.     }
  30.     public function generateId(EntityManagerInterface $em$entity): Ulid
  31.     {
  32.         if ($this->factory) {
  33.             return $this->factory->create();
  34.         }
  35.         return new Ulid();
  36.     }
  37. }