_sequenceName = $sequenceName; $this->_allocationSize = $allocationSize; } /** * {@inheritDoc} */ public function generateId(EntityManagerInterface $em, $entity) { if ($this->_maxValue === null || $this->_nextValue === $this->_maxValue) { // Allocate new values $connection = $em->getConnection(); $sql = $connection->getDatabasePlatform()->getSequenceNextValSQL($this->_sequenceName); if ($connection instanceof PrimaryReadReplicaConnection) { $connection->ensureConnectedToPrimary(); } $this->_nextValue = (int) $connection->executeQuery($sql)->fetchOne(); $this->_maxValue = $this->_nextValue + $this->_allocationSize; } return $this->_nextValue++; } /** * Gets the maximum value of the currently allocated bag of values. * * @return int|null */ public function getCurrentMaxValue() { return $this->_maxValue; } /** * Gets the next value that will be returned by generate(). * * @return int */ public function getNextValue() { return $this->_nextValue; } /** * @return string * * @final */ public function serialize() { return serialize($this->__serialize()); } /** * @return array */ public function __serialize(): array { return [ 'allocationSize' => $this->_allocationSize, 'sequenceName' => $this->_sequenceName, ]; } /** * @param string $serialized * * @return void * * @final */ public function unserialize($serialized) { $this->__unserialize(unserialize($serialized)); } /** * @param array $data */ public function __unserialize(array $data): void { $this->_sequenceName = $data['sequenceName']; $this->_allocationSize = $data['allocationSize']; } }