<commit_before><?php
/**
 * Spiral Framework.
 *
 * @license   MIT
 * @author    <NAME> (Wolfy-J)
 * @copyright ©2009-2015
 */
namespace Spiral\Components\ODM;

/**
 * @method array explain()
 */
class CursorReader implements \Iterator
{
    /**
     * MongoCursor instance.
     *
     * @var \MongoCursor
     */
    protected $cursor = null;

    /**
     * ODM component.
     *
     * @var ODM
     */
    protected $odm = null;

    /**
     * Document schema used by CursorReader to construct valid documents. Fields will be returned
     * if no schema provided.
     *
     * @var array
     */
    protected $schema = array();

    /**
     * CursorReader is wrapper at top of MongoCursor used to correctly resolve data type of result.
     *
     * @param \MongoCursor $cursor
     * @param ODM          $odm
     * @param array        $schema
     * @param array        $sort
     * @param int          $limit
     * @param int          $offset
     */
    public function __construct(
        \MongoCursor $cursor,
        ODM $odm,
        array $schema,
        array $sort = array(),
        $limit = null,
        $offset = null
    )
    {
        $this->cursor = $cursor;
        $this->odm = $odm;
        $this->schema = $schema;

        if (!empty($sort))
        {
            $this->cursor->sort($sort);
        }

        !empty($limit) && $this->cursor->limit($limit);
        !empty($offset) && $this->cursor->skip($offset);
    }

    /**
     * Create document instance by class definition stored in ODM schema.
     *
     * @param array $fields
     * @return Document
     * @throws ODMException
     */
    protected function createDocument(array $fields)
    {
        $class = $this->odm->defineClass($fields, $this->schema[ODM::C_DEFINITION]);

        //No IoC here due unpredictable consequences
        return new $class($fields);
    }

    /**
     * Sets the fields for a query.
     *
     * @link http://www.php.net/manual/en/mongocursor.fields.php
     * @param array $fields Fields to return (or not return).
     * @throws \MongoCursorException
     * @return static
     */
    public function fields(array $fields)
    {<commit_msg>odm passed<commit_after><?php
/**
 * Spiral Framework.
 *
 * @license   MIT
 * @author    <NAME> (Wolfy-J)
 * @copyright ©2009-2015
 */
namespace Spiral\Components\ODM;

/**
 * @method array explain()
 */
class CursorReader implements \Iterator
{
    /**
     * MongoCursor instance.
     *
     * @var \MongoCursor
     */
    protected $cursor = null;

    /**
     * ODM component.
     *
     * @var ODM
     */
    protected $odm = null;

    /**
     * Document schema used by CursorReader to construct valid documents. Fields will be returned
     * if no schema provided.
     *
     * @var array
     */
    protected $schema = array();

    /**
     * CursorReader is wrapper at top of MongoCursor used to correctly resolve data type of result.
     *
     * @param \MongoCursor $cursor
     * @param ODM          $odm
     * @param array        $schema
     * @param array        $sort
     * @param int          $limit
     * @param int          $offset
     */
    public function __construct(
        \MongoCursor $cursor,
        ODM $odm,
        array $schema,
        array $sort = array(),
        $limit = null,
        $offset = null
    )
    {
        $this->cursor = $cursor;
        $this->odm = $odm;
        $this->schema = $schema;

        if (!empty($sort))
        {
            $this->cursor->sort($sort);
        }

        !empty($limit) && $this->cursor->limit($limit);
        !empty($offset) && $this->cursor->skip($offset);
    }

    /**
     * Create document instance by class definition stored in ODM schema.
     *
     * @param array $fields
     * @return Document
     * @throws ODMException
     */
    protected function createDocument(array $fields)
    {
        $class = $this->odm->defineClass($fields, $this->schema[ODM::C_DEFINITION]);

        //No IoC here due unpredictable consequences
        return new $class($fields, null, array(), $this->odm);
    }

    /**
     * Sets the fields for a query.
     *
     * @link http://www.php.net/manual/en/mongocursor.fields.php
     * @param array $fields Fields to return (or not return).
     * @throws \MongoCursorException
     * @return static
     */
    public function fields(array $fields)
    {
{'fraction_non_alphanumeric': 0.12853236098450319, 'fraction_numerical': 0.0036463081130355514, 'mean_word_length': 1.8723821989528795, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7308125', 'n_tokens_mistral': 1331, 'n_tokens_neox': 1284, 'n_words': 354}