public function grabInFromRepositoryFirstRecordsOrderedByMatching($variable, $repo, $limitAndOffset = null, $orderBy = null, YamlStringNode $criteria = null)
    {
        //support to use "limit:offset"
        if (strpos($limitAndOffset, ':') !== false) {
            list($limit, $offset) = explode(':', $limitAndOffset);
        } else {
            $limit = $limitAndOffset;
            $offset = null;
        }
        // support field:ORDER, eg. name:ASC
        if (is_string($orderBy)) {
            list($field, $order) = explode(':', $orderBy);
            $orderBy = [$field => $order];
        }
        $records = $this->getDoctrine()
                        ->getRepository($repo)
                        ->findBy($criteria ? $criteria->toArray() : [], $orderBy, $limit, $offset);
        $this->storage->setValue($variable, $records);
    }
public function grabInFromRepositoryFirstRecordsOrderedByMatching($variable, $repo, $limitAndOffset = null, $orderBy = null, YamlStringNode $criteria = null)
    {
        //support to use "limit:offset"
        if (strpos($limitAndOffset, ':') !== false) {
            list($limit, $offset) = explode(':', $limitAndOffset);
        } else {
            $limit = $limitAndOffset;
            $offset = null;
        }
        // support field:ORDER, eg. name:ASC
        if (is_string($orderBy)) {
            list($field, $order) = explode(':', $orderBy);
            $orderBy = [$field => $order];
        }
        $records = $this->getDoctrine()
                        ->getRepository($repo)
                        ->findBy($criteria ? $criteria->toArray() : [], $orderBy, $limit, $offset);
        $this->storage->setValue($variable, $records);
    }
public function grabInFromRepositoryFirstRecordsOrderedByMatching ( $ variable , $ repo , $ limitAndOffset = null , $ orderBy = null , YamlStringNode $ criteria = null ) { //support to use "limit:offset" if ( strpos ( $ limitAndOffset , ':' ) !== false ) { list ( $ limit , $ offset ) = explode ( ':' , $ limitAndOffset ) ; } else { $ limit = $ limitAndOffset ; $ offset = null ; } // support field:ORDER, eg. name:ASC if ( is_string ( $ orderBy ) ) { list ( $ field , $ order ) = explode ( ':' , $ orderBy ) ; $ orderBy = [ $ field => $ order ] ; } $ records = $ this -> getDoctrine ( ) -> getRepository ( $ repo ) -> findBy ( $ criteria ? $ criteria -> toArray ( ) : [ ] , $ orderBy , $ limit , $ offset ) ; $ this -> storage -> setValue ( $ variable , $ records ) ; }
Grab a set of records from database in a temp variable inside the `"storage"` in order to use latter in an expression

The prefix `"grab in"` is optional and can be used in "Then" for readability

<code>
Given "users" from ....
Then grab in "users" from ...
</code>

The suffix `"matching:"` is optional too and can be used to set array of conditions to match.

### Placeholders:
- **$variable:** `(string)` name of the variable to save in the storage
- **$entity:** `(string)` name of the entity using bundle notation `"AppBundle:Entity"` or FQN
- **$limitAndOffset:** `(int|string)` amount of records to fetch `"limit"` or use `"limit:offset"` to use pagination
- **$orderBy:** `(string|array)` string like `"title:ASC"` or array inside expression like `"{ [{status: 'DESC', title: 'ASC'}] }"`
- **$criteria:** `(yaml)` YAML node to convert to array of criteria

### Examples:

<code>
- Given "orderedUsers" from repository "AppBundle:User" first 5 records ordered by "username:ASC" matching:
"""
enabled: true
"""
- Given "orderedUsers" from repository "AppBundle:User" first 5 records ordered by "username:ASC"
- And "orderedUsersWithOffset" from repository "AppBundle:User" first "10:20" records ordered by "username:ASC"
- Then grab in "orderedPosts" from repository "AppBundle:Post" first 10 records ordered by "{ [{status: 'DESC', title: 'ASC'}] }"
</code>

and later can be used:

<code>
- And "{orderedUsers[0].getUsername()}" should be equal to "{response.data.users.all.edges[0].node.login}"
</code>

@Given /^(?:grab in )?"([^"]*)" from repository "([^"]*)" first "?([^"]*)"? records ordered by "([^"]*)"(?: matching:)?$/
Grab a set of records from database in a temp variable inside the storage in order to use latter in an expression