public function attach( Base $entity, &$restingPlace = null )
    {

        if( !$this->makeableSafetyCheck() ) {
            return null;
        }

        // check type
        if( !is_a( $entity, $this->entityClass ) ) {
            throw new EntityNotCompatibleWithRepositoryException( $entity, $this );
        }

        // At the moment something is new if it doesn't have a key set.
        // This is still a work in progress
        if( $key = $entity->keyGet( $entity ) ) {

            // check we've not got a collision already
            if( isset( $this->instancesPersisted[$key] ) ) {
                throw new \RuntimeException( "Repository entity merging not yet coded (but I'm not exactly sure why you need this). You've probably got a logic bug somewhere. What you are asking is, well, odd.");
            }

            $this->instancesPersisted[$key] = $entity;
            $restingPlace = self::PERSISTED;

        } else {

            // debugging check to find where something is being double attached
            if( false !== array_search( $entity, $this->instancesUnpersisted, true ) ) {
                d_pr( sane_debug_backtrace() );
                die();
            }

            $this->instancesUnpersisted[] = $entity;
            $restingPlace = self::UNPERSISTED;

        }

        return true;

    }
public function attach( Base $entity, &$restingPlace = null )
    {

        if( !$this->makeableSafetyCheck() ) {
            return null;
        }

        // check type
        if( !is_a( $entity, $this->entityClass ) ) {
            throw new EntityNotCompatibleWithRepositoryException( $entity, $this );
        }

        // At the moment something is new if it doesn't have a key set.
        // This is still a work in progress
        if( $key = $entity->keyGet( $entity ) ) {

            // check we've not got a collision already
            if( isset( $this->instancesPersisted[$key] ) ) {
                throw new \RuntimeException( "Repository entity merging not yet coded (but I'm not exactly sure why you need this). You've probably got a logic bug somewhere. What you are asking is, well, odd.");
            }

            $this->instancesPersisted[$key] = $entity;
            $restingPlace = self::PERSISTED;

        } else {

            // debugging check to find where something is being double attached
            if( false !== array_search( $entity, $this->instancesUnpersisted, true ) ) {
                d_pr( sane_debug_backtrace() );
                die();
            }

            $this->instancesUnpersisted[] = $entity;
            $restingPlace = self::UNPERSISTED;

        }

        return true;

    }
public function attach ( Base $ entity , & $ restingPlace = null ) { if ( ! $ this -> makeableSafetyCheck ( ) ) { return null ; } // check type if ( ! is_a ( $ entity , $ this -> entityClass ) ) { throw new EntityNotCompatibleWithRepositoryException ( $ entity , $ this ) ; } // At the moment something is new if it doesn't have a key set. // This is still a work in progress if ( $ key = $ entity -> keyGet ( $ entity ) ) { // check we've not got a collision already if ( isset ( $ this -> instancesPersisted [ $ key ] ) ) { throw new \ RuntimeException ( "Repository entity merging not yet coded (but I'm not exactly sure why you need this). You've probably got a logic bug somewhere. What you are asking is, well, odd." ) ; } $ this -> instancesPersisted [ $ key ] = $ entity ; $ restingPlace = self :: PERSISTED ; } else { // debugging check to find where something is being double attached if ( false !== array_search ( $ entity , $ this -> instancesUnpersisted , true ) ) { d_pr ( sane_debug_backtrace ( ) ) ; die ( ) ; } $ this -> instancesUnpersisted [ ] = $ entity ; $ restingPlace = self :: UNPERSISTED ; } return true ; }
Add a entity into the multiton array

@param Entity\Base
@param mixed If successful attachment the location of the new attachment

@return bool. Successful attachment?
Add a entity into the multiton array