FactoryGirl\Provider\Doctrine\ORM\QueryBuilder::ensure PHP Method

ensure() protected method

$status is a string that describes state the operation should affect and $operation is a callback which is executed if and only if the status is not already in effect. Example: public function withProduct() { return $this->ensure('product is joined', function($qb) { $qb->join('pv.product', 'p'); }); } Should be used to allow the possibility of several different methods each wanting to affect a certain state without messing up the query by duplicate calls to methods. Has the pleasant side effect of describing the results of operations on a more intimate level than the plain object API can allow for, making for more self-documenting code.
protected ensure ( string $status, callback(QueryBuilder) $operation ) : QueryBuilder
$status string
$operation callback(QueryBuilder)
return QueryBuilder
    protected function ensure($status, $operation)
    {
        if (empty($this->_statuses[$status])) {
            $operation($this);
            $this->_statuses[$status] = true;
        }
        return $this;
    }