Overview

Namespaces

  • Contrib
    • Bundle
      • CoverallsBundle
        • Console
        • Entity
      • CoverallsV1Bundle
        • Api
        • Collector
        • Command
        • Config
        • Entity
          • Git
    • Component
      • File
      • Log
      • System
        • Git
  • Guzzle
    • Batch
      • Exception
    • Cache
    • Common
      • Exception
    • Http
      • Curl
      • Exception
      • Message
      • QueryAggregator
    • Inflection
    • Iterator
    • Log
    • Parser
      • Cookie
      • Message
      • UriTemplate
      • Url
    • Plugin
      • Async
      • Backoff
      • Cache
      • Cookie
        • CookieJar
        • Exception
      • CurlAuth
      • ErrorResponse
        • Exception
      • History
      • Log
      • Md5
      • Mock
      • Oauth
    • Service
      • Builder
      • Command
        • Factory
        • LocationVisitor
          • Request
          • Response
      • Description
      • Exception
      • Resource
    • Stream
  • PHP
  • Psr
    • Log
  • Symfony
    • Component
      • Config
        • Definition
          • Builder
          • Exception
        • Exception
        • Loader
        • Resource
        • Util
      • Console
        • Command
        • Formatter
        • Helper
        • Input
        • Output
        • Tester
      • EventDispatcher
        • Debug
      • Finder
        • Adapter
        • Comparator
        • Exception
        • Expression
        • Iterator
        • Shell
      • Stopwatch
      • Yaml
        • Exception

Classes

  • AbstractBatchDecorator
  • Batch
  • BatchBuilder
  • BatchClosureDivisor
  • BatchClosureTransfer
  • BatchCommandTransfer
  • BatchRequestTransfer
  • BatchSizeDivisor
  • ExceptionBufferingBatch
  • FlushingBatch
  • HistoryBatch
  • NotifyingBatch

Interfaces

  • BatchDivisorInterface
  • BatchInterface
  • BatchTransferInterface
  • Overview
  • Namespace
  • Class
  • Tree
  • Todo
 1: <?php
 2: 
 3: namespace Guzzle\Batch;
 4: 
 5: /**
 6:  * BatchInterface decorator used to add automatic flushing of the queue when the size of the queue reaches a threshold.
 7:  */
 8: class FlushingBatch extends AbstractBatchDecorator
 9: {
10:     /**
11:      * @var int The threshold for which to automatically flush
12:      */
13:     protected $threshold;
14: 
15:     /**
16:      * @var int Current number of items known to be in the queue
17:      */
18:     protected $currentTotal = 0;
19: 
20:     /**
21:      * @param BatchInterface $decoratedBatch  BatchInterface that is being decorated
22:      * @param int            $threshold       Flush when the number in queue matches the threshold
23:      */
24:     public function __construct(BatchInterface $decoratedBatch, $threshold)
25:     {
26:         $this->threshold = $threshold;
27:         parent::__construct($decoratedBatch);
28:     }
29: 
30:     /**
31:      * Set the auto-flush threshold
32:      *
33:      * @param int $threshold The auto-flush threshold
34:      *
35:      * @return FlushingBatch
36:      */
37:     public function setThreshold($threshold)
38:     {
39:         $this->threshold = $threshold;
40: 
41:         return $this;
42:     }
43: 
44:     /**
45:      * Get the auto-flush threshold
46:      *
47:      * @return int
48:      */
49:     public function getThreshold()
50:     {
51:         return $this->threshold;
52:     }
53: 
54:     /**
55:      * {@inheritdoc}
56:      */
57:     public function add($item)
58:     {
59:         $this->decoratedBatch->add($item);
60:         if (++$this->currentTotal >= $this->threshold) {
61:             $this->currentTotal = 0;
62:             $this->decoratedBatch->flush();
63:         }
64: 
65:         return $this;
66:     }
67: }
68: 
php-coveralls API documentation generated by ApiGen 2.8.0