public function find( $key, $disableLateLoading = null, $cache = true )
    {

        // $disableLateLoading default value management
        if( !is_bool( $disableLateLoading ) ) {
            $disableLateLoading = false;
        }

        // have we switched off the multiton?
        if( !$cache ) {
            return parent::find( $key, $disableLateLoading );
        }

        // determine the multitonKey
        if( is_null( $key ) ) {
            return null;
        } elseif( is_scalar( $key ) ) {
            $multitonKey = $key;
        } elseif( is_array( $key ) ) {
            $multitonKey = call_user_func( "{$this->entityClass}::keyGet", $key );
        } else {
            return null;
        }

        // do we have this?
        if( !isset( $this->instancesPersisted[$multitonKey] ) ) {

            $obj = parent::find( $key, $disableLateLoading );

            // not got anything?
            if( !$obj ) {
                return null;
            }

            $this->garbageCollect();
            $this->instancesPersisted[$multitonKey] = $obj;

        // disable late loading
        } elseif( $disableLateLoading ) {

            $this->instancesPersisted[$multitonKey]->load();

        }

        return $this->instancesPersisted[$multitonKey];

    }
public function find( $key, $disableLateLoading = null, $cache = true )
    {

        // $disableLateLoading default value management
        if( !is_bool( $disableLateLoading ) ) {
            $disableLateLoading = false;
        }

        // have we switched off the multiton?
        if( !$cache ) {
            return parent::find( $key, $disableLateLoading );
        }

        // determine the multitonKey
        if( is_null( $key ) ) {
            return null;
        } elseif( is_scalar( $key ) ) {
            $multitonKey = $key;
        } elseif( is_array( $key ) ) {
            $multitonKey = call_user_func( "{$this->entityClass}::keyGet", $key );
        } else {
            return null;
        }

        // do we have this?
        if( !isset( $this->instancesPersisted[$multitonKey] ) ) {

            $obj = parent::find( $key, $disableLateLoading );

            // not got anything?
            if( !$obj ) {
                return null;
            }

            $this->garbageCollect();
            $this->instancesPersisted[$multitonKey] = $obj;

        // disable late loading
        } elseif( $disableLateLoading ) {

            $this->instancesPersisted[$multitonKey]->load();

        }

        return $this->instancesPersisted[$multitonKey];

    }
public function find ( $ key , $ disableLateLoading = null , $ cache = true ) { // $disableLateLoading default value management if ( ! is_bool ( $ disableLateLoading ) ) { $ disableLateLoading = false ; } // have we switched off the multiton? if ( ! $ cache ) { return parent :: find ( $ key , $ disableLateLoading ) ; } // determine the multitonKey if ( is_null ( $ key ) ) { return null ; } elseif ( is_scalar ( $ key ) ) { $ multitonKey = $ key ; } elseif ( is_array ( $ key ) ) { $ multitonKey = call_user_func ( "{$this->entityClass}::keyGet" , $ key ) ; } else { return null ; } // do we have this? if ( ! isset ( $ this -> instancesPersisted [ $ multitonKey ] ) ) { $ obj = parent :: find ( $ key , $ disableLateLoading ) ; // not got anything? if ( ! $ obj ) { return null ; } $ this -> garbageCollect ( ) ; $ this -> instancesPersisted [ $ multitonKey ] = $ obj ; // disable late loading } elseif ( $ disableLateLoading ) { $ this -> instancesPersisted [ $ multitonKey ] -> load ( ) ; } return $ this -> instancesPersisted [ $ multitonKey ] ; }
Multiton. Fuck yeah!

@param $key scalar. This key will be used to key the multiton array and instance the multiton.
@param bool $disableLateLoading
@param bool $cache default false. Is is now possible to create a object that doesn't exist in the multion.
Multiton . Fuck yeah!