<commit_before><?php
/**
 * @author <NAME> | halil · ozgur |o| gmail.com
 */

namespace XmlIterator;

class XmlIterator implements \Iterator
{
    /**
     * @var int
     */
    protected $position = 0;

    /**
     * @var string
     */
    protected $xmlFileUri;

    /**
     * @var string The name of the tag that delimits/separates each iterated element/row
     */
    protected $delimiterTagName;

    /**
     * @var array
     */
    protected $options = array(
        /**
         * @var string Encoding of source file
         */
        "encoding"      => null, //

        /**
         * @var null See __construct() for the default
         */
        "readerOptions" => null, //

        /**
         * @var bool Activate UTF8 filter agains invalid (e.g. "out of allowed range") characters?
         *
         * Disable for performance gain if you know that the xml is clean of bad characters.
         */
        "utf8Filter"    => true, //

        /**
         * @var bool Return current element as an array for ease of use?
         *
         * Disable for performance gain. Bu you need to do (string)$current->something for each sub-element.
         */
        "asArray"       => true, //
    );

    /**
     * @var \XMLReader
     */
    protected $reader;

    /**
     * @var \DOMDocument
     */
    protected $doc;

    /**
     * @param string $xmlFileUri
     * @param string $delimiterTagName
     * @param array  $options
     *
     * @throws \Exception
     */
    function __construct($xmlFileUri, $delimiterTagName, $options = array())
    {
        $this->xmlFileUri       = $xmlFileUri;
        $this->delimiterTagName = $delimiterTagName;

        if (empty($options["readerOptions"])) {
            $options["readerOptions"] = \XMLReader::VALIDATE | \XMLReader::SUBST_ENTITIES;
        }
        $this->options = array_replace_recursive($this->options, $options);

        $this->reader = new \XMLReader();
        $this->doc    = new \DOMDocument();

        if ($this->options["utf8Filter"]) {
            require_once "Utf8Filter.php";
            stream_filter_register('xmlutf8', __NAMESPACE__ . "\\Utf8Filter");
        }
    }

    /**
     * Return the current element
     * @link http://php.net/manual/en/iterator.current.php<commit_msg>Make readerOptions nullable<commit_after><?php
/**
 * @author <NAME> | halil · ozgur |o| <EMAIL>
 */

namespace XmlIterator;

class XmlIterator implements \Iterator
{
    /**
     * @var int
     */
    protected $position = 0;

    /**
     * @var string
     */
    protected $xmlFileUri;

    /**
     * @var string The name of the tag that delimits/separates each iterated element/row
     */
    protected $delimiterTagName;

    /**
     * @var array
     */
    protected $options = array(
        /**
         * @var string Encoding of source file
         */
        "encoding"      => null, //

        /**
         * @var null See __construct() for the default
         */
        "readerOptions" => null, //

        /**
         * @var bool Activate UTF8 filter agains invalid (e.g. "out of allowed range") characters?
         *
         * Disable for performance gain if you know that the xml is clean of bad characters.
         */
        "utf8Filter"    => true, //

        /**
         * @var bool Return current element as an array for ease of use?
         *
         * Disable for performance gain. Bu you need to do (string)$current->something for each sub-element.
         */
        "asArray"       => true, //
    );

    /**
     * @var \XMLReader
     */
    protected $reader;

    /**
     * @var \DOMDocument
     */
    protected $doc;

    /**
     * @param string $xmlFileUri
     * @param string $delimiterTagName
     * @param array  $options
     *
     * @throws \Exception
     */
    function __construct($xmlFileUri, $delimiterTagName, $options = array())
    {
        $this->xmlFileUri       = $xmlFileUri;
        $this->delimiterTagName = $delimiterTagName;

        // work-around for non-scalar default value
        $this->options["readerOptions"] = \XMLReader::VALIDATE | \XMLReader::SUBST_ENTITIES;
        $this->options                  = array_replace_recursive($this->options, $options);

        $this->reader = new \XMLReader();
        $this->doc    = new \DOMDocument();

        if ($this->options["utf8Filter"]) {
            require_once "Utf8Filter.php";
            stream_filter_register('xmlutf8', __NAMESPACE__ . "\\Utf8Filter");
        }
    }

    /**
     * Return the current element
     * @link http://php.net/manual/en/iterator.current.php
{'fraction_non_alphanumeric': 0.1289902280130293, 'fraction_numerical': 0.0030401737242128123, 'mean_word_length': 1.825766871165644, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 14}, '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': '3190981', 'n_tokens_mistral': 1353, 'n_tokens_neox': 1313, 'n_words': 346}