1: <?php
2:
3: namespace Guzzle\Batch;
4:
5: /**
6: * Divides batches into smaller batches under a certain size
7: */
8: class BatchSizeDivisor implements BatchDivisorInterface
9: {
10: /**
11: * @var int Size of each batch
12: */
13: protected $size;
14:
15: /**
16: * @param int $size Size of each batch
17: */
18: public function __construct($size)
19: {
20: $this->size = $size;
21: }
22:
23: /**
24: * Set the size of each batch
25: *
26: * @param int $size Size of each batch
27: *
28: * @return BatchSizeDivisor
29: */
30: public function setSize($size)
31: {
32: $this->size = $size;
33:
34: return $this;
35: }
36:
37: /**
38: * Get the size of each batch
39: *
40: * @return int
41: */
42: public function getSize()
43: {
44: return $this->size;
45: }
46:
47: /**
48: * {@inheritdoc}
49: */
50: public function createBatches(\SplQueue $queue)
51: {
52: return array_chunk(iterator_to_array($queue, false), $this->size);
53: }
54: }
55: