src/Titon/Db/Repository.php
public function find(Query $query, $type, array $options = []) {
        $options = $options + [
            'before' => true,
            'after' => true,
            'collection' => $this->getConfig('collection')
        ];

        $finder = $this->getFinder($type);
        $state = null;

        if ($options['before']) {
            $event = $this->emit('db.preFind', [$query, $type]);
            $state = $event->getState();

            if (!$state) {
                return $finder->noResults($options);
            }
        }

        // Use the event response as the results
        if (is_array($state)) {
            $results = $state;

        // Query the driver for results
        } else {
            $finder->before($query, $options);

            // Update the connection context
            $results = $this->getDriver()
                ->setContext('read')
                ->executeQuery($query)
                ->find();
        }

        if (!$results) {
            return $finder->noResults($options);
        }

        if ($options['after']) {
            $this->emit('db.postFind', [&$results, $type]);
        }

        return $finder->after($results, $options);
    }
public function find(Query $query, $type, array $options = []) {
        $options = $options + [
            'before' => true,
            'after' => true,
            'collection' => $this->getConfig('collection')
        ];

        $finder = $this->getFinder($type);
        $state = null;

        if ($options['before']) {
            $event = $this->emit('db.preFind', [$query, $type]);
            $state = $event->getState();

            if (!$state) {
                return $finder->noResults($options);
            }
        }

        // Use the event response as the results
        if (is_array($state)) {
            $results = $state;

        // Query the driver for results
        } else {
            $finder->before($query, $options);

            // Update the connection context
            $results = $this->getDriver()
                ->setContext('read')
                ->executeQuery($query)
                ->find();
        }

        if (!$results) {
            return $finder->noResults($options);
        }

        if ($options['after']) {
            $this->emit('db.postFind', [&$results, $type]);
        }

        return $finder->after($results, $options);
    }
public function find ( Query $ query , $ type , array $ options = [ ] ) { $ options = $ options + [ 'before' => true , 'after' => true , 'collection' => $ this -> getConfig ( 'collection' ) ] ; $ finder = $ this -> getFinder ( $ type ) ; $ state = null ; if ( $ options [ 'before' ] ) { $ event = $ this -> emit ( 'db.preFind' , [ $ query , $ type ] ) ; $ state = $ event -> getState ( ) ; if ( ! $ state ) { return $ finder -> noResults ( $ options ) ; } } // Use the event response as the results if ( is_array ( $ state ) ) { $ results = $ state ; // Query the driver for results } else { $ finder -> before ( $ query , $ options ) ; // Update the connection context $ results = $ this -> getDriver ( ) -> setContext ( 'read' ) -> executeQuery ( $ query ) -> find ( ) ; } if ( ! $ results ) { return $ finder -> noResults ( $ options ) ; } if ( $ options [ 'after' ] ) { $ this -> emit ( 'db.postFind' , [ & $ results , $ type ] ) ; } return $ finder -> after ( $ results , $ options ) ; }
All-in-one method for fetching results from a query.
Depending on the type of finder, the returned results will differ.

Before a fetch is executed, a `preFind` event will be triggered.
If this event returns a falsey value, the find will exit and
return a `noResults` value based on the current finder.
If this event returns an array of data, the find will exit and
return the array as the results instead of querying the driver.

Before executing against the driver, the finders `before` method
will be called allowing the current query to be modified.
The driver connection context will also be set to `read`.
If no results are returned from the driver, the finders `noResults`
method will be called.

After a fetch is executed (or a `preFind` event returns data),
a `postFind` event will be triggered. This event allows
the results to be modified via references.

Finally, before the results are returned, wrap each row in an
entity object and pass it through the finders `after` method.

@param \Titon\Db\Query $query
@param string $type
@param mixed $options {
@type bool $before  Will trigger before callbacks
@type bool $after   Will trigger after callbacks
}
@return array|\Titon\Db\Entity|\Titon\Db\EntityCollection
All - in - one method for fetching results from a query . Depending on the type of finder the returned results will differ .