scratch – Blame information for rev

Subversion Repositories:
Rev:
Rev Author Line No. Line
87 office 1 <?php
2  
3 namespace GuzzleHttp\Adapter;
4  
5 use GuzzleHttp\ClientInterface;
6 use GuzzleHttp\Event\ListenerAttacherTrait;
7 use GuzzleHttp\Message\RequestInterface;
8  
9 /**
10 * Converts a sequence of request objects into a transaction.
11 * @internal
12 */
13 class TransactionIterator implements \Iterator
14 {
15 use ListenerAttacherTrait;
16  
17 /** @var \Iterator */
18 private $source;
19  
20 /** @var ClientInterface */
21 private $client;
22  
23 /** @var array Listeners to attach to each request */
24 private $eventListeners = [];
25  
26 public function __construct(
27 $source,
28 ClientInterface $client,
29 array $options
30 ) {
31 $this->client = $client;
32 $this->eventListeners = $this->prepareListeners(
33 $options,
34 ['before', 'complete', 'error']
35 );
36 if ($source instanceof \Iterator) {
37 $this->source = $source;
38 } elseif (is_array($source)) {
39 $this->source = new \ArrayIterator($source);
40 } else {
41 throw new \InvalidArgumentException('Expected an Iterator or array');
42 }
43 }
44  
45 public function current()
46 {
47 $request = $this->source->current();
48 if (!$request instanceof RequestInterface) {
49 throw new \RuntimeException('All must implement RequestInterface');
50 }
51  
52 $this->attachListeners($request, $this->eventListeners);
53  
54 return new Transaction($this->client, $request);
55 }
56  
57 public function next()
58 {
59 $this->source->next();
60 }
61  
62 public function key()
63 {
64 return $this->source->key();
65 }
66  
67 public function valid()
68 {
69 return $this->source->valid();
70 }
71  
72 public function rewind()
73 {
74 if (!($this->source instanceof \Generator)) {
75 $this->source->rewind();
76 }
77 }
78 }