public function removeTransaction( $transaction = self::TRANSACTION_LAST_USED, $throwExceptionIfNotFound = true )
    {

        // remove all transactions
        if( $transaction === self::TRANSACTIONS_ALL ) {
            $numTransactions = count( $this->queue );
            $this->queue = array();
            $this->lastTransaction = null;
            return $numTransactions;
        }

        // last created transaction
        if( $transaction === self::TRANSACTION_LAST_CREATED ) {
            $keys = array_keys( $this->queue );
            if( $transaction = array_pop( $keys ) ) {
                if( $this->lastTransaction === $transaction ) {
                    $this->lastTransaction = null;
                }
                unset( $this->queue[$transaction] );
                return 1;
            }
            return 0;
        }

        // last used
        if( $transaction === self::TRANSACTION_LAST_USED ) {
            if( $this->lastTransaction ) {
                unset( $this->queue[$this->lastTransaction] );
                $this->lastTransaction = null;
                return 0;
            }
            return 0;
        }

        // array of transactions
        if( is_array( $transaction ) ) {
            $output = 0;
            foreach( $transaction as $name ) {
                if( array_key_exists( $name, $this->queue ) ) {
                    if( $this->lastTransaction === $name ) {
                        $this->lastTransaction = null;
                    }
                    unset( $this->queue[$name] );
                    $output++;
                } elseif ( $throwExceptionIfNotFound ) {
                    throw new TransactionDoesNotExistException(
                        "Transaction with this name `{$name}` doesn't exist. Sorry."
                    );
                }
            }
            return $output;
        }

        if( is_scalar($transaction) ) {
            if( array_key_exists( $transaction, $this->queue ) ) {
                if( $this->lastTransaction === $transaction ) {
                    $this->lastTransaction = null;
                }
                unset( $this->queue[$name] );
                return 1;
            } elseif ( $throwExceptionIfNotFound ) {
                throw new TransactionDoesNotExistException(
                    "Transaction with this name `{$transaction}` doesn't exist. Sorry."
                );
            }
            return 0;
        }

        throw new \InvalidArgumentException(
            sprintf(
                "Not sure how to remove transaction `%s`",
                print_r( $transaction, true )
            )
        );

    }
public function removeTransaction( $transaction = self::TRANSACTION_LAST_USED, $throwExceptionIfNotFound = true )
    {

        // remove all transactions
        if( $transaction === self::TRANSACTIONS_ALL ) {
            $numTransactions = count( $this->queue );
            $this->queue = array();
            $this->lastTransaction = null;
            return $numTransactions;
        }

        // last created transaction
        if( $transaction === self::TRANSACTION_LAST_CREATED ) {
            $keys = array_keys( $this->queue );
            if( $transaction = array_pop( $keys ) ) {
                if( $this->lastTransaction === $transaction ) {
                    $this->lastTransaction = null;
                }
                unset( $this->queue[$transaction] );
                return 1;
            }
            return 0;
        }

        // last used
        if( $transaction === self::TRANSACTION_LAST_USED ) {
            if( $this->lastTransaction ) {
                unset( $this->queue[$this->lastTransaction] );
                $this->lastTransaction = null;
                return 0;
            }
            return 0;
        }

        // array of transactions
        if( is_array( $transaction ) ) {
            $output = 0;
            foreach( $transaction as $name ) {
                if( array_key_exists( $name, $this->queue ) ) {
                    if( $this->lastTransaction === $name ) {
                        $this->lastTransaction = null;
                    }
                    unset( $this->queue[$name] );
                    $output++;
                } elseif ( $throwExceptionIfNotFound ) {
                    throw new TransactionDoesNotExistException(
                        "Transaction with this name `{$name}` doesn't exist. Sorry."
                    );
                }
            }
            return $output;
        }

        if( is_scalar($transaction) ) {
            if( array_key_exists( $transaction, $this->queue ) ) {
                if( $this->lastTransaction === $transaction ) {
                    $this->lastTransaction = null;
                }
                unset( $this->queue[$name] );
                return 1;
            } elseif ( $throwExceptionIfNotFound ) {
                throw new TransactionDoesNotExistException(
                    "Transaction with this name `{$transaction}` doesn't exist. Sorry."
                );
            }
            return 0;
        }

        throw new \InvalidArgumentException(
            sprintf(
                "Not sure how to remove transaction `%s`",
                print_r( $transaction, true )
            )
        );

    }
public function removeTransaction ( $ transaction = self :: TRANSACTION_LAST_USED , $ throwExceptionIfNotFound = true ) { // remove all transactions if ( $ transaction === self :: TRANSACTIONS_ALL ) { $ numTransactions = count ( $ this -> queue ) ; $ this -> queue = array ( ) ; $ this -> lastTransaction = null ; return $ numTransactions ; } // last created transaction if ( $ transaction === self :: TRANSACTION_LAST_CREATED ) { $ keys = array_keys ( $ this -> queue ) ; if ( $ transaction = array_pop ( $ keys ) ) { if ( $ this -> lastTransaction === $ transaction ) { $ this -> lastTransaction = null ; } unset ( $ this -> queue [ $ transaction ] ) ; return 1 ; } return 0 ; } // last used if ( $ transaction === self :: TRANSACTION_LAST_USED ) { if ( $ this -> lastTransaction ) { unset ( $ this -> queue [ $ this -> lastTransaction ] ) ; $ this -> lastTransaction = null ; return 0 ; } return 0 ; } // array of transactions if ( is_array ( $ transaction ) ) { $ output = 0 ; foreach ( $ transaction as $ name ) { if ( array_key_exists ( $ name , $ this -> queue ) ) { if ( $ this -> lastTransaction === $ name ) { $ this -> lastTransaction = null ; } unset ( $ this -> queue [ $ name ] ) ; $ output ++ ; } elseif ( $ throwExceptionIfNotFound ) { throw new TransactionDoesNotExistException ( "Transaction with this name `{$name}` doesn't exist. Sorry." ) ; } } return $ output ; } if ( is_scalar ( $ transaction ) ) { if ( array_key_exists ( $ transaction , $ this -> queue ) ) { if ( $ this -> lastTransaction === $ transaction ) { $ this -> lastTransaction = null ; } unset ( $ this -> queue [ $ name ] ) ; return 1 ; } elseif ( $ throwExceptionIfNotFound ) { throw new TransactionDoesNotExistException ( "Transaction with this name `{$transaction}` doesn't exist. Sorry." ) ; } return 0 ; } throw new \ InvalidArgumentException ( sprintf ( "Not sure how to remove transaction `%s`" , print_r ( $ transaction , true ) ) ) ; }
Remove a transaction

@param scalar|array The name of the transaction
@param bool Throw a exception if the transaction we want to remove can't be found

@return int The number of transactions removed
Remove a transaction