src/Guzzle/Service/Resource/ResourceIteratorApplyBatched.php
public function apply($perBatch = 50)
    {
        $this->iterated = $this->batches = $batches = 0;
        $that = $this;
        $it = $this->iterator;
        $callback = $this->callback;

        $batch = BatchBuilder::factory()
            ->createBatchesWith(new BatchSizeDivisor($perBatch))
            ->transferWith(new BatchClosureTransfer(function (array $batch) use ($that, $callback, &$batches, $it) {
                $batches++;
                $that->dispatch('iterator_batch.before_batch', array('iterator' => $it, 'batch' => $batch));
                call_user_func_array($callback, array($it, $batch));
                $that->dispatch('iterator_batch.after_batch', array('iterator' => $it, 'batch' => $batch));
            }))
            ->autoFlushAt($perBatch)
            ->build();

        $this->dispatch('iterator_batch.created_batch', array('batch' => $batch));

        foreach ($this->iterator as $resource) {
            $this->iterated++;
            $batch->add($resource);
        }

        $batch->flush();
        $this->batches = $batches;

        return $this->iterated;
    }
public function apply($perBatch = 50)
    {
        $this->iterated = $this->batches = $batches = 0;
        $that = $this;
        $it = $this->iterator;
        $callback = $this->callback;

        $batch = BatchBuilder::factory()
            ->createBatchesWith(new BatchSizeDivisor($perBatch))
            ->transferWith(new BatchClosureTransfer(function (array $batch) use ($that, $callback, &$batches, $it) {
                $batches++;
                $that->dispatch('iterator_batch.before_batch', array('iterator' => $it, 'batch' => $batch));
                call_user_func_array($callback, array($it, $batch));
                $that->dispatch('iterator_batch.after_batch', array('iterator' => $it, 'batch' => $batch));
            }))
            ->autoFlushAt($perBatch)
            ->build();

        $this->dispatch('iterator_batch.created_batch', array('batch' => $batch));

        foreach ($this->iterator as $resource) {
            $this->iterated++;
            $batch->add($resource);
        }

        $batch->flush();
        $this->batches = $batches;

        return $this->iterated;
    }
public function apply ( $ perBatch = 50 ) { $ this -> iterated = $ this -> batches = $ batches = 0 ; $ that = $ this ; $ it = $ this -> iterator ; $ callback = $ this -> callback ; $ batch = BatchBuilder :: factory ( ) -> createBatchesWith ( new BatchSizeDivisor ( $ perBatch ) ) -> transferWith ( new BatchClosureTransfer ( function ( array $ batch ) use ( $ that , $ callback , & $ batches , $ it ) { $ batches ++ ; $ that -> dispatch ( 'iterator_batch.before_batch' , array ( 'iterator' => $ it , 'batch' => $ batch ) ) ; call_user_func_array ( $ callback , array ( $ it , $ batch ) ) ; $ that -> dispatch ( 'iterator_batch.after_batch' , array ( 'iterator' => $ it , 'batch' => $ batch ) ) ; } ) ) -> autoFlushAt ( $ perBatch ) -> build ( ) ; $ this -> dispatch ( 'iterator_batch.created_batch' , array ( 'batch' => $ batch ) ) ; foreach ( $ this -> iterator as $ resource ) { $ this -> iterated ++ ; $ batch -> add ( $ resource ) ; } $ batch -> flush ( ) ; $ this -> batches = $ batches ; return $ this -> iterated ; }
Apply the callback to the contents of the resource iterator

@param int $perBatch The number of records to group per batch transfer

@return int Returns the number of iterated resources
Apply the callback to the contents of the resource iterator