<commit_before><?php

namespace Tequila\MongoDB\ODM;

use Tequila\MongoDB\Cursor;
use Tequila\MongoDB\DocumentListenerInterface;
use Tequila\MongoDB\ODM\Exception\LogicException;
use Tequila\MongoDB\QueryListenerInterface;

class SetBulkWriteBuilderListener implements QueryListenerInterface, DocumentListenerInterface
{
    /**
     * @var BulkWriteBuilderFactory
     */
    private $bulkBuilderFactory;

    /**
     * @var string[]
     */
    private $cursorHashToNamespaceMap;

    /**
     * @param BulkWriteBuilderFactory $bulkBuilderFactory
     */
    public function __construct(BulkWriteBuilderFactory $bulkBuilderFactory)
    {
        $this->bulkBuilderFactory = $bulkBuilderFactory;
    }

    /**
     * @inheritdoc
     */
    public function onQueryExecuted($namespace, $filter, array $options, Cursor $cursor)
    {
        $cursor->setDocumentListener($this);
        $this->cursorHashToNamespaceMap[\spl_object_hash($cursor)] = $namespace;
    }

    /**
     * @inheritdoc
     */
    public function onDocument(Cursor $cursor, $document)
    {
        if ($document instanceof BulkWriteBuilderAwareInterface) {
            $cursorHash = \spl_object_hash($cursor);
            if (!array_key_exists($cursorHash, $this->cursorHashToNamespaceMap)) {
                throw new LogicException(
                    'Namespace for $cursor is not found. $cursor must have been tracked by the onQueryExecuted().'
                );
            }
            $namespace = $this->cursorHashToNamespaceMap[$cursorHash];
            $document->setBulkWriteBuilder($this->bulkBuilderFactory->getBulkWriteBuilder($namespace));
        }
    }
}<commit_msg>SetBulkWriteBuilderListener changed to use QueryCursor instead of Cursor<commit_after><?php

namespace Tequila\MongoDB\ODM;

use Tequila\MongoDB\DocumentListenerInterface;
use Tequila\MongoDB\QueryCursor;
use Tequila\MongoDB\QueryListenerInterface;

class SetBulkWriteBuilderListener implements QueryListenerInterface, DocumentListenerInterface
{
    /**
     * @var BulkWriteBuilderFactory
     */
    private $bulkBuilderFactory;

    /**
     * @param BulkWriteBuilderFactory $bulkBuilderFactory
     */
    public function __construct(BulkWriteBuilderFactory $bulkBuilderFactory)
    {
        $this->bulkBuilderFactory = $bulkBuilderFactory;
    }

    /**
     * @inheritdoc
     */
    public function onQueryExecuted($namespace, $filter, array $options, QueryCursor $cursor)
    {
        $cursor->setDocumentListener($this);
    }

    /**
     * @inheritdoc
     */
    public function onDocument(QueryCursor $cursor, $document)
    {
        if ($document instanceof BulkWriteBuilderAwareInterface) {
            $document->setBulkWriteBuilder(
                $this->bulkBuilderFactory->getBulkWriteBuilder($cursor->getNamespace())
            );
        }
    }
}
{'fraction_non_alphanumeric': 0.09964788732394367, 'fraction_numerical': 0.0, 'mean_word_length': 3.0936599423631126, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '6713557', 'n_tokens_mistral': 795, 'n_tokens_neox': 782, 'n_words': 136}