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

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\Id\AbstractIdGenerator;
  13. use Symfony\Component\Uid\Factory\UlidFactory;
  14. use Symfony\Component\Uid\Ulid;
  15. final class UlidGenerator extends AbstractIdGenerator
  16. {
  17.     private $factory;
  18.     public function __construct(UlidFactory $factory = null)
  19.     {
  20.         $this->factory = $factory;
  21.     }
  22.     public function generate(EntityManager $em, $entity): Ulid
  23.     {
  24.         if ($this->factory) {
  25.             return $this->factory->create();
  26.         }
  27.         return new Ulid();
  28.     }
  29. }