protected function transaction(callable $callback)
    {
        try {
            $this->database->beginTransaction();
            $reflect = new \ReflectionFunction($callback);
            if ($reflect->getNumberOfParameters() == 1) {
                $result = $callback($this->database);
            } elseif ($reflect->getNumberOfParameters() == 0) {
                $result = $callback();
            } else {
                throw new \InvalidArgumentException("Specified callback must have 0 or 1 argument");
            }
            $this->database->commit();
            return $result;
        } catch (\Exception $e) {
            $this->database->rollback();
            throw new DatabaseException($e->getMessage());
        }
    }
protected function transaction(callable $callback)
    {
        try {
            $this->database->beginTransaction();
            $reflect = new \ReflectionFunction($callback);
            if ($reflect->getNumberOfParameters() == 1) {
                $result = $callback($this->database);
            } elseif ($reflect->getNumberOfParameters() == 0) {
                $result = $callback();
            } else {
                throw new \InvalidArgumentException("Specified callback must have 0 or 1 argument");
            }
            $this->database->commit();
            return $result;
        } catch (\Exception $e) {
            $this->database->rollback();
            throw new DatabaseException($e->getMessage());
        }
    }
protected function transaction ( callable $ callback ) { try { $ this -> database -> beginTransaction ( ) ; $ reflect = new \ ReflectionFunction ( $ callback ) ; if ( $ reflect -> getNumberOfParameters ( ) == 1 ) { $ result = $ callback ( $ this -> database ) ; } elseif ( $ reflect -> getNumberOfParameters ( ) == 0 ) { $ result = $ callback ( ) ; } else { throw new \ InvalidArgumentException ( "Specified callback must have 0 or 1 argument" ) ; } $ this -> database -> commit ( ) ; return $ result ; } catch ( \ Exception $ e ) { $ this -> database -> rollback ( ) ; throw new DatabaseException ( $ e -> getMessage ( ) ) ; } }
Execute a query which should be contain inside a transaction. The specified
callback method will optionally receive the Database instance if one argument
is defined. Will work with nested transactions if using the TransactionPDO
handler. Best suited method for INSERT, UPDATE and DELETE queries.

@param callable $callback
@return mixed
Execute a query which should be contain inside a transaction . The specified callback method will optionally receive the Database instance if one argument is defined . Will work with nested transactions if using the TransactionPDO handler . Best suited method for INSERT UPDATE and DELETE queries .