FactoryGirl\Provider\Doctrine\ORM\Repository::useWithLock PHP Method

useWithLock() public method

Acquires a lock to an entity, provides the entity to a callback function and relinquishes the lock by flushing the entity manager immediately after.
public useWithLock ( integer $id, integer $lockMode, $callback ) : mixed
$id integer
$lockMode integer
return mixed callback return type
    public function useWithLock($id, $lockMode, $callback)
    {
        $entityName = $this->getEntityName();
        return $this->transaction(function ($em, $self) use($id, $lockMode, $callback, $entityName) {
            $entity = $self->find($id, $lockMode);
            if (empty($entity)) {
                $message = \sprintf("Could not lock %s entity by id %d: entity not found", $entityName, $id);
                throw new LockException($message);
            }
            $result = $callback($entity, $em, $self);
            return $result;
        });
    }