PHP code example of tourze / doctrine-snowflake-bundle

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

    

tourze / doctrine-snowflake-bundle example snippets


// config/bundles.php
return [
    // ... other bundles
    Tourze\DoctrineSnowflakeBundle\DoctrineSnowflakeBundle::class => ['all' => true],
];

use Doctrine\ORM\Mapping as ORM;
use Tourze\DoctrineSnowflakeBundle\Traits\SnowflakeKeyAware;

#[ORM\Entity]
class YourEntity
{
    use SnowflakeKeyAware;
    
    #[ORM\Column(type: 'string', length: 255)]
    private string $name;
    
    // getter/setter methods...
}

use Doctrine\ORM\Mapping as ORM;
use Tourze\DoctrineSnowflakeBundle\Attribute\SnowflakeColumn;

#[ORM\Entity]
class YourEntity
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column(type: 'integer')]
    private int $id;
    
    #[SnowflakeColumn(prefix: 'ORDER_', length: 32)]
    #[ORM\Column(type: 'string', length: 32)]
    private string $orderId;
    
    // getter/setter methods...
}

use Doctrine\ORM\Mapping as ORM;
use Tourze\DoctrineSnowflakeBundle\Service\SnowflakeIdGenerator;

#[ORM\Entity]
class YourEntity
{
    #[ORM\Id]
    #[ORM\GeneratedValue(strategy: 'CUSTOM')]
    #[ORM\CustomIdGenerator(class: SnowflakeIdGenerator::class)]
    #[ORM\Column(type: 'bigint', nullable: false)]
    private string $id;
    
    // getter/setter methods...
}

#[ORM\Entity]
class Order
{
    use SnowflakeKeyAware;  // Primary key
    
    #[SnowflakeColumn(prefix: 'ORDER_', length: 32)]
    #[ORM\Column(type: 'string', length: 32)]
    private string $orderNumber;
    
    #[SnowflakeColumn(prefix: 'TXN_', length: 24)]
    #[ORM\Column(type: 'string', length: 24)]
    private string $transactionId;
}

#[SnowflakeColumn(prefix: 'ORDER_', length: 32)]