Subversion Repositories php-qbpwcf

Rev

Rev 3 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 liveuser 1
<?php
2
 
3
namespace Guzzle\Http\Exception;
4
 
5
use Guzzle\Common\Exception\ExceptionCollection;
6
use Guzzle\Http\Message\RequestInterface;
7
 
8
/**
9
 * Exception encountered during a multi transfer
10
 */
11
class MultiTransferException extends ExceptionCollection
12
{
13
    protected $successfulRequests = array();
14
    protected $failedRequests = array();
15
    protected $exceptionForRequest = array();
16
 
17
    /**
18
     * Get all of the requests in the transfer
19
     *
20
     * @return array
21
     */
22
    public function getAllRequests()
23
    {
24
        return array_merge($this->successfulRequests, $this->failedRequests);
25
    }
26
 
27
    /**
28
     * Add to the array of successful requests
29
     *
30
     * @param RequestInterface $request Successful request
31
     *
32
     * @return self
33
     */
34
    public function addSuccessfulRequest(RequestInterface $request)
35
    {
36
        $this->successfulRequests[] = $request;
37
 
38
        return $this;
39
    }
40
 
41
    /**
42
     * Add to the array of failed requests
43
     *
44
     * @param RequestInterface $request Failed request
45
     *
46
     * @return self
47
     */
48
    public function addFailedRequest(RequestInterface $request)
49
    {
50
        $this->failedRequests[] = $request;
51
 
52
        return $this;
53
    }
54
 
55
    /**
56
     * Add to the array of failed requests and associate with exceptions
57
     *
58
     * @param RequestInterface $request   Failed request
59
     * @param \Exception       $exception Exception to add and associate with
60
     *
61
     * @return self
62
     */
63
    public function addFailedRequestWithException(RequestInterface $request, \Exception $exception)
64
    {
65
        $this->add($exception)
66
             ->addFailedRequest($request)
67
             ->exceptionForRequest[spl_object_hash($request)] = $exception;
68
 
69
        return $this;
70
    }
71
 
72
    /**
73
     * Get the Exception that caused the given $request to fail
74
     *
75
     * @param RequestInterface $request Failed command
76
     *
77
     * @return \Exception|null
78
     */
79
    public function getExceptionForFailedRequest(RequestInterface $request)
80
    {
81
        $oid = spl_object_hash($request);
82
 
83
        return isset($this->exceptionForRequest[$oid]) ? $this->exceptionForRequest[$oid] : null;
84
    }
85
 
86
    /**
87
     * Set all of the successful requests
88
     *
89
     * @param array Array of requests
90
     *
91
     * @return self
92
     */
93
    public function setSuccessfulRequests(array $requests)
94
    {
95
        $this->successfulRequests = $requests;
96
 
97
        return $this;
98
    }
99
 
100
    /**
101
     * Set all of the failed requests
102
     *
103
     * @param array Array of requests
104
     *
105
     * @return self
106
     */
107
    public function setFailedRequests(array $requests)
108
    {
109
        $this->failedRequests = $requests;
110
 
111
        return $this;
112
    }
113
 
114
    /**
115
     * Get an array of successful requests sent in the multi transfer
116
     *
117
     * @return array
118
     */
119
    public function getSuccessfulRequests()
120
    {
121
        return $this->successfulRequests;
122
    }
123
 
124
    /**
125
     * Get an array of failed requests sent in the multi transfer
126
     *
127
     * @return array
128
     */
129
    public function getFailedRequests()
130
    {
131
        return $this->failedRequests;
132
    }
133
 
134
    /**
135
     * Check if the exception object contains a request
136
     *
137
     * @param RequestInterface $request Request to check
138
     *
139
     * @return bool
140
     */
141
    public function containsRequest(RequestInterface $request)
142
    {
143
        return in_array($request, $this->failedRequests, true) || in_array($request, $this->successfulRequests, true);
144
    }
145
}