<commit_before><?php
namespace LazyRecord;
use PDO;
use PDOException;
use RuntimeException;
use InvalidArgumentException;
use Exception;
use Iterator;
use ArrayAccess;
use Countable;

use SQLBuilder\QueryBuilder;
use LazyRecord\OperationResult\OperationSuccess;
use LazyRecord\OperationResult\OperationError;
use LazyRecord\ConnectionManager;
use LazyRecord\Schema\SchemaLoader;
use SerializerKit\YamlSerializer;
use SerializerKit\XmlSerializer;
use SerializerKit\JsonSerializer;

/**
 * base collection class
 */
class BaseCollection
    implements Iterator, ArrayAccess, Countable, ExporterInterface
{
    protected $_lastSql;

    protected $_vars;

    /**
     * @var SQLBuilder\QueryBuilder
     */
    public $_readQuery;

    /**
     * @var PDOStatement handle
     */
    protected $handle;


    /**
     * handle data for items
     *
     * @var array
     */ 
    protected $_itemData = null;



    /**
     * preset vars for creating
     */
    protected $_presetVars = array();




    /**
     * @var array save joined alias and table names
     *
     *  Relationship Id => Joined Alias
     *
     */
    protected $_joinedRelationships = array();


    /**
     * postCreate hook
     */
    protected $_postCreate;


    /**
     * current data item cursor position
     *
     * @var integer
     */
    protected $_itemCursor = null;


    protected $_schema;

    /**
     * operation result object
     */
    protected $_result;


    protected $_alias = 'm';

    protected $explictSelect = false;


    public function getSchema() 
    {
        if ( $this->_schema ) {
            return $this->_schema;
        } elseif ( @constant('static::schema_proxy_class') ) {
            return $this->_schema = SchemaLoader::load( static::schema_proxy_class );
        } 
        throw new RuntimeException("schema is not defined in " . get_class($this) );
    }





    public function __get( $key ) {
        /**
         * lazy attributes
         */
        if( $key === '_schema' || $key === 'schema' ) {
            return $this->getSchema();
        } elseif( $key === '_handle' ) {
            return $this->handle ?: $this->prepareData();
        }
        elseif( $key === '_query' ) {
            return $this->_readQuery 
                    ? $this->_readQuery<commit_msg>using ArrayIterator should be faster than Iterator interface<commit_after><?php
namespace LazyRecord;
use PDO;
use PDOException;
use RuntimeException;
use InvalidArgumentException;
use Exception;
use Iterator;
use ArrayAccess;
use Countable;
use IteratorAggregate;
use ArrayIterator;

use SQLBuilder\QueryBuilder;
use LazyRecord\OperationResult\OperationSuccess;
use LazyRecord\OperationResult\OperationError;
use LazyRecord\ConnectionManager;
use LazyRecord\Schema\SchemaLoader;
use SerializerKit\YamlSerializer;
use SerializerKit\XmlSerializer;
use SerializerKit\JsonSerializer;

/**
 * base collection class
 */
class BaseCollection
    implements 
    // Iterator, 
    ArrayAccess, 
    Countable, 
    IteratorAggregate, 
    ExporterInterface
{
    protected $_lastSql;

    protected $_vars;

    /**
     * @var SQLBuilder\QueryBuilder
     */
    public $_readQuery;

    /**
     * @var PDOStatement handle
     */
    protected $handle;


    /**
     * handle data for items
     *
     * @var array
     */ 
    protected $_itemData = null;



    /**
     * preset vars for creating
     */
    protected $_presetVars = array();




    /**
     * @var array save joined alias and table names
     *
     *  Relationship Id => Joined Alias
     *
     */
    protected $_joinedRelationships = array();


    /**
     * postCreate hook
     */
    protected $_postCreate;


    /**
     * current data item cursor position
     *
     * @var integer
     */
    protected $_itemCursor = null;


    protected $_schema;

    /**
     * operation result object
     */
    protected $_result;


    protected $_alias = 'm';

    protected $explictSelect = false;


    public function getIterator()
    {
        if ( ! $this->_itemData ) {
            $this->_readRows();
        }
        return new ArrayIterator($this->_itemData);
    }

    public function getSchema() 
    {
        if ( $this->_schema ) {
            return $this->_schema;
        } elseif ( @constant('static::schema_proxy_class') ) {
            return $this->_schema = SchemaLoader::load( static::schema_proxy_class );
        } 
        throw new RuntimeException("schema is not defined in " . get_class($this) );
    }





    public function __get( $key ) {
        /**
         * lazy attributes
         */
        if( $key === '_schema' || $key === 'schema' ) {
            return $this->getSchema();
        } elseif( $key === '_handle' ) {
            return $this->handle ?: $this->prepareData();
        }
        elseif( $key === '_query' ) {
            return $this->_readQuery 
                    ? $this->_readQuery
{'fraction_non_alphanumeric': 0.11174204015412695, 'fraction_numerical': 0.0, 'mean_word_length': 2.242603550295858, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4718834', 'n_tokens_mistral': 1410, 'n_tokens_neox': 1346, 'n_words': 344}