public function find($needle, $fetch = true)
    {
        if (empty($needle)) {
            throw new InvalidArgumentException('No condition pased to the repository::find');
        }

        if (!is_array($needle)) {
            $needle = array($this->_description->getIdentityProperty()->getName() => $needle);
        }

        $found = null;
        //there's a key in the needle then it must be a unique entity
        if (count(array_intersect_key($this->_description->getIdentifyingProperties(), $needle)) > 0) {
            $found = $this->_space->findEntity($this->_description, $needle);
        } else {
            $entities = $this->getEntities();
            $found = $entities->find($needle);
        }

        if (!$found && $fetch) {
            $this->getCommandChain()->disable();
            $query = $this->getQuery()->where($needle);
            $found = $this->fetch($query);
            $this->getCommandChain()->enable();
        }

        return $found;
    }
public function find($needle, $fetch = true)
    {
        if (empty($needle)) {
            throw new InvalidArgumentException('No condition pased to the repository::find');
        }

        if (!is_array($needle)) {
            $needle = array($this->_description->getIdentityProperty()->getName() => $needle);
        }

        $found = null;
        //there's a key in the needle then it must be a unique entity
        if (count(array_intersect_key($this->_description->getIdentifyingProperties(), $needle)) > 0) {
            $found = $this->_space->findEntity($this->_description, $needle);
        } else {
            $entities = $this->getEntities();
            $found = $entities->find($needle);
        }

        if (!$found && $fetch) {
            $this->getCommandChain()->disable();
            $query = $this->getQuery()->where($needle);
            $found = $this->fetch($query);
            $this->getCommandChain()->enable();
        }

        return $found;
    }
public function find ( $ needle , $ fetch = true ) { if ( empty ( $ needle ) ) { throw new InvalidArgumentException ( 'No condition pased to the repository::find' ) ; } if ( ! is_array ( $ needle ) ) { $ needle = array ( $ this -> _description -> getIdentityProperty ( ) -> getName ( ) => $ needle ) ; } $ found = null ; //there's a key in the needle then it must be a unique entity if ( count ( array_intersect_key ( $ this -> _description -> getIdentifyingProperties ( ) , $ needle ) ) > 0 ) { $ found = $ this -> _space -> findEntity ( $ this -> _description , $ needle ) ; } else { $ entities = $ this -> getEntities ( ) ; $ found = $ entities -> find ( $ needle ) ; } if ( ! $ found && $ fetch ) { $ this -> getCommandChain ( ) -> disable ( ) ; $ query = $ this -> getQuery ( ) -> where ( $ needle ) ; $ found = $ this -> fetch ( $ query ) ; $ this -> getCommandChain ( ) -> enable ( ) ; } return $ found ; }
Find an existing entity with the passed properties. If not found it returns null.
If the record is not found then try to fetch the entity from the storage.

@param scalar|array $needle The needle to look for
@param bool         $fetch  Boolean flag to whether to fetch entity or not if not found

@return AnDomainEntityAbstract|null
Find an existing entity with the passed properties . If not found it returns null . If the record is not found then try to fetch the entity from the storage .