PHP code example of azaharizaman / nexus-sequencing

1. Go to this page and download the library: Download azaharizaman/nexus-sequencing 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/ */

    

azaharizaman / nexus-sequencing example snippets


use Nexus\Sequencing\Services\SequenceManager;

// Inject via dependency injection
public function __construct(
    private readonly SequenceManager $sequenceManager
) {}

// Generate the next number
$invoiceNumber = $this->sequenceManager->generate(
    sequenceName: 'invoice_number',
    scopeIdentifier: 'tenant_123',
    contextVariables: [
        'DEPARTMENT' => 'SALES',
    ]
);
// Result: "INV-2025-SALES-00001"

$preview = $this->sequenceManager->preview(
    sequenceName: 'invoice_number',
    scopeIdentifier: 'tenant_123'
);
// Result: "INV-2025-SALES-00002" (counter not incremented)

$numbers = $this->bulkGenerator->generateBulk(
    sequenceName: 'ticket_number',
    count: 100
);
// Result: ["TKT-00001", "TKT-00002", ..., "TKT-00100"]

// Reserve 10 numbers for batch processing
$reservedNumbers = $this->reservationService->reserve(
    sequenceName: 'order_number',
    count: 10,
    ttlMinutes: 30
);
// Result: ["ORD-001", "ORD-002", ..., "ORD-010"]

// Release unused numbers
$this->reservationService->release(
    sequenceName: 'order_number',
    numbers: ['ORD-005', 'ORD-008']
);

// Report on gaps in a sequence
$gapReport = $this->gapManager->getGapReport(
    sequenceName: 'invoice_number'
);
// Result: ["INV-00005", "INV-00012", "INV-00023"]

// Reclaim a gap (for fill_gaps policy)
$this->gapManager->reclaimGap(
    sequenceName: 'invoice_number',
    number: 'INV-00005'
);