public function findByFilterComponents( $qty, array $filterComponents )
    {

        // don't use $this copy because we might not be returning a object of exactly the same type
        $output = $this->copy();

        // nothing to filter - return what we've got
        if( !$filterComponents ) {
            return $output;
        }

        // first attempt - this definately works
        $filterClosure = function( $obj ) use ( $filterComponents ) {

            $pass = true;
            foreach( $filterComponents as $filter ) {

//                try {
                    $filterResult = $filter->check( $obj );
//                } catch ( BadPropertyException $e ) {
//                    print_r( $obj );
//                    die();
//                }

                if( in_array( $filter->operation, array( 'AND', '', null ) ) ) {
                    $pass = ( $pass and $filterResult );
                } elseif( $filter->operation === 'OR' ) {
                    $pass = ( $pass or $filterResult );
                } else {
                    throw new \UnknownFilterOperatorException( "I don't know how to handle this operation yet. Sorry." );
                }

            }

            return $pass;

        };

        // go filter
        $output->filter( $filterClosure );

        // qty outputs
        if( $qty === FindFilterComponentFactory::FIND_ALL ) {
            return $output;
        }

        switch( $count = count( $output ) ) {
            case 0:
                return null;
            case 1:
                return $output->pop();
        }

        throw new IncompatibleQtyException( "{$count} entities found - can't return 'one'" );

    }
public function findByFilterComponents( $qty, array $filterComponents )
    {

        // don't use $this copy because we might not be returning a object of exactly the same type
        $output = $this->copy();

        // nothing to filter - return what we've got
        if( !$filterComponents ) {
            return $output;
        }

        // first attempt - this definately works
        $filterClosure = function( $obj ) use ( $filterComponents ) {

            $pass = true;
            foreach( $filterComponents as $filter ) {

//                try {
                    $filterResult = $filter->check( $obj );
//                } catch ( BadPropertyException $e ) {
//                    print_r( $obj );
//                    die();
//                }

                if( in_array( $filter->operation, array( 'AND', '', null ) ) ) {
                    $pass = ( $pass and $filterResult );
                } elseif( $filter->operation === 'OR' ) {
                    $pass = ( $pass or $filterResult );
                } else {
                    throw new \UnknownFilterOperatorException( "I don't know how to handle this operation yet. Sorry." );
                }

            }

            return $pass;

        };

        // go filter
        $output->filter( $filterClosure );

        // qty outputs
        if( $qty === FindFilterComponentFactory::FIND_ALL ) {
            return $output;
        }

        switch( $count = count( $output ) ) {
            case 0:
                return null;
            case 1:
                return $output->pop();
        }

        throw new IncompatibleQtyException( "{$count} entities found - can't return 'one'" );

    }
public function findByFilterComponents ( $ qty , array $ filterComponents ) { // don't use $this copy because we might not be returning a object of exactly the same type $ output = $ this -> copy ( ) ; // nothing to filter - return what we've got if ( ! $ filterComponents ) { return $ output ; } // first attempt - this definately works $ filterClosure = function ( $ obj ) use ( $ filterComponents ) { $ pass = true ; foreach ( $ filterComponents as $ filter ) { //                try { $ filterResult = $ filter -> check ( $ obj ) ; //                } catch ( BadPropertyException $e ) { //                    print_r( $obj ); //                    die(); //                } if ( in_array ( $ filter -> operation , array ( 'AND' , '' , null ) ) ) { $ pass = ( $ pass and $ filterResult ) ; } elseif ( $ filter -> operation === 'OR' ) { $ pass = ( $ pass or $ filterResult ) ; } else { throw new \ UnknownFilterOperatorException ( "I don't know how to handle this operation yet. Sorry." ) ; } } return $ pass ; } ; // go filter $ output -> filter ( $ filterClosure ) ; // qty outputs if ( $ qty === FindFilterComponentFactory :: FIND_ALL ) { return $ output ; } switch ( $ count = count ( $ output ) ) { case 0 : return null ; case 1 : return $ output -> pop ( ) ; } throw new IncompatibleQtyException ( "{$count} entities found - can't return 'one'" ) ; }
Filter a container

@param FindFilterComponentFactory::FIND_ALL | FindFilterComponentFactory::FIND_ONE $qty
@param Bond\Container\FindFilterComponent[]
@return object|Container
Filter a container