Open Journal Systems  3.3.0
BatchBuilder.php
1 <?php
2 
3 namespace Guzzle\Batch;
4 
7 
12 {
14  protected $autoFlush = false;
15 
17  protected $history = false;
18 
20  protected $exceptionBuffering = false;
21 
23  protected $afterFlush;
24 
26  protected $transferStrategy;
27 
29  protected $divisorStrategy;
30 
32  protected static $mapping = array(
33  'request' => 'Guzzle\Batch\BatchRequestTransfer',
34  'command' => 'Guzzle\Batch\BatchCommandTransfer'
35  );
36 
42  public static function factory()
43  {
44  return new self();
45  }
46 
54  public function autoFlushAt($threshold)
55  {
56  $this->autoFlush = $threshold;
57 
58  return $this;
59  }
60 
66  public function keepHistory()
67  {
68  $this->history = true;
69 
70  return $this;
71  }
72 
79  public function bufferExceptions()
80  {
81  $this->exceptionBuffering = true;
82 
83  return $this;
84  }
85 
94  public function notify($callable)
95  {
96  $this->afterFlush = $callable;
97 
98  return $this;
99  }
100 
109  public function transferRequests($batchSize = 50)
110  {
111  $className = self::$mapping['request'];
112  $this->transferStrategy = new $className($batchSize);
113  $this->divisorStrategy = $this->transferStrategy;
114 
115  return $this;
116  }
117 
126  public function transferCommands($batchSize = 50)
127  {
128  $className = self::$mapping['command'];
129  $this->transferStrategy = new $className($batchSize);
130  $this->divisorStrategy = $this->transferStrategy;
131 
132  return $this;
133  }
134 
143  {
144  $this->divisorStrategy = $divisorStrategy;
145 
146  return $this;
147  }
148 
157  {
158  $this->transferStrategy = $transferStrategy;
159 
160  return $this;
161  }
162 
169  public function build()
170  {
171  if (!$this->transferStrategy) {
172  throw new RuntimeException('No transfer strategy has been specified');
173  }
174 
175  if (!$this->divisorStrategy) {
176  throw new RuntimeException('No divisor strategy has been specified');
177  }
178 
179  $batch = new Batch($this->transferStrategy, $this->divisorStrategy);
180 
181  if ($this->exceptionBuffering) {
182  $batch = new ExceptionBufferingBatch($batch);
183  }
184 
185  if ($this->afterFlush) {
186  $batch = new NotifyingBatch($batch, $this->afterFlush);
187  }
188 
189  if ($this->autoFlush) {
190  $batch = new FlushingBatch($batch, $this->autoFlush);
191  }
192 
193  if ($this->history) {
194  $batch = new HistoryBatch($batch);
195  }
196 
197  return $batch;
198  }
199 }
Guzzle\Batch\BatchBuilder\$autoFlush
$autoFlush
Definition: BatchBuilder.php:17
Guzzle\Batch
Definition: AbstractBatchDecorator.php:3
Guzzle\Batch\BatchBuilder\$divisorStrategy
$divisorStrategy
Definition: BatchBuilder.php:47
Guzzle\Batch\HistoryBatch
Definition: HistoryBatch.php:9
Guzzle\Batch\BatchTransferInterface
Definition: BatchTransferInterface.php:8
Guzzle\Batch\BatchBuilder\$transferStrategy
$transferStrategy
Definition: BatchBuilder.php:41
Guzzle\Batch\FlushingBatch
Definition: FlushingBatch.php:8
Guzzle\Batch\BatchBuilder\$history
$history
Definition: BatchBuilder.php:23
Guzzle\Batch\BatchBuilder\$mapping
static $mapping
Definition: BatchBuilder.php:50
Guzzle\Batch\BatchBuilder\transferRequests
transferRequests($batchSize=50)
Definition: BatchBuilder.php:127
Guzzle\Batch\BatchBuilder\keepHistory
keepHistory()
Definition: BatchBuilder.php:84
Guzzle\Batch\BatchBuilder\autoFlushAt
autoFlushAt($threshold)
Definition: BatchBuilder.php:72
Guzzle\Common\Exception\InvalidArgumentException
Definition: lib/vendor/guzzle/guzzle/src/Guzzle/Common/Exception/InvalidArgumentException.php:5
Guzzle\Batch\BatchBuilder\$afterFlush
$afterFlush
Definition: BatchBuilder.php:35
Guzzle\Batch\BatchBuilder\factory
static factory()
Definition: BatchBuilder.php:60
Guzzle\Batch\ExceptionBufferingBatch
Definition: ExceptionBufferingBatch.php:11
Guzzle\Batch\BatchBuilder\bufferExceptions
bufferExceptions()
Definition: BatchBuilder.php:97
Guzzle\Batch\BatchBuilder
Definition: BatchBuilder.php:11
Guzzle\Batch\BatchBuilder\$exceptionBuffering
$exceptionBuffering
Definition: BatchBuilder.php:29
Guzzle\Batch\BatchBuilder\transferCommands
transferCommands($batchSize=50)
Definition: BatchBuilder.php:144
Guzzle\Batch\BatchBuilder\createBatchesWith
createBatchesWith(BatchDivisorInterface $divisorStrategy)
Definition: BatchBuilder.php:160
Guzzle\Batch\BatchBuilder\transferWith
transferWith(BatchTransferInterface $transferStrategy)
Definition: BatchBuilder.php:174
Guzzle\Batch\BatchBuilder\build
build()
Definition: BatchBuilder.php:187
Guzzle\Common\Exception\RuntimeException
Definition: lib/vendor/guzzle/guzzle/src/Guzzle/Common/Exception/RuntimeException.php:5
Guzzle\Batch\BatchDivisorInterface
Definition: BatchDivisorInterface.php:8
Guzzle\Batch\Batch
Definition: Batch.php:15
Guzzle\Batch\BatchBuilder\notify
notify($callable)
Definition: BatchBuilder.php:112
Guzzle\Batch\NotifyingBatch
Definition: NotifyingBatch.php:10